lodash.set
Advanced tools
Comparing version 3.7.4 to 4.0.0
128
index.js
/** | ||
* lodash 3.7.4 (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 toPath = require('lodash._topath'), | ||
isArray = require('lodash.isarray'); | ||
var baseSet = require('lodash._baseset'); | ||
/** Used to match property names within property paths. */ | ||
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, | ||
reIsPlainProp = /^\w*$/; | ||
/** Used to detect unsigned integer values. */ | ||
var reIsUint = /^\d+$/; | ||
/** | ||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) | ||
* of an array-like value. | ||
*/ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
* Sets the value at `path` of `object`. If a portion of `path` doesn't exist | ||
* it's created. Arrays are created for missing index properties while objects | ||
* are created for all other missing properties. Use `_.setWith` to customize | ||
* `path` creation. | ||
* | ||
* @private | ||
* @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; | ||
} | ||
/** | ||
* Checks if `value` is a property name and not a property path. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. | ||
*/ | ||
function isKey(value, object) { | ||
var type = typeof value; | ||
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') { | ||
return true; | ||
} | ||
if (isArray(value)) { | ||
return false; | ||
} | ||
var result = !reIsDeepProp.test(value); | ||
return result || (object != null && value in toObject(object)); | ||
} | ||
/** | ||
* Converts `value` to an object if it's not one. | ||
* | ||
* @private | ||
* @param {*} value The value to process. | ||
* @returns {Object} Returns the object. | ||
*/ | ||
function toObject(value) { | ||
return isObject(value) ? value : Object(value); | ||
} | ||
/** | ||
* 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(1); | ||
* // => 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'); | ||
} | ||
/** | ||
* Sets the property value of `path` on `object`. If a portion of `path` | ||
* does not exist it is created. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to augment. | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
@@ -121,27 +37,5 @@ * @param {*} value The value to set. | ||
function set(object, path, value) { | ||
if (object == null) { | ||
return object; | ||
} | ||
var pathKey = (path + ''); | ||
path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path); | ||
var index = -1, | ||
length = path.length, | ||
lastIndex = length - 1, | ||
nested = object; | ||
while (nested != null && ++index < length) { | ||
var key = path[index]; | ||
if (isObject(nested)) { | ||
if (index == lastIndex) { | ||
nested[key] = value; | ||
} else if (nested[key] == null) { | ||
nested[key] = isIndex(path[index + 1]) ? [] : {}; | ||
} | ||
} | ||
nested = nested[key]; | ||
} | ||
return object; | ||
return object == null ? object : baseSet(object, path, value); | ||
} | ||
module.exports = set; |
{ | ||
"name": "lodash.set", | ||
"version": "3.7.4", | ||
"description": "The modern build of lodash’s `_.set` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.set` 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, set", | ||
"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,4 @@ ], | ||
"dependencies": { | ||
"lodash._topath": "^3.0.0", | ||
"lodash.isarray": "^3.0.0" | ||
"lodash._baseset": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.set v3.7.4 | ||
# lodash.set v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.set` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.set` 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 set = require('lodash.set'); | ||
See the [documentation](https://lodash.com/docs#set) or [package source](https://github.com/lodash/lodash/blob/3.7.4-npm-packages/lodash.set) for more details. | ||
See the [documentation](https://lodash.com/docs#set) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.set) 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
1
3765
38
19
+ Addedlodash._baseset@^4.0.0
+ Addedlodash._baseset@4.3.0(transitive)
+ Addedlodash._basetostring@4.12.0(transitive)
+ Addedlodash._stringtopath@4.8.0(transitive)
- Removedlodash._topath@^3.0.0
- Removedlodash.isarray@^3.0.0
- Removedlodash._topath@3.8.1(transitive)
- Removedlodash.isarray@3.0.4(transitive)