lodash.has
Advanced tools
Comparing version 4.2.2 to 4.3.0
191
index.js
/** | ||
* lodash 4.2.2 (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'); | ||
@@ -19,12 +18,9 @@ /** Used as references for various `Number` constants. */ | ||
genTag = '[object GeneratorFunction]', | ||
stringTag = '[object String]'; | ||
stringTag = '[object String]', | ||
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 to detect unsigned integer values. */ | ||
@@ -60,5 +56,7 @@ var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** Built-in value references. */ | ||
var getPrototypeOf = Object.getPrototypeOf, | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable; | ||
var propertyIsEnumerable = objectProto.propertyIsEnumerable; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeGetPrototype = Object.getPrototypeOf; | ||
/** | ||
@@ -76,22 +74,2 @@ * Casts `value` to a path array if it's not one. | ||
/** | ||
* 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; | ||
} | ||
/** | ||
* The base implementation of `_.has` without support for deep paths. | ||
@@ -109,3 +87,3 @@ * | ||
return hasOwnProperty.call(object, key) || | ||
(typeof object == 'object' && key in object && getPrototypeOf(object) === null); | ||
(typeof object == 'object' && key in object && getPrototype(object) === null); | ||
} | ||
@@ -129,4 +107,5 @@ | ||
* | ||
* **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. | ||
* **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. | ||
* | ||
@@ -140,2 +119,13 @@ * @private | ||
/** | ||
* Gets the `[[Prototype]]` of `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {null|Object} Returns the `[[Prototype]]`. | ||
*/ | ||
function getPrototype(value) { | ||
return nativeGetPrototype(Object(value)); | ||
} | ||
/** | ||
* Checks if `path` exists on `object`. | ||
@@ -156,6 +146,12 @@ * | ||
path = baseCastPath(path); | ||
object = parent(object, path); | ||
if (object != null) { | ||
path = last(path); | ||
result = hasFunc(object, path); | ||
var index = -1, | ||
length = path.length; | ||
while (object != null && ++index < length) { | ||
var key = path[index]; | ||
if (!(result = hasFunc(object, key))) { | ||
break; | ||
} | ||
object = object[key]; | ||
} | ||
@@ -179,7 +175,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))); | ||
@@ -189,47 +186,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; | ||
} | ||
/** | ||
* Gets the last element of `array`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Array | ||
* @param {Array} array The array to query. | ||
* @returns {*} Returns the last element of `array`. | ||
* @example | ||
* | ||
* _.last([1, 2, 3]); | ||
* // => 3 | ||
*/ | ||
function last(array) { | ||
var length = array ? array.length : 0; | ||
return length ? array[length - 1] : undefined; | ||
} | ||
/** | ||
* Checks if `value` is likely an `arguments` object. | ||
@@ -239,5 +191,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 | ||
@@ -262,6 +216,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 | ||
@@ -290,2 +246,3 @@ * | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
@@ -318,5 +275,7 @@ * @param {*} value The value to check. | ||
* @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`. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, | ||
* else `false`. | ||
* @example | ||
@@ -345,5 +304,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 | ||
@@ -368,9 +329,12 @@ * | ||
* | ||
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* **Note:** This function is loosely based on | ||
* [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, | ||
* else `false`. | ||
* @example | ||
@@ -401,2 +365,3 @@ * | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
@@ -430,2 +395,3 @@ * @param {*} value The value to check. | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
@@ -456,6 +422,8 @@ * @param {*} value The value to check. | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @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 | ||
@@ -475,28 +443,22 @@ * | ||
/** | ||
* Gets the value at `path` of `object`. If the resolved value is | ||
* `undefined` the `defaultValue` is used in its place. | ||
* Checks if `value` is classified as a `Symbol` primitive or 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 correctly classified, | ||
* else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': [{ 'b': { 'c': 3 } }] }; | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.get(object, 'a[0].b.c'); | ||
* // => 3 | ||
* | ||
* _.get(object, ['a', '0', 'b', 'c']); | ||
* // => 3 | ||
* | ||
* _.get(object, 'a.b.c', 'default'); | ||
* // => 'default' | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function get(object, path, defaultValue) { | ||
var result = object == null ? undefined : baseGet(object, path); | ||
return result === undefined ? defaultValue : result; | ||
function isSymbol(value) { | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && objectToString.call(value) == symbolTag); | ||
} | ||
@@ -508,2 +470,3 @@ | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
@@ -510,0 +473,0 @@ * @category Object |
{ | ||
"name": "lodash.has", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "The lodash method `_.has` 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.has v4.2.2 | ||
# lodash.has v4.3.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.has` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#has) or [package source](https://github.com/lodash/lodash/blob/4.2.2-npm-packages/lodash.has) for more details. | ||
See the [documentation](https://lodash.com/docs#has) or [package source](https://github.com/lodash/lodash/blob/4.3.0-npm-packages/lodash.has) 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
15413
1
447
+ 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)