UNPKG

1.41 kBJavaScriptView Raw
1import baseKeysIn from './_baseKeysIn';
2import indexKeys from './_indexKeys';
3import isIndex from './_isIndex';
4import isPrototype from './_isPrototype';
5
6/** Used for built-in method references. */
7var objectProto = Object.prototype;
8
9/** Used to check objects for own properties. */
10var hasOwnProperty = objectProto.hasOwnProperty;
11
12/**
13 * Creates an array of the own and inherited enumerable property names of `object`.
14 *
15 * **Note:** Non-object values are coerced to objects.
16 *
17 * @static
18 * @memberOf _
19 * @since 3.0.0
20 * @category Object
21 * @param {Object} object The object to query.
22 * @returns {Array} Returns the array of property names.
23 * @example
24 *
25 * function Foo() {
26 * this.a = 1;
27 * this.b = 2;
28 * }
29 *
30 * Foo.prototype.c = 3;
31 *
32 * _.keysIn(new Foo);
33 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
34 */
35function keysIn(object) {
36 var index = -1,
37 isProto = isPrototype(object),
38 props = baseKeysIn(object),
39 propsLength = props.length,
40 indexes = indexKeys(object),
41 skipIndexes = !!indexes,
42 result = indexes || [],
43 length = result.length;
44
45 while (++index < propsLength) {
46 var key = props[index];
47 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
48 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
49 result.push(key);
50 }
51 }
52 return result;
53}
54
55export default keysIn;