Code Monkey home page Code Monkey logo

object-agent's Introduction

Object Agent

A javascript library for working with objects

npm build coverage deps size vulnerabilities license


Installation

npm install object-agent

Requires Babel 7.2+


Functions

Comparison Functions

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.

Data Generation Functions

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.

Interaction Functions

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.

Iteration Functions

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.

Path Utility Functions

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.

object-agent's People

Contributors

darrenpaulwright avatar dependabot[bot] avatar

Stargazers

hoff avatar Marc avatar Joseph avatar  avatar

Watchers

James Cloos avatar  avatar

object-agent's Issues

Intersection integer values

I have tried to get an intersection of two complex objects. Properties like array, object, string and null are recognized as expected, but none of the integer properties are recognized, neither first level nor deep.

Tests don't seem to cover integers also.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.