mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Move internal modules to “internal” folder.
This commit is contained in:
44
.internal/arrayLikeKeys.js
Normal file
44
.internal/arrayLikeKeys.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import baseTimes from './.internal/baseTimes.js';
|
||||
import isArguments from './isArguments.js';
|
||||
import isBuffer from './isBuffer.js';
|
||||
import isIndex from './.internal/isIndex.js';
|
||||
import isTypedArray from './isTypedArray.js';
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Creates an array of the enumerable property names of the array-like `value`.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to query.
|
||||
* @param {boolean} inherited Specify returning inherited property names.
|
||||
* @returns {Array} Returns the array of property names.
|
||||
*/
|
||||
function arrayLikeKeys(value, inherited) {
|
||||
const isArr = Array.isArray(value);
|
||||
const isArg = !isArr && isArguments(value);
|
||||
const isBuff = !isArr && !isArg && isBuffer(value);
|
||||
const isType = !isArr && !isArg && !isBuff && isTypedArray(value);
|
||||
const skipIndexes = isArr || isArg || isBuff || isType;
|
||||
const result = skipIndexes ? baseTimes(value.length, String) : [];
|
||||
const length = result.length;
|
||||
|
||||
for (const key in value) {
|
||||
if ((inherited || hasOwnProperty.call(value, key)) &&
|
||||
!(skipIndexes && (
|
||||
// Safari 9 has enumerable `arguments.length` in strict mode.
|
||||
(key == 'length' ||
|
||||
// Node.js 0.10 has enumerable non-index properties on buffers.
|
||||
(isBuff && (key == 'offset' || key == 'parent')) ||
|
||||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
|
||||
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || // Skip index properties.
|
||||
isIndex(key, length))
|
||||
))) {
|
||||
result.push(key);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default arrayLikeKeys;
|
||||
Reference in New Issue
Block a user