| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isBuffer = require('../../predicate/isBuffer.js');
|
|---|
| 6 | const isPrototype = require('../_internal/isPrototype.js');
|
|---|
| 7 | const isArrayLike = require('../predicate/isArrayLike.js');
|
|---|
| 8 | const isTypedArray = require('../predicate/isTypedArray.js');
|
|---|
| 9 | const times = require('../util/times.js');
|
|---|
| 10 |
|
|---|
| 11 | function keysIn(object) {
|
|---|
| 12 | if (object == null) {
|
|---|
| 13 | return [];
|
|---|
| 14 | }
|
|---|
| 15 | switch (typeof object) {
|
|---|
| 16 | case 'object':
|
|---|
| 17 | case 'function': {
|
|---|
| 18 | if (isArrayLike.isArrayLike(object)) {
|
|---|
| 19 | return arrayLikeKeysIn(object);
|
|---|
| 20 | }
|
|---|
| 21 | if (isPrototype.isPrototype(object)) {
|
|---|
| 22 | return prototypeKeysIn(object);
|
|---|
| 23 | }
|
|---|
| 24 | return keysInImpl(object);
|
|---|
| 25 | }
|
|---|
| 26 | default: {
|
|---|
| 27 | return keysInImpl(Object(object));
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 | function keysInImpl(object) {
|
|---|
| 32 | const result = [];
|
|---|
| 33 | for (const key in object) {
|
|---|
| 34 | result.push(key);
|
|---|
| 35 | }
|
|---|
| 36 | return result;
|
|---|
| 37 | }
|
|---|
| 38 | function prototypeKeysIn(object) {
|
|---|
| 39 | const keys = keysInImpl(object);
|
|---|
| 40 | return keys.filter(key => key !== 'constructor');
|
|---|
| 41 | }
|
|---|
| 42 | function arrayLikeKeysIn(object) {
|
|---|
| 43 | const indices = times.times(object.length, index => `${index}`);
|
|---|
| 44 | const filteredKeys = new Set(indices);
|
|---|
| 45 | if (isBuffer.isBuffer(object)) {
|
|---|
| 46 | filteredKeys.add('offset');
|
|---|
| 47 | filteredKeys.add('parent');
|
|---|
| 48 | }
|
|---|
| 49 | if (isTypedArray.isTypedArray(object)) {
|
|---|
| 50 | filteredKeys.add('buffer');
|
|---|
| 51 | filteredKeys.add('byteLength');
|
|---|
| 52 | filteredKeys.add('byteOffset');
|
|---|
| 53 | }
|
|---|
| 54 | const inheritedKeys = keysInImpl(object).filter(key => !filteredKeys.has(key));
|
|---|
| 55 | if (Array.isArray(object)) {
|
|---|
| 56 | return [...indices, ...inheritedKeys];
|
|---|
| 57 | }
|
|---|
| 58 | return [...indices.filter(index => Object.hasOwn(object, index)), ...inheritedKeys];
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | exports.keysIn = keysIn;
|
|---|