mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Bump to v3.0.0.
This commit is contained in:
42
internal/shimKeys.js
Normal file
42
internal/shimKeys.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import isArguments from '../lang/isArguments';
|
||||
import isArray from '../lang/isArray';
|
||||
import isIndex from './isIndex';
|
||||
import isLength from './isLength';
|
||||
import keysIn from '../object/keysIn';
|
||||
import support from '../support';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* A fallback implementation of `Object.keys` which creates an array of the
|
||||
* own enumerable property names of `object`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to inspect.
|
||||
* @returns {Array} Returns the array of property names.
|
||||
*/
|
||||
function shimKeys(object) {
|
||||
var props = keysIn(object),
|
||||
propsLength = props.length,
|
||||
length = propsLength && object.length;
|
||||
|
||||
var allowIndexes = length && isLength(length) &&
|
||||
(isArray(object) || (support.nonEnumArgs && isArguments(object)));
|
||||
|
||||
var index = -1,
|
||||
result = [];
|
||||
|
||||
while (++index < propsLength) {
|
||||
var key = props[index];
|
||||
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
|
||||
result.push(key);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default shimKeys;
|
||||
Reference in New Issue
Block a user