@newdash/newdash
Version:
javascript/typescript utility library
45 lines (44 loc) • 1.85 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const isArguments_1 = __importDefault(require("../isArguments"));
const isBuffer_1 = __importDefault(require("../isBuffer"));
const isIndex_1 = __importDefault(require("./isIndex"));
const isTypedArray_1 = __importDefault(require("../isTypedArray"));
/** 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 = false) {
const isArr = Array.isArray(value);
const isArg = !isArr && (0, isArguments_1.default)(value);
const isBuff = !isArr && !isArg && (0, isBuffer_1.default)(value);
const isType = !isArr && !isArg && !isBuff && (0, isTypedArray_1.default)(value);
const skipIndexes = isArr || isArg || isBuff || isType;
const length = value.length;
const result = new Array(skipIndexes ? length : 0);
let index = skipIndexes ? -1 : length;
while (++index < length) {
result[index] = `${index}`;
}
for (const key in value) {
if ((inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
(key === 'length' ||
// Skip index properties.
(0, isIndex_1.default)(key, length))))) {
result.push(key);
}
}
return result;
}
exports.default = arrayLikeKeys;