lodash.assign
Advanced tools
Comparing version 3.2.0 to 4.0.0
369
index.js
/** | ||
* lodash 3.2.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 4.0.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var baseAssign = require('lodash._baseassign'), | ||
createAssigner = require('lodash._createassigner'), | ||
keys = require('lodash.keys'); | ||
var keys = require('lodash.keys'), | ||
rest = require('lodash.rest'); | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** Used to detect unsigned integer values. */ | ||
var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** | ||
* A specialized version of `_.assign` for customizing assigned values without | ||
* support for argument juggling, multiple sources, and `this` binding `customizer` | ||
* functions. | ||
* Checks if `value` is a valid array-like index. | ||
* | ||
* @private | ||
* @param {Object} object The destination object. | ||
* @param {Object} source The source object. | ||
* @param {Function} customizer The function to customize assigned values. | ||
* @param {*} value The value to check. | ||
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. | ||
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`. | ||
*/ | ||
function isIndex(value, length) { | ||
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; | ||
length = length == null ? MAX_SAFE_INTEGER : length; | ||
return value > -1 && value % 1 == 0 && value < length; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** | ||
* Assigns `value` to `key` of `object` if the existing value is not equivalent | ||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* for equality comparisons. | ||
* | ||
* @private | ||
* @param {Object} object The object to modify. | ||
* @param {string} key The key of the property to assign. | ||
* @param {*} value The value to assign. | ||
*/ | ||
function assignValue(object, key, value) { | ||
var objValue = object[key]; | ||
if ((!eq(objValue, value) || | ||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) || | ||
(value === undefined && !(key in object))) { | ||
object[key] = value; | ||
} | ||
} | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
* | ||
* @private | ||
* @param {string} key The key of the property to get. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function baseProperty(key) { | ||
return function(object) { | ||
return object == null ? undefined : object[key]; | ||
}; | ||
} | ||
/** | ||
* Copies properties of `source` to `object`. | ||
* | ||
* @private | ||
* @param {Object} source The object to copy properties from. | ||
* @param {Array} props The property names to copy. | ||
* @param {Object} [object={}] The object to copy properties to. | ||
* @returns {Object} Returns `object`. | ||
*/ | ||
function assignWith(object, source, customizer) { | ||
function copyObject(source, props, object) { | ||
return copyObjectWith(source, props, object); | ||
} | ||
/** | ||
* This function is like `copyObject` except that it accepts a function to | ||
* customize copied values. | ||
* | ||
* @private | ||
* @param {Object} source The object to copy properties from. | ||
* @param {Array} props The property names to copy. | ||
* @param {Object} [object={}] The object to copy properties to. | ||
* @param {Function} [customizer] The function to customize copied values. | ||
* @returns {Object} Returns `object`. | ||
*/ | ||
function copyObjectWith(source, props, object, customizer) { | ||
object || (object = {}); | ||
var index = -1, | ||
props = keys(source), | ||
length = props.length; | ||
@@ -31,9 +112,5 @@ | ||
var key = props[index], | ||
value = object[key], | ||
result = customizer(value, source[key], key, object, source); | ||
newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key]; | ||
if ((result === result ? (result !== value) : (value === value)) || | ||
(value === undefined && !(key in object))) { | ||
object[key] = result; | ||
} | ||
assignValue(object, key, newValue); | ||
} | ||
@@ -44,39 +121,245 @@ return object; | ||
/** | ||
* Assigns own enumerable properties of source object(s) to the destination | ||
* object. Subsequent sources overwrite property assignments of previous sources. | ||
* If `customizer` is provided it is invoked to produce the assigned values. | ||
* The `customizer` is bound to `thisArg` and invoked with five arguments: | ||
* (objectValue, sourceValue, key, object, source). | ||
* Creates a function like `_.assign`. | ||
* | ||
* **Note:** This method mutates `object` and is based on | ||
* [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign). | ||
* @private | ||
* @param {Function} assigner The function to assign values. | ||
* @returns {Function} Returns the new assigner function. | ||
*/ | ||
function createAssigner(assigner) { | ||
return rest(function(object, sources) { | ||
var index = -1, | ||
length = sources.length, | ||
customizer = length > 1 ? sources[length - 1] : undefined, | ||
guard = length > 2 ? sources[2] : undefined; | ||
customizer = typeof customizer == 'function' ? (length--, customizer) : undefined; | ||
if (guard && isIterateeCall(sources[0], sources[1], guard)) { | ||
customizer = length < 3 ? undefined : customizer; | ||
length = 1; | ||
} | ||
object = Object(object); | ||
while (++index < length) { | ||
var source = sources[index]; | ||
if (source) { | ||
assigner(object, source, customizer); | ||
} | ||
} | ||
return object; | ||
}); | ||
} | ||
/** | ||
* Gets the "length" property value of `object`. | ||
* | ||
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) | ||
* that affects Safari on at least iOS 8.1-8.3 ARM64. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {*} Returns the "length" value. | ||
*/ | ||
var getLength = baseProperty('length'); | ||
/** | ||
* Checks if the provided arguments are from an iteratee call. | ||
* | ||
* @private | ||
* @param {*} value The potential iteratee value argument. | ||
* @param {*} index The potential iteratee index or key argument. | ||
* @param {*} object The potential iteratee object argument. | ||
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. | ||
*/ | ||
function isIterateeCall(value, index, object) { | ||
if (!isObject(object)) { | ||
return false; | ||
} | ||
var type = typeof index; | ||
if (type == 'number' | ||
? (isArrayLike(object) && isIndex(index, object.length)) | ||
: (type == 'string' && index in object)) { | ||
return eq(object[index], value); | ||
} | ||
return false; | ||
} | ||
/** | ||
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | ||
* comparison between two values to determine if they are equivalent. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @alias extend | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. | ||
* @example | ||
* | ||
* var object = { 'user': 'fred' }; | ||
* var other = { 'user': 'fred' }; | ||
* | ||
* _.eq(object, object); | ||
* // => true | ||
* | ||
* _.eq(object, other); | ||
* // => false | ||
* | ||
* _.eq('a', 'a'); | ||
* // => true | ||
* | ||
* _.eq('a', Object('a')); | ||
* // => false | ||
* | ||
* _.eq(NaN, NaN); | ||
* // => true | ||
*/ | ||
function eq(value, other) { | ||
return value === other || (value !== value && other !== other); | ||
} | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && | ||
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value)); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array constructors, and | ||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like length. | ||
* | ||
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
function isLength(value) { | ||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | ||
} | ||
/** | ||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | ||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
// Avoid a V8 JIT bug in Chrome 19-20. | ||
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details. | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Assigns own enumerable 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). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The destination object. | ||
* @param {...Object} [sources] The source objects. | ||
* @param {Function} [customizer] The function to customize assigned values. | ||
* @param {*} [thisArg] The `this` binding of `customizer`. | ||
* @returns {Object} Returns `object`. | ||
* @example | ||
* | ||
* _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' }); | ||
* // => { 'user': 'fred', 'age': 40 } | ||
* function Foo() { | ||
* this.c = 3; | ||
* } | ||
* | ||
* // using a customizer callback | ||
* var defaults = _.partialRight(_.assign, function(value, other) { | ||
* return _.isUndefined(value) ? other : value; | ||
* }); | ||
* function Bar() { | ||
* this.e = 5; | ||
* } | ||
* | ||
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); | ||
* // => { 'user': 'barney', 'age': 36 } | ||
* Foo.prototype.d = 4; | ||
* Bar.prototype.f = 6; | ||
* | ||
* _.assign({ 'a': 1 }, new Foo, new Bar); | ||
* // => { 'a': 1, 'c': 3, 'e': 5 } | ||
*/ | ||
var assign = createAssigner(function(object, source, customizer) { | ||
return customizer | ||
? assignWith(object, source, customizer) | ||
: baseAssign(object, source); | ||
var assign = createAssigner(function(object, source) { | ||
copyObject(source, keys(source), object); | ||
}); | ||
module.exports = assign; |
{ | ||
"name": "lodash.assign", | ||
"version": "3.2.0", | ||
"description": "The modern build of lodash’s `_.assign` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.assign` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"keywords": "lodash, lodash-modularized, stdlib, util, assign", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
@@ -20,6 +18,5 @@ ], | ||
"dependencies": { | ||
"lodash._baseassign": "^3.0.0", | ||
"lodash._createassigner": "^3.0.0", | ||
"lodash.keys": "^3.0.0" | ||
"lodash.keys": "^4.0.0", | ||
"lodash.rest": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.assign v3.2.0 | ||
# lodash.assign v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.assign` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.assign` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -8,3 +8,2 @@ ## Installation | ||
Using npm: | ||
```bash | ||
@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm | ||
In Node.js/io.js: | ||
In Node.js: | ||
```js | ||
@@ -22,2 +20,2 @@ var assign = require('lodash.assign'); | ||
See the [documentation](https://lodash.com/docs#assign) or [package source](https://github.com/lodash/lodash/blob/3.2.0-npm-packages/lodash.assign) for more details. | ||
See the [documentation](https://lodash.com/docs#assign) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.assign) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12729
2
338
19
1
+ Addedlodash.rest@^4.0.0
+ Addedlodash.keys@4.2.0(transitive)
+ Addedlodash.rest@4.0.5(transitive)
- Removedlodash._baseassign@^3.0.0
- Removedlodash._createassigner@^3.0.0
- Removedlodash._baseassign@3.2.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._createassigner@3.1.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
Updatedlodash.keys@^4.0.0