3.0.0 • Published 8 months ago

@ultraq/object-utils v3.0.0

Weekly downloads
172
License
Apache-2.0
Repository
github
Last release
8 months ago

object-utils

Build Status codecov npm Bundlephobia minified size

A collection of utilities for JavaScript objects.

Installation

npm install @ultraq/object-utils

API

equals(object1, object2)

Deep-equality comparison between 2 objects on whether they contain the same values as each other. Only works with objects that act as data structures, not classes or the like as this function only compares primitives using identity (===) comparison.

  • object1:
  • object2:

merge(target, ...sources)

Deep-merges all of the properties of the objects in sources with target, modifying the target object and returning it.

  • target: object to merge values into
  • sources: array of argument list of objects to copy values from

navigate(object, path)

The null-safe nature of this method is now in JavaScript as the optional chaining operator (?.). If you're not using string paths/selectors to the item in your object, then I suggest you use that instead. Otherwise, if you're using string path selectors or can't use that method because of browser support, this method will still do the job 🙂

Returns a value from an object via a path string that describes the nesting of objects to get to the value, eg:

let object = {
  greeting: {
    message: 'Hello!'
  }
};
let pathToMessage = 'greeting.message';

If the path doesn't resolve to anything, then undefined is returned.

  • object: object to search through
  • path: a dot-separated path string to get to the desired value within the object
3.0.0

8 months ago

2.1.0

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago