lodash.result
Advanced tools
Comparing version 4.2.1 to 4.3.0
172
index.js
/** | ||
* lodash 4.2.1 (Custom Build) <https://lodash.com/> | ||
* lodash 4.3.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
* Released under MIT license <https://lodash.com/license> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
*/ | ||
var baseSlice = require('lodash._baseslice'), | ||
toString = require('lodash.tostring'); | ||
var stringToPath = require('lodash._stringtopath'); | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
/** Used to match property names within property paths. */ | ||
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, | ||
reIsPlainProp = /^\w*$/, | ||
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; | ||
reIsPlainProp = /^\w*$/; | ||
/** Used to match backslashes in property paths. */ | ||
var reEscapeChar = /\\(\\)?/g; | ||
/** Used for built-in method references. */ | ||
@@ -45,22 +41,2 @@ var objectProto = Object.prototype; | ||
/** | ||
* The base implementation of `_.get` without support for default values. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @returns {*} Returns the resolved value. | ||
*/ | ||
function baseGet(object, path) { | ||
path = isKey(path, object) ? [path + ''] : baseCastPath(path); | ||
var index = 0, | ||
length = path.length; | ||
while (object != null && index < length) { | ||
object = object[path[index++]]; | ||
} | ||
return (index && index == length) ? object : undefined; | ||
} | ||
/** | ||
* Checks if `value` is a property name and not a property path. | ||
@@ -74,7 +50,8 @@ * | ||
function isKey(value, object) { | ||
if (typeof value == 'number') { | ||
var type = typeof value; | ||
if (type == 'number' || type == 'symbol') { | ||
return true; | ||
} | ||
return !isArray(value) && | ||
(reIsPlainProp.test(value) || !reIsDeepProp.test(value) || | ||
(isSymbol(value) || reIsPlainProp.test(value) || !reIsDeepProp.test(value) || | ||
(object != null && value in Object(object))); | ||
@@ -84,29 +61,2 @@ } | ||
/** | ||
* Gets the parent value at `path` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Array} path The path to get the parent value of. | ||
* @returns {*} Returns the parent value. | ||
*/ | ||
function parent(object, path) { | ||
return path.length == 1 ? object : get(object, baseSlice(path, 0, -1)); | ||
} | ||
/** | ||
* Converts `string` to a property path array. | ||
* | ||
* @private | ||
* @param {string} string The string to convert. | ||
* @returns {Array} Returns the property path array. | ||
*/ | ||
function stringToPath(string) { | ||
var result = []; | ||
toString(string).replace(rePropName, function(match, number, quote, string) { | ||
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); | ||
}); | ||
return result; | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
@@ -116,6 +66,8 @@ * | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @type {Function} | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @example | ||
@@ -142,5 +94,7 @@ * | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @example | ||
@@ -168,2 +122,3 @@ * | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
@@ -192,41 +147,64 @@ * @param {*} value The value to check. | ||
/** | ||
* Gets the value at `path` of `object`. If the resolved value is | ||
* `undefined` the `defaultValue` is used in its place. | ||
* 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 _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`. | ||
* @returns {*} Returns the resolved value. | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': [{ 'b': { 'c': 3 } }] }; | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.get(object, 'a[0].b.c'); | ||
* // => 3 | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.get(object, ['a', '0', 'b', 'c']); | ||
* // => 3 | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.get(object, 'a.b.c', 'default'); | ||
* // => 'default' | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function get(object, path, defaultValue) { | ||
var result = object == null ? undefined : baseGet(object, path); | ||
return result === undefined ? defaultValue : result; | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* This method is like `_.get` except that if the resolved value is a function | ||
* it's invoked with the `this` binding of its parent object and its result | ||
* is returned. | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol(value) { | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && objectToString.call(value) == symbolTag); | ||
} | ||
/** | ||
* This method is like `_.get` except that if the resolved value is a | ||
* function it's invoked with the `this` binding of its parent object and | ||
* its result is returned. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to resolve. | ||
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`. | ||
* @param {*} [defaultValue] The value returned for `undefined` resolved values. | ||
* @returns {*} Returns the resolved value. | ||
@@ -250,15 +228,23 @@ * @example | ||
function result(object, path, defaultValue) { | ||
if (!isKey(path, object)) { | ||
path = baseCastPath(path); | ||
var result = get(object, path); | ||
object = parent(object, path); | ||
} else { | ||
result = object == null ? undefined : object[path]; | ||
path = isKey(path, object) ? [path] : baseCastPath(path); | ||
var index = -1, | ||
length = path.length; | ||
// Ensure the loop is entered when path is empty. | ||
if (!length) { | ||
object = undefined; | ||
length = 1; | ||
} | ||
if (result === undefined) { | ||
result = defaultValue; | ||
while (++index < length) { | ||
var value = object == null ? undefined : object[path[index]]; | ||
if (value === undefined) { | ||
index = length; | ||
value = defaultValue; | ||
} | ||
object = isFunction(value) ? value.call(object) : value; | ||
} | ||
return isFunction(result) ? result.call(object) : result; | ||
return object; | ||
} | ||
module.exports = result; |
{ | ||
"name": "lodash.result", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "The lodash method `_.result` exported as a module.", | ||
@@ -18,5 +18,4 @@ "homepage": "https://lodash.com/", | ||
"dependencies": { | ||
"lodash._baseslice": "~4.0.0", | ||
"lodash.tostring": "^4.0.0" | ||
"lodash._stringtopath": "~4.7.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.result v4.2.1 | ||
# lodash.result v4.3.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.result` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#result) or [package source](https://github.com/lodash/lodash/blob/4.2.1-npm-packages/lodash.result) for more details. | ||
See the [documentation](https://lodash.com/docs#result) or [package source](https://github.com/lodash/lodash/blob/4.3.0-npm-packages/lodash.result) 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
Mixed license
License(Experimental) Package contains multiple licenses.
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
9375
1
227
+ Addedlodash._stringtopath@~4.7.0
+ Addedlodash._stringtopath@4.7.1(transitive)
- Removedlodash._baseslice@~4.0.0
- Removedlodash.tostring@^4.0.0
- Removedlodash._baseslice@4.0.0(transitive)
- Removedlodash.tostring@4.1.4(transitive)