lodash.pick
Advanced tools
Comparing version 4.2.1 to 4.3.0
410
index.js
@@ -9,12 +9,43 @@ /** | ||
*/ | ||
var baseFlatten = require('lodash._baseflatten'), | ||
rest = require('lodash.rest'); | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0; | ||
var INFINITY = 1 / 0, | ||
MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var symbolTag = '[object Symbol]'; | ||
var argsTag = '[object Arguments]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
/** Detect free variable `self`. */ | ||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root = freeGlobal || freeSelf || Function('return this')(); | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* A specialized version of `_.map` for arrays without support for iteratee | ||
@@ -24,3 +55,3 @@ * shorthands. | ||
* @private | ||
* @param {Array} array The array to iterate over. | ||
* @param {Array} [array] The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
@@ -31,3 +62,3 @@ * @returns {Array} Returns the new mapped array. | ||
var index = -1, | ||
length = array.length, | ||
length = array ? array.length : 0, | ||
result = Array(length); | ||
@@ -42,29 +73,39 @@ | ||
/** | ||
* A specialized version of `_.reduce` for arrays without support for | ||
* iteratee shorthands. | ||
* Appends the elements of `values` to `array`. | ||
* | ||
* @private | ||
* @param {Array} array The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @param {*} [accumulator] The initial value. | ||
* @param {boolean} [initAccum] Specify using the first element of `array` as | ||
* the initial value. | ||
* @returns {*} Returns the accumulated value. | ||
* @param {Array} array The array to modify. | ||
* @param {Array} values The values to append. | ||
* @returns {Array} Returns `array`. | ||
*/ | ||
function arrayReduce(array, iteratee, accumulator, initAccum) { | ||
function arrayPush(array, values) { | ||
var index = -1, | ||
length = array.length; | ||
length = values.length, | ||
offset = array.length; | ||
if (initAccum && length) { | ||
accumulator = array[++index]; | ||
} | ||
while (++index < length) { | ||
accumulator = iteratee(accumulator, array[index], index, array); | ||
array[offset + index] = values[index]; | ||
} | ||
return accumulator; | ||
return array; | ||
} | ||
/** | ||
* 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]; | ||
}; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
@@ -77,3 +118,45 @@ * Used to resolve the | ||
/** Built-in value references. */ | ||
var Symbol = root.Symbol, | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable, | ||
spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax = Math.max; | ||
/** | ||
* The base implementation of `_.flatten` with support for restricting flattening. | ||
* | ||
* @private | ||
* @param {Array} array The array to flatten. | ||
* @param {number} depth The maximum recursion depth. | ||
* @param {boolean} [predicate=isFlattenable] The function invoked per iteration. | ||
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. | ||
* @param {Array} [result=[]] The initial result value. | ||
* @returns {Array} Returns the new flattened array. | ||
*/ | ||
function baseFlatten(array, depth, predicate, isStrict, result) { | ||
var index = -1, | ||
length = array.length; | ||
predicate || (predicate = isFlattenable); | ||
result || (result = []); | ||
while (++index < length) { | ||
var value = array[index]; | ||
if (depth > 0 && predicate(value)) { | ||
if (depth > 1) { | ||
// Recursively flatten arrays (susceptible to call stack limits). | ||
baseFlatten(value, depth - 1, predicate, isStrict, result); | ||
} else { | ||
arrayPush(result, value); | ||
} | ||
} else if (!isStrict) { | ||
result[result.length] = value; | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* The base implementation of `_.pick` without support for individual | ||
@@ -89,11 +172,87 @@ * property identifiers. | ||
object = Object(object); | ||
return arrayReduce(props, function(result, key) { | ||
if (key in object) { | ||
result[key] = object[key]; | ||
return basePickBy(object, props, function(value, key) { | ||
return key in object; | ||
}); | ||
} | ||
/** | ||
* The base implementation of `_.pickBy` without support for iteratee shorthands. | ||
* | ||
* @private | ||
* @param {Object} object The source object. | ||
* @param {string[]} props The property identifiers to pick from. | ||
* @param {Function} predicate The function invoked per property. | ||
* @returns {Object} Returns the new object. | ||
*/ | ||
function basePickBy(object, props, predicate) { | ||
var index = -1, | ||
length = props.length, | ||
result = {}; | ||
while (++index < length) { | ||
var key = props[index], | ||
value = object[key]; | ||
if (predicate(value, key)) { | ||
result[key] = value; | ||
} | ||
return result; | ||
}, {}); | ||
} | ||
return result; | ||
} | ||
/** | ||
* 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); | ||
}; | ||
} | ||
/** | ||
* Gets the "length" property value of `object`. | ||
* | ||
* **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. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {*} Returns the "length" value. | ||
*/ | ||
var getLength = baseProperty('length'); | ||
/** | ||
* Checks if `value` is a flattenable `arguments` object or array. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is flattenable, else `false`. | ||
*/ | ||
function isFlattenable(value) { | ||
return isArray(value) || isArguments(value) || | ||
!!(spreadableSymbol && value && value[spreadableSymbol]) | ||
} | ||
/** | ||
* Converts `value` to a string key if it's not a string or symbol. | ||
@@ -114,2 +273,196 @@ * | ||
/** | ||
* 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 | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && isLength(getLength(value)) && !isFunction(value); | ||
} | ||
/** | ||
* 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. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array and weak map constructors, | ||
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like length. | ||
* | ||
* **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`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
function isLength(value) { | ||
return typeof value == 'number' && | ||
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @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(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
@@ -150,4 +503,3 @@ * and has a `typeof` result of "object". | ||
* @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 symbol, else `false`. | ||
* @example | ||
@@ -183,3 +535,3 @@ * | ||
*/ | ||
var pick = rest(function(object, props) { | ||
var pick = baseRest(function(object, props) { | ||
return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); | ||
@@ -186,0 +538,0 @@ }); |
{ | ||
"name": "lodash.pick", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "The lodash method `_.pick` 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._baseflatten": "~4.2.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.pick v4.2.1 | ||
# lodash.pick v4.3.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.pick` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#pick) or [package source](https://github.com/lodash/lodash/blob/4.2.1-npm-packages/lodash.pick) for more details. | ||
See the [documentation](https://lodash.com/docs#pick) or [package source](https://github.com/lodash/lodash/blob/4.3.0-npm-packages/lodash.pick) 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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
17122
0
492
1
- Removedlodash._baseflatten@~4.2.0
- Removedlodash.rest@^4.0.0
- Removedlodash._baseflatten@4.2.1(transitive)
- Removedlodash.rest@4.0.5(transitive)