A javascript library for working with objects
npm install object-agent
Requires Babel 7.2+
- deepEqual(item1, item2) ⇒
boolean
Deeply compares two items.
- diffUpdate(object1, object2) ⇒
object
Performs a deep comparison of two objects, returns a new object with only the first level values that have been changed or added on the second object.
- isEmpty(item) ⇒
boolean
Tests if an object or array has any set keys. The values of each key are not considered.
- isEqual(args) ⇒
boolean
Shallow compares two or more items. All items are compared with SameValue equality except Dates and RegExps which compare their values with SameValue equality, Objects and Arrays which compare key lengths, and instances of objects that compare all properties and prototype objects.
- combo(array, [length]) ⇒
Array
Takes an array of values and returns a new array of the unique sets of the values of a given length.
- mix(...args) ⇒
Array
Mix the contents of multiple arrays into a nested array where all variations of one item from each array is in each of the nested arrays.
- powerset(values) ⇒
Array
Create a power set from a set of values.
- clone(value, [settings]) ⇒
unknown
Deep clone a value.
- erase(object, key) ⇒
boolean
Deletes a property from an object, if the property exists.
- get(object, path) ⇒
unknown
Gets a nested value from an object.
- has(object, path) ⇒
boolean
Determines if a nested value is defined.
- intersection(args) ⇒
object
Performs a deep comparison of objects and returns a new object of values that are equal in all given objects.
- set(object, path, value) ⇒
object
Sets a nested value in an object. Keys in the path that don't exist at any point in the object will be created and added to the object once.
- superimpose(...args, [mutateFirst]) ⇒
Partial.<T>
Deeply superimposes two or more items on each other.
Notes:
- Undefined values will not overwrite defined values
- Array order is maintained
- unset(object, path) ⇒
object
Deletes a property from a nested object.
- countInString(string, match) ⇒
number
Counts the number of instances of a string within another string.
- fill(length, [callback]) ⇒
Array.<unknown>
Returns an array of specified length filled with either the index value or the value returned from the provided callback.
- forIn(object, callback) ⇒
boolean
Iterates over own and inherited properties of an object. Stops iterating as soon as the callback returns a truthy value.
- forOwn(object, callback) ⇒
boolean
Iterates over own properties of an object. Stops iterating as soon as the callback returns a truthy value.
- forOwnReduce(object, callback, initialValue) ⇒
unknown
Iterates over own properties of an object and returns a reduced value.
- mapOwn(object, callback, [ignoreKeys]) ⇒
object
|*
Builds a new object by iterating over own properties of an object.
- nestedEach(arrays, callback, [accrue])
Iterate over the values of multiple arrays.
- pull(array, path) ⇒
Array
Pulls values from an array of objects into a new array.
- repeat(times, callback)
Calls a callback a specified number of times.
- traverse(object, callback, [isOptimistic]) ⇒
boolean
Traverses a nested object. Circular objects are only traversed once.
- appendToPath(path, key, [separator]) ⇒
string
Adds a key to the end of a path.
- firstInPath(path, [separator]) ⇒
string
Returns the first key in a path.
- initialInPath(path, [separator]) ⇒
string
Returns the path without the last key.
- lastInPath(path, [separator]) ⇒
string
Returns the last key in a path.
- tailInPath(path, [separator]) ⇒
string
Returns the path without the first key.
- walkPath(path, callback, [separator])
Calls a callback for every key in a path. If true is returned from the callback then no further calls will be made.