| [a762898] | 1 | import { isBuffer } from '../../predicate/isBuffer.mjs';
|
|---|
| 2 | import { isPrototype } from '../_internal/isPrototype.mjs';
|
|---|
| 3 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 4 | import { isTypedArray } from '../predicate/isTypedArray.mjs';
|
|---|
| 5 | import { times } from '../util/times.mjs';
|
|---|
| 6 |
|
|---|
| 7 | function keys(object) {
|
|---|
| 8 | if (isArrayLike(object)) {
|
|---|
| 9 | return arrayLikeKeys(object);
|
|---|
| 10 | }
|
|---|
| 11 | const result = Object.keys(Object(object));
|
|---|
| 12 | if (!isPrototype(object)) {
|
|---|
| 13 | return result;
|
|---|
| 14 | }
|
|---|
| 15 | return result.filter(key => key !== 'constructor');
|
|---|
| 16 | }
|
|---|
| 17 | function arrayLikeKeys(object) {
|
|---|
| 18 | const indices = times(object.length, index => `${index}`);
|
|---|
| 19 | const filteredKeys = new Set(indices);
|
|---|
| 20 | if (isBuffer(object)) {
|
|---|
| 21 | filteredKeys.add('offset');
|
|---|
| 22 | filteredKeys.add('parent');
|
|---|
| 23 | }
|
|---|
| 24 | if (isTypedArray(object)) {
|
|---|
| 25 | filteredKeys.add('buffer');
|
|---|
| 26 | filteredKeys.add('byteLength');
|
|---|
| 27 | filteredKeys.add('byteOffset');
|
|---|
| 28 | }
|
|---|
| 29 | const inheritedKeys = Object.keys(object).filter(key => !filteredKeys.has(key));
|
|---|
| 30 | if (Array.isArray(object)) {
|
|---|
| 31 | return [...indices, ...inheritedKeys];
|
|---|
| 32 | }
|
|---|
| 33 | return [...indices.filter(index => Object.hasOwn(object, index)), ...inheritedKeys];
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | export { keys };
|
|---|