| 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 keys(object) {
|
|---|
| 12 | if (isArrayLike.isArrayLike(object)) {
|
|---|
| 13 | return arrayLikeKeys(object);
|
|---|
| 14 | }
|
|---|
| 15 | const result = Object.keys(Object(object));
|
|---|
| 16 | if (!isPrototype.isPrototype(object)) {
|
|---|
| 17 | return result;
|
|---|
| 18 | }
|
|---|
| 19 | return result.filter(key => key !== 'constructor');
|
|---|
| 20 | }
|
|---|
| 21 | function arrayLikeKeys(object) {
|
|---|
| 22 | const indices = times.times(object.length, index => `${index}`);
|
|---|
| 23 | const filteredKeys = new Set(indices);
|
|---|
| 24 | if (isBuffer.isBuffer(object)) {
|
|---|
| 25 | filteredKeys.add('offset');
|
|---|
| 26 | filteredKeys.add('parent');
|
|---|
| 27 | }
|
|---|
| 28 | if (isTypedArray.isTypedArray(object)) {
|
|---|
| 29 | filteredKeys.add('buffer');
|
|---|
| 30 | filteredKeys.add('byteLength');
|
|---|
| 31 | filteredKeys.add('byteOffset');
|
|---|
| 32 | }
|
|---|
| 33 | const inheritedKeys = Object.keys(object).filter(key => !filteredKeys.has(key));
|
|---|
| 34 | if (Array.isArray(object)) {
|
|---|
| 35 | return [...indices, ...inheritedKeys];
|
|---|
| 36 | }
|
|---|
| 37 | return [...indices.filter(index => Object.hasOwn(object, index)), ...inheritedKeys];
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | exports.keys = keys;
|
|---|