@newdash/newdash
Version:
javascript/typescript utility library
75 lines (74 loc) • 1.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.keysIn = void 0;
const isArrayLike_1 = __importDefault(require("./isArrayLike"));
const arrayLikeKeys_1 = __importDefault(require("./.internal/arrayLikeKeys"));
const isObject_1 = __importDefault(require("./isObject"));
const isPrototype_1 = __importDefault(require("./.internal/isPrototype"));
/**
* @ignore
* @private
*/
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* @private
* @ignore
* @param object
*/
function nativeKeysIn(object) {
const result = [];
if (object != null) {
for (const key in Object(object)) {
result.push(key);
}
}
return result;
}
/**
* @ignore
* @private
* @param object ant
*/
function baseKeysIn(object) {
if (!(0, isObject_1.default)(object)) {
return nativeKeysIn(object);
}
const isProto = (0, isPrototype_1.default)(object);
const result = [];
for (const key in object) {
if (!(key == "constructor" && (isProto || !hasOwnProperty.call(object, key)))) {
result.push(key);
}
}
return result;
}
/**
* Creates an array of the own and inherited enumerable property names of `object`.
*
*
* @since 5.5.0
* @category Object
* @param object The object to query.
* @returns Returns the array of property names.
* @example
*
* ```js
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* keysIn(new Foo);
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
* ```
*/
function keysIn(object) {
return (0, isArrayLike_1.default)(object) ? (0, arrayLikeKeys_1.default)(object, true) : baseKeysIn(object);
}
exports.keysIn = keysIn;
exports.default = keysIn;