lodash.keys
Advanced tools
Comparing version 3.1.2 to 4.0.0
411
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 getNative = require('lodash._getnative'), | ||
isArguments = require('lodash.isarguments'), | ||
isArray = require('lodash.isarray'); | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var argsTag = '[object Arguments]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
stringTag = '[object String]'; | ||
/** Used to detect unsigned integer values. */ | ||
var reIsUint = /^\d+$/; | ||
var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** Used for native method references. */ | ||
var objectProto = Object.prototype; | ||
/** | ||
* The base implementation of `_.times` without support for iteratee shorthands | ||
* or max array length checks. | ||
* | ||
* @private | ||
* @param {number} n The number of times to invoke `iteratee`. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the array of results. | ||
*/ | ||
function baseTimes(n, iteratee) { | ||
var index = -1, | ||
result = Array(n); | ||
while (++index < n) { | ||
result[index] = iteratee(index); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
* | ||
* @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; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/* Native method references for those with the same name as other `lodash` methods. */ | ||
var nativeKeys = getNative(Object, 'keys'); | ||
/** | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** Built-in value references. */ | ||
var getPrototypeOf = Object.getPrototypeOf, | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeKeys = Object.keys; | ||
/** | ||
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) | ||
* of an array-like value. | ||
* The base implementation of `_.has` without support for deep paths. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} key The key to check. | ||
* @returns {boolean} Returns `true` if `key` exists, else `false`. | ||
*/ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
function baseHas(object, key) { | ||
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, | ||
// that are composed entirely of index properties, return `false` for | ||
// `hasOwnProperty` checks of them. | ||
return hasOwnProperty.call(object, key) || | ||
(typeof object == 'object' && key in object && getPrototypeOf(object) === null); | ||
} | ||
/** | ||
* The base implementation of `_.keys` which doesn't skip the constructor | ||
* property of prototypes or treat sparse arrays as dense. | ||
* | ||
* @private | ||
* @type Function | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
*/ | ||
function baseKeys(object) { | ||
return nativeKeys(Object(object)); | ||
} | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
@@ -57,68 +129,188 @@ * | ||
/** | ||
* Checks if `value` is array-like. | ||
* Creates an array of index keys for `object` values of arrays, | ||
* `arguments` objects, and strings, otherwise `null` is returned. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @param {Object} object The object to query. | ||
* @returns {Array|null} Returns index keys, else `null`. | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && isLength(getLength(value)); | ||
function indexKeys(object) { | ||
var length = object ? object.length : undefined; | ||
return (isLength(length) && (isArray(object) || isString(object) || isArguments(object))) | ||
? baseTimes(length, String) | ||
: null; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
* Checks if `value` is likely a prototype object. | ||
* | ||
* @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`. | ||
* @returns {boolean} Returns `true` if `value` is a prototype, 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; | ||
function isPrototype(value) { | ||
var Ctor = value && value.constructor, | ||
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; | ||
return value === proto; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like length. | ||
* Checks if `value` is likely an `arguments` object. | ||
* | ||
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* _.isArguments(function() { return arguments; }()); | ||
* // => true | ||
* | ||
* _.isArguments([1, 2, 3]); | ||
* // => false | ||
*/ | ||
function isLength(value) { | ||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | ||
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); | ||
} | ||
/** | ||
* A fallback implementation of `Object.keys` which creates an array of the | ||
* own enumerable property names of `object`. | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
function shimKeys(object) { | ||
var props = keysIn(object), | ||
propsLength = props.length, | ||
length = propsLength && object.length; | ||
var isArray = Array.isArray; | ||
var allowIndexes = !!length && isLength(length) && | ||
(isArray(object) || isArguments(object)); | ||
/** | ||
* 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 _ | ||
* @type Function | ||
* @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 && | ||
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value)); | ||
} | ||
var index = -1, | ||
result = []; | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @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); | ||
} | ||
while (++index < propsLength) { | ||
var key = props[index]; | ||
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) { | ||
result.push(key); | ||
} | ||
} | ||
return result; | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, 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 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 _ | ||
* @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](https://es5.github.io/#x8) of `Object`. | ||
@@ -140,3 +332,6 @@ * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* _.isObject(1); | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
@@ -152,42 +347,56 @@ */ | ||
/** | ||
* Creates an array of the own enumerable property names of `object`. | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* **Note:** Non-object values are coerced to objects. See the | ||
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) | ||
* for more details. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* function Foo() { | ||
* this.a = 1; | ||
* this.b = 2; | ||
* } | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* Foo.prototype.c = 3; | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.keys(new Foo); | ||
* // => ['a', 'b'] (iteration order is not guaranteed) | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.keys('hi'); | ||
* // => ['0', '1'] | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
var keys = !nativeKeys ? shimKeys : function(object) { | ||
var Ctor = object == null ? undefined : object.constructor; | ||
if ((typeof Ctor == 'function' && Ctor.prototype === object) || | ||
(typeof object != 'function' && isArrayLike(object))) { | ||
return shimKeys(object); | ||
} | ||
return isObject(object) ? nativeKeys(object) : []; | ||
}; | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Creates an array of the own and inherited enumerable property names of `object`. | ||
* Checks if `value` is classified as a `String` primitive or object. | ||
* | ||
* **Note:** Non-object values are coerced to objects. | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isString('abc'); | ||
* // => true | ||
* | ||
* _.isString(1); | ||
* // => false | ||
*/ | ||
function isString(value) { | ||
return typeof value == 'string' || | ||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag); | ||
} | ||
/** | ||
* Creates an array of the own enumerable property names of `object`. | ||
* | ||
* **Note:** Non-object values are coerced to objects. See the | ||
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) | ||
* for more details. | ||
* | ||
* @static | ||
@@ -207,28 +416,22 @@ * @memberOf _ | ||
* | ||
* _.keysIn(new Foo); | ||
* // => ['a', 'b', 'c'] (iteration order is not guaranteed) | ||
* _.keys(new Foo); | ||
* // => ['a', 'b'] (iteration order is not guaranteed) | ||
* | ||
* _.keys('hi'); | ||
* // => ['0', '1'] | ||
*/ | ||
function keysIn(object) { | ||
if (object == null) { | ||
return []; | ||
function keys(object) { | ||
var isProto = isPrototype(object); | ||
if (!(isProto || isArrayLike(object))) { | ||
return baseKeys(object); | ||
} | ||
if (!isObject(object)) { | ||
object = Object(object); | ||
} | ||
var length = object.length; | ||
length = (length && isLength(length) && | ||
(isArray(object) || isArguments(object)) && length) || 0; | ||
var indexes = indexKeys(object), | ||
skipIndexes = !!indexes, | ||
result = indexes || [], | ||
length = result.length; | ||
var Ctor = object.constructor, | ||
index = -1, | ||
isProto = typeof Ctor == 'function' && Ctor.prototype === object, | ||
result = Array(length), | ||
skipIndexes = length > 0; | ||
while (++index < length) { | ||
result[index] = (index + ''); | ||
} | ||
for (var key in object) { | ||
if (!(skipIndexes && isIndex(key, length)) && | ||
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { | ||
if (baseHas(object, key) && | ||
!(skipIndexes && (key == 'length' || isIndex(key, length))) && | ||
!(isProto && key == 'constructor')) { | ||
result.push(key); | ||
@@ -235,0 +438,0 @@ } |
{ | ||
"name": "lodash.keys", | ||
"version": "3.1.2", | ||
"description": "The modern build of lodash’s `_.keys` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.keys` 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, keys", | ||
"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/)" | ||
], | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash._getnative": "^3.0.0", | ||
"lodash.isarguments": "^3.0.0", | ||
"lodash.isarray": "^3.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.keys v3.1.2 | ||
# lodash.keys v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.keys` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.keys` 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 keys = require('lodash.keys'); | ||
See the [documentation](https://lodash.com/docs#keys) or [package source](https://github.com/lodash/lodash/blob/3.1.2-npm-packages/lodash.keys) for more details. | ||
See the [documentation](https://lodash.com/docs#keys) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.keys) for more details. |
Sorry, the diff of this file is not supported yet
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
14063
0
409
19
1
- Removedlodash._getnative@^3.0.0
- Removedlodash.isarguments@^3.0.0
- Removedlodash.isarray@^3.0.0
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)