moltres-utils
Version:
Utils for Moltres apps
57 lines (45 loc) • 2.08 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _isBuffer = _interopRequireDefault(require("../buffer/isBuffer"));
var _isArguments = _interopRequireDefault(require("./isArguments"));
var _isIndex = _interopRequireDefault(require("./isIndex"));
var _isTypedArray = _interopRequireDefault(require("./isTypedArray"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** 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`.
*
* @param {*} value The value to query.
* @param {boolean} inherited Specify returning inherited property names.
* @returns {Array} Returns the array of property names.
*/
const arrayLikeKeys = (value, inherited) => {
const isArr = Array.isArray(value);
const isArg = !isArr && (0, _isArguments.default)(value);
const isBuff = !isArr && !isArg && (0, _isBuffer.default)(value);
const isType = !isArr && !isArg && !isBuff && (0, _isTypedArray.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' || // 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.
(0, _isIndex.default)(key, length)))) {
result.push(key);
}
}
return result;
};
var _default = arrayLikeKeys;
exports.default = _default;
//# sourceMappingURL=arrayLikeKeys.js.map
;