( value: unknown )
| 1 | export default function isArrayLike( |
| 2 | value: unknown |
| 3 | ): value is ArrayLike<unknown> { |
| 4 | if (Array.isArray(value) || typeof value === 'string') { |
| 5 | return true; |
| 6 | } |
| 7 | |
| 8 | // @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean |
| 9 | return ( |
| 10 | value && |
| 11 | typeof value === 'object' && |
| 12 | // @ts-expect-error check that `'length' in value &&` |
| 13 | Number.isInteger(value.length) && |
| 14 | // @ts-expect-error check that `'length' in value &&` |
| 15 | value.length >= 0 && |
| 16 | // @ts-expect-error check that `'length' in value &&` |
| 17 | (value.length === 0 |
| 18 | ? // Only {length: 0} is considered Array-like. |
| 19 | Object.keys(value).length === 1 |
| 20 | : // An object is only Array-like if it has a property where the last value |
| 21 | // in the array-like may be found (which could be undefined). |
| 22 | // @ts-expect-error check that `'length' in value &&` |
| 23 | value.hasOwnProperty(value.length - 1)) |
| 24 | ); |
| 25 | } |
no test coverage detected