The complete modularized lodash v3.0.3 library exported as standalone npm packages for utility functions, collections, objects, arrays, and more.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Object manipulation utilities for merging, transforming, and analyzing object properties. These functions provide comprehensive object handling capabilities for data processing and state management.
Assigns own enumerable string keyed properties of source objects to the destination object.
/**
* Assigns own enumerable string keyed properties of source objects to the
* destination object. Source objects are applied from left to right.
* Subsequent sources overwrite property assignments of previous sources.
*
* **Note:** This method mutates `object` and is loosely based on
* [`Object.assign`](https://mdn.io/Object/assign).
*
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
*/
function assign(object, ...sources);Usage Examples:
var assign = require('lodash.assign');
assign({ a: 1 }, { b: 2 }, { c: 3 });
// => { a: 1, b: 2, c: 3 }
var users = { name: 'alice' };
assign(users, { age: 25 }, { active: true });
// => { name: 'alice', age: 25, active: true }Creates a shallow clone of value.
/**
* Creates a shallow clone of `value`.
*
* **Note:** This method is loosely based on the
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
* and supports cloning arrays, array buffers, booleans, date objects, maps,
* numbers, `Object` objects, regexes, sets, strings, symbols, and typed arrays.
*
* @param {*} value The value to clone.
* @returns {*} Returns the cloned value.
*/
function clone(value);Usage Examples:
var clone = require('lodash.clone');
var objects = [{ a: 1 }, { b: 2 }];
var shallow = clone(objects);
console.log(shallow[0] === objects[0]);
// => true (shallow clone - references preserved)Creates a deep clone of value.
/**
* This method is like `_.clone` except that it recursively clones `value`.
*
* @param {*} value The value to recursively clone.
* @returns {*} Returns the deep cloned value.
*/
function cloneDeep(value);Usage Examples:
var cloneDeep = require('lodash.clonedeep');
var objects = [{ a: 1 }, { b: 2 }];
var deep = cloneDeep(objects);
console.log(deep[0] === objects[0]);
// => false (deep clone - new objects created)Recursively merges own and inherited enumerable string keyed properties of source objects into the destination object.
/**
* This method is like `_.assign` except that it recursively merges own and
* inherited enumerable string keyed properties of source objects into the
* destination object. Source properties that resolve to `undefined` are skipped
* if a destination value exists.
*
* **Note:** This method mutates `object`.
*
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
*/
function merge(object, ...sources);Usage Examples:
var merge = require('lodash.merge');
var object = {
a: [{ b: 2 }, { d: 4 }]
};
var other = {
a: [{ c: 3 }, { e: 5 }]
};
merge(object, other);
// => { a: [{ b: 2, c: 3 }, { d: 4, e: 5 }] }Creates an array of the own enumerable property names of object.
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
* for more details.
*
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function keys(object);Usage Examples:
var keys = require('lodash.keys');
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
keys(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)
keys('hi');
// => ['0', '1']Creates an array of the own enumerable string keyed property values of object.
/**
* Creates an array of the own enumerable string keyed property values of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
*/
function values(object);Usage Examples:
var values = require('lodash.values');
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
values(new Foo);
// => [1, 2] (iteration order is not guaranteed)
values('hi');
// => ['h', 'i']Creates an object composed of the picked object properties.
/**
* Creates an object composed of the picked `object` properties.
*
* @param {Object} object The source object.
* @param {...(string|string[])} [props] The property identifiers to pick.
* @returns {Object} Returns the new object.
*/
function pick(object, ...props);Usage Examples:
var pick = require('lodash.pick');
var object = { a: 1, b: '2', c: 3 };
pick(object, ['a', 'c']);
// => { a: 1, c: 3 }
pick(object, 'a', 'c');
// => { a: 1, c: 3 }Creates an object composed of the own and inherited enumerable properties of object that are not omitted.
/**
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable properties of `object` that are not omitted.
*
* @param {Object} object The source object.
* @param {...(string|string[])} [props] The property identifiers to omit.
* @returns {Object} Returns the new object.
*/
function omit(object, ...props);Usage Examples:
var omit = require('lodash.omit');
var object = { a: 1, b: '2', c: 3 };
omit(object, ['a', 'c']);
// => { b: '2' }
omit(object, 'a', 'c');
// => { b: '2' }Checks if path is a direct property of object.
/**
* Checks if `path` is a direct property of `object`.
*
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @returns {boolean} Returns `true` if `path` exists, else `false`.
*/
function has(object, path);Usage Examples:
var has = require('lodash.has');
var object = { a: { b: 2 } };
has(object, 'a');
// => true
has(object, 'a.b');
// => true
has(object, ['a', 'b']);
// => trueAssigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined.
/**
* Assigns own and inherited enumerable string keyed properties of source
* objects to the destination object for all destination properties that
* resolve to `undefined`. Source objects are applied from left to right.
* Once a property is set, additional values of the same property are ignored.
*
* **Note:** This method mutates `object`.
*
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.
* @returns {Object} Returns `object`.
*/
function defaults(object, ...sources);Usage Examples:
var defaults = require('lodash.defaults');
defaults({ a: 1 }, { b: 2 }, { a: 3 });
// => { a: 1, b: 2 }Creates an object composed of the inverted keys and values of object.
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite property
* assignments of previous values unless `multiValue` is `true`.
*
* @param {Object} object The object to invert.
* @param {boolean} [multiValue] Allow multiple values per key.
* @returns {Object} Returns the new inverted object.
*/
function invert(object, multiValue);Usage Examples:
var invert = require('lodash.invert');
var object = { a: 1, b: 2, c: 1 };
invert(object);
// => { '1': 'c', '2': 'b' }
// Handle multiple values
invert(object, true);
// => { '1': ['a', 'c'], '2': ['b'] }The object category also includes: create, findKey, findLastKey, forIn, forInRight, forOwn, forOwnRight, functions, keysIn, mapValues, pairs, result, transform, valuesIn
Package Installation:
npm install lodash.assign lodash.clone lodash.clonedeep lodash.merge
npm install lodash.keys lodash.values lodash.pick lodash.omit
npm install lodash.has lodash.defaults lodash.invert