Package Exports
- object-lib
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
object-lib
Getting Started
$ npm install --save-dev object-libFunctions
For more extensive examples, please refer to the tests.
align(obj: Object, ref: Object)
Align the ordering of one object recursively to a reference object.
Example:
const { align } = require('object-lib');
const obj = { k1: 1, k2: 2 };
const ref = { k2: null, k1: null };
align(obj, ref);
// obj => { k2: 1, k1: 2 }clone(obj: Object[], needles: Array = [])
Deep clone object.
Fields targeted by passed needles are created as a reference and not cloned.
Fields targeted by excluded needles are removed entirely from the result.
Needles are declared using the object-scan syntax.
Example:
const { clone } = require('object-lib');
const data = { a: {}, b: {}, c: {} };
const cloned = clone(data, ['b', '!c']);
console.log(cloned);
// => { a: {}, b: {} }
console.log(cloned.a !== data.a);
// => true
console.log(cloned.b === data.b);
// => truecontains(tree: Object, subtree: Object)
Check if subtree is contained in tree recursively.
Different types are never considered contained.
Arrays are contained iff they are the same length and every element is contained in the corresponding element.
Objects are contained if the keys are a subset, and the respective values are contained.
All other types are contained if they match exactly (===).
Example:
const { contains } = require('object-lib');
contains({ a: [1, 2], b: 'c' }, { a: [1, 2] });
// => true
contains({ a: [1, 2], b: 'c' }, { a: [1] });
// => falseMerge(logic: Object = {})(...obj: Object[])
Allows merging of objects. The logic defines paths that map to a field, or a function, to merge by.
If a function is passed, it is invoked with the value, and the result is used as the merge identifier.
The paths are defined using object-scan syntax.
Example:
const { Merge } = require('object-lib');
Merge()(
{ children: [{ id: 1 }, { id: 2 }] },
{ children: [{ id: 2 }, { id: 3 }] }
);
// => { children: [ { id: 1 }, { id: 2 }, { id: 2 }, { id: 3 } ] }
Merge({ '**[*]': 'id' })(
{ children: [{ id: 1 }, { id: 2 }] },
{ children: [{ id: 2 }, { id: 3 }] }
);
// => { children: [ { id: 1 }, { id: 2 }, { id: 3 } ] }