UNPKG

moltres-utils

Version:
90 lines (70 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _curry = _interopRequireDefault(require("./curry")); var _hasProp = _interopRequireDefault(require("./hasProp")); var _isArguments = _interopRequireDefault(require("./isArguments")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // cover IE < 9 keys issues const hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString'); const nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug const hasArgsEnumBug = function () { return arguments.propertyIsEnumerable('length'); }(); const contains = (list, item) => { let idx = 0; while (idx < list.length) { if (list[idx] === item) { return true; } idx += 1; } return false; }; /** * Returns a list containing the names of all the enumerable own properties of the supplied object. * Note that the order of the output array is not guaranteed to be consistent across different JS platforms. * * @func * @since v0.1.0 * @category data * @param {Object} obj The object to extract properties from * @returns {Array} An array of the object's own properties. * @example * * objectKeys({a: 1, b: 2, c: 3}) //=> ['a', 'b', 'c'] */ const objectKeys = typeof Object.keys === 'function' && !hasArgsEnumBug ? (0, _curry.default)(obj => { return Object(obj) !== obj ? [] : Object.keys(obj); }) : (0, _curry.default)(obj => { if (Object(obj) !== obj) { return []; } let prop; let nIdx; const ks = []; const checkArgsLength = hasArgsEnumBug && (0, _isArguments.default)(obj); for (prop in obj) { if ((0, _hasProp.default)(prop, obj) && (!checkArgsLength || prop !== 'length')) { ks[ks.length] = prop; } } if (hasEnumBug) { nIdx = nonEnumerableProps.length - 1; while (nIdx >= 0) { prop = nonEnumerableProps[nIdx]; if ((0, _hasProp.default)(prop, obj) && !contains(ks, prop)) { ks[ks.length] = prop; } nIdx -= 1; } } return ks; }); var _default = objectKeys; exports.default = _default; //# sourceMappingURL=objectKeys.js.map