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.