lodash.assign
Advanced tools
Comparing version 4.0.9 to 4.1.0
361
index.js
@@ -9,4 +9,2 @@ /** | ||
*/ | ||
var keys = require('lodash.keys'), | ||
rest = require('lodash.rest'); | ||
@@ -17,4 +15,6 @@ /** Used as references for various `Number` constants. */ | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
var argsTag = '[object Arguments]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
stringTag = '[object String]'; | ||
@@ -24,2 +24,68 @@ /** Used to detect unsigned integer values. */ | ||
/** | ||
* A faster alternative to `Function#apply`, this function invokes `func` | ||
* with the `this` binding of `thisArg` and the arguments of `args`. | ||
* | ||
* @private | ||
* @param {Function} func The function to invoke. | ||
* @param {*} thisArg The `this` binding of `func`. | ||
* @param {Array} args The arguments to invoke `func` with. | ||
* @returns {*} Returns the result of `func`. | ||
*/ | ||
function apply(func, thisArg, args) { | ||
switch (args.length) { | ||
case 0: return func.call(thisArg); | ||
case 1: return func.call(thisArg, args[0]); | ||
case 2: return func.call(thisArg, args[0], args[1]); | ||
case 3: return func.call(thisArg, args[0], args[1], args[2]); | ||
} | ||
return func.apply(thisArg, args); | ||
} | ||
/** | ||
* 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 accessor function. | ||
*/ | ||
function baseProperty(key) { | ||
return function(object) { | ||
return object == null ? undefined : object[key]; | ||
}; | ||
} | ||
/** | ||
* The base implementation of `_.times` without support for iteratee shorthands | ||
* or max array length checks. | ||
* | ||
* @private | ||
* @param {number} n The number of times to invoke `iteratee`. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the array of results. | ||
*/ | ||
function baseTimes(n, iteratee) { | ||
var index = -1, | ||
result = Array(n); | ||
while (++index < n) { | ||
result[index] = iteratee(index); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Creates a function that invokes `func` with its first argument transformed. | ||
* | ||
* @private | ||
* @param {Function} func The function to wrap. | ||
* @param {Function} transform The argument transform. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function overArg(func, transform) { | ||
return function(arg) { | ||
return func(transform(arg)); | ||
}; | ||
} | ||
/** Used for built-in method references. */ | ||
@@ -41,2 +107,7 @@ var objectProto = Object.prototype; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeGetPrototype = Object.getPrototypeOf, | ||
nativeKeys = Object.keys, | ||
nativeMax = Math.max; | ||
/** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */ | ||
@@ -64,11 +135,54 @@ var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
* The base implementation of `_.has` without support for deep paths. | ||
* | ||
* @private | ||
* @param {string} key The key of the property to get. | ||
* @returns {Function} Returns the new accessor function. | ||
* @param {Object} [object] The object to query. | ||
* @param {Array|string} key The key to check. | ||
* @returns {boolean} Returns `true` if `key` exists, else `false`. | ||
*/ | ||
function baseProperty(key) { | ||
return function(object) { | ||
return object == null ? undefined : object[key]; | ||
function baseHas(object, key) { | ||
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, | ||
// that are composed entirely of index properties, return `false` for | ||
// `hasOwnProperty` checks of them. | ||
return object != null && | ||
(hasOwnProperty.call(object, key) || | ||
(typeof object == 'object' && key in object && getPrototype(object) === null)); | ||
} | ||
/** | ||
* The base implementation of `_.keys` which doesn't skip the constructor | ||
* property of prototypes or treat sparse arrays as dense. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
*/ | ||
var baseKeys = overArg(nativeKeys, Object); | ||
/** | ||
* The base implementation of `_.rest` which doesn't validate or coerce arguments. | ||
* | ||
* @private | ||
* @param {Function} func The function to apply a rest parameter to. | ||
* @param {number} [start=func.length-1] The start position of the rest parameter. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function baseRest(func, start) { | ||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0); | ||
return function() { | ||
var args = arguments, | ||
index = -1, | ||
length = nativeMax(args.length - start, 0), | ||
array = Array(length); | ||
while (++index < length) { | ||
array[index] = args[start + index]; | ||
} | ||
index = -1; | ||
var otherArgs = Array(start + 1); | ||
while (++index < start) { | ||
otherArgs[index] = args[index]; | ||
} | ||
otherArgs[start] = array; | ||
return apply(func, this, otherArgs); | ||
}; | ||
@@ -98,5 +212,5 @@ } | ||
? customizer(object[key], source[key], key, object, source) | ||
: source[key]; | ||
: undefined; | ||
assignValue(object, key, newValue); | ||
assignValue(object, key, newValue === undefined ? source[key] : newValue); | ||
} | ||
@@ -114,3 +228,3 @@ return object; | ||
function createAssigner(assigner) { | ||
return rest(function(object, sources) { | ||
return baseRest(function(object, sources) { | ||
var index = -1, | ||
@@ -154,2 +268,28 @@ length = sources.length, | ||
/** | ||
* Gets the `[[Prototype]]` of `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {null|Object} Returns the `[[Prototype]]`. | ||
*/ | ||
var getPrototype = overArg(nativeGetPrototype, Object); | ||
/** | ||
* Creates an array of index keys for `object` values of arrays, | ||
* `arguments` objects, and strings, otherwise `null` is returned. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array|null} Returns index keys, else `null`. | ||
*/ | ||
function indexKeys(object) { | ||
var length = object ? object.length : undefined; | ||
if (isLength(length) && | ||
(isArray(object) || isString(object) || isArguments(object))) { | ||
return baseTimes(length, String); | ||
} | ||
return null; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
@@ -221,4 +361,4 @@ * | ||
* | ||
* var object = { 'user': 'fred' }; | ||
* var other = { 'user': 'fred' }; | ||
* var object = { 'a': 1 }; | ||
* var other = { 'a': 1 }; | ||
* | ||
@@ -245,2 +385,51 @@ * _.eq(object, object); | ||
/** | ||
* Checks if `value` is likely an `arguments` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArguments(function() { return arguments; }()); | ||
* // => true | ||
* | ||
* _.isArguments([1, 2, 3]); | ||
* // => false | ||
*/ | ||
function isArguments(value) { | ||
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. | ||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && | ||
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
@@ -275,2 +464,31 @@ * not a function and has a `value.length` that's an integer greater than or | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArrayLikeObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject('abc'); | ||
* // => false | ||
* | ||
* _.isArrayLikeObject(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLikeObject(value) { | ||
return isObjectLike(value) && isArrayLike(value); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
@@ -283,4 +501,3 @@ * | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
@@ -365,2 +582,52 @@ * | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is classified as a `String` primitive or object. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a string, else `false`. | ||
* @example | ||
* | ||
* _.isString('abc'); | ||
* // => true | ||
* | ||
* _.isString(1); | ||
* // => false | ||
*/ | ||
function isString(value) { | ||
return typeof value == 'string' || | ||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag); | ||
} | ||
/** | ||
* Assigns own enumerable string keyed properties of source objects to the | ||
@@ -384,14 +651,14 @@ * destination object. Source objects are applied from left to right. | ||
* function Foo() { | ||
* this.c = 3; | ||
* this.a = 1; | ||
* } | ||
* | ||
* function Bar() { | ||
* this.e = 5; | ||
* this.c = 3; | ||
* } | ||
* | ||
* Foo.prototype.d = 4; | ||
* Bar.prototype.f = 6; | ||
* Foo.prototype.b = 2; | ||
* Bar.prototype.d = 4; | ||
* | ||
* _.assign({ 'a': 1 }, new Foo, new Bar); | ||
* // => { 'a': 1, 'c': 3, 'e': 5 } | ||
* _.assign({ 'a': 0 }, new Foo, new Bar); | ||
* // => { 'a': 1, 'c': 3 } | ||
*/ | ||
@@ -410,2 +677,50 @@ var assign = createAssigner(function(object, source) { | ||
/** | ||
* 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. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
* @example | ||
* | ||
* 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'] | ||
*/ | ||
function keys(object) { | ||
var isProto = isPrototype(object); | ||
if (!(isProto || isArrayLike(object))) { | ||
return baseKeys(object); | ||
} | ||
var indexes = indexKeys(object), | ||
skipIndexes = !!indexes, | ||
result = indexes || [], | ||
length = result.length; | ||
for (var key in object) { | ||
if (baseHas(object, key) && | ||
!(skipIndexes && (key == 'length' || isIndex(key, length))) && | ||
!(isProto && key == 'constructor')) { | ||
result.push(key); | ||
} | ||
} | ||
return result; | ||
} | ||
module.exports = assign; |
{ | ||
"name": "lodash.assign", | ||
"version": "4.0.9", | ||
"version": "4.1.0", | ||
"description": "The lodash method `_.assign` exported as a module.", | ||
@@ -16,7 +16,3 @@ "homepage": "https://lodash.com/", | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash.keys": "^4.0.0", | ||
"lodash.rest": "^4.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.assign v4.0.9 | ||
# lodash.assign v4.1.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.assign` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#assign) or [package source](https://github.com/lodash/lodash/blob/4.0.9-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.1.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
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
21981
0
663
- Removedlodash.keys@^4.0.0
- Removedlodash.rest@^4.0.0
- Removedlodash.keys@4.2.0(transitive)
- Removedlodash.rest@4.0.5(transitive)