lodash.defaults
Advanced tools
Comparing version 3.1.2 to 4.0.0
110
index.js
/** | ||
* lodash 3.1.2 (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 assign = require('lodash.assign'), | ||
restParam = require('lodash.restparam'); | ||
var assignInWith = require('lodash.assigninwith'), | ||
rest = require('lodash.rest'); | ||
/** | ||
* Used by `_.defaults` to customize its `_.assign` use. | ||
* A faster alternative to `Function#apply`, this function invokes `func` | ||
* with the `this` binding of `thisArg` and the arguments of `args`. | ||
* | ||
* @private | ||
* @param {*} objectValue The destination object property value. | ||
* @param {*} sourceValue The source object property value. | ||
* @returns {*} Returns the value to assign to the destination object. | ||
* @param {Function} func The function to invoke. | ||
* @param {*} thisArg The `this` binding of `func`. | ||
* @param {...*} [args] The arguments to invoke `func` with. | ||
* @returns {*} Returns the result of `func`. | ||
*/ | ||
function assignDefaults(objectValue, sourceValue) { | ||
return objectValue === undefined ? sourceValue : objectValue; | ||
function apply(func, thisArg, args) { | ||
var length = args ? args.length : 0; | ||
switch (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); | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Creates a `_.defaults` or `_.defaultsDeep` function. | ||
* Used by `_.defaults` to customize its `_.assignIn` use. | ||
* | ||
* @private | ||
* @param {Function} assigner The function to assign values. | ||
* @param {Function} customizer The function to customize assigned values. | ||
* @returns {Function} Returns the new defaults function. | ||
* @param {*} objValue The destination value. | ||
* @param {*} srcValue The source value. | ||
* @param {string} key The key of the property to assign. | ||
* @param {Object} object The parent object of `objValue`. | ||
* @returns {*} Returns the value to assign. | ||
*/ | ||
function createDefaults(assigner, customizer) { | ||
return restParam(function(args) { | ||
var object = args[0]; | ||
if (object == null) { | ||
return object; | ||
} | ||
args.push(customizer); | ||
return assigner.apply(undefined, args); | ||
}); | ||
function assignInDefaults(objValue, srcValue, key, object) { | ||
if (objValue === undefined || | ||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { | ||
return srcValue; | ||
} | ||
return objValue; | ||
} | ||
/** | ||
* Assigns own enumerable properties of source object(s) to the destination | ||
* object for all destination properties that resolve to `undefined`. Once a | ||
* property is set, additional values of the same property are ignored. | ||
* 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 _ | ||
* @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); | ||
} | ||
/** | ||
* Assigns own and inherited enumerable 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`. | ||
@@ -61,4 +110,7 @@ * | ||
*/ | ||
var defaults = createDefaults(assign, assignDefaults); | ||
var defaults = rest(function(args) { | ||
args.push(undefined, assignInDefaults); | ||
return apply(assignInWith, undefined, args); | ||
}); | ||
module.exports = defaults; |
{ | ||
"name": "lodash.defaults", | ||
"version": "3.1.2", | ||
"description": "The modern build of lodash’s `_.defaults` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.defaults` 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, defaults", | ||
"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,5 +18,5 @@ ], | ||
"dependencies": { | ||
"lodash.assign": "^3.0.0", | ||
"lodash.restparam": "^3.0.0" | ||
"lodash.assigninwith": "^4.0.0", | ||
"lodash.rest": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.defaults v3.1.2 | ||
# lodash.defaults v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.defaults` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.defaults` 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 defaults = require('lodash.defaults'); | ||
See the [documentation](https://lodash.com/docs#defaults) or [package source](https://github.com/lodash/lodash/blob/3.1.2-npm-packages/lodash.defaults) for more details. | ||
See the [documentation](https://lodash.com/docs#defaults) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.defaults) for more details. |
Sorry, the diff of this file is not supported yet
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
6097
108
19
+ Addedlodash.assigninwith@^4.0.0
+ Addedlodash.rest@^4.0.0
+ Addedlodash.assigninwith@4.2.0(transitive)
+ Addedlodash.rest@4.0.5(transitive)
- Removedlodash.assign@^3.0.0
- Removedlodash.restparam@^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.assign@3.2.0(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)