MCPcopy Index your code
hub / github.com/immutable-js/immutable-js / isArrayLike

Function isArrayLike

src/utils/isArrayLike.ts:1–25  ·  view source on GitHub ↗
(
  value: unknown
)

Source from the content-addressed store, hash-verified

1export 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}

Callers 3

fromJSWithFunction · 0.85
maybeIndexedSeqFromValueFunction · 0.85
coerceKeyPathFunction · 0.85

Calls 1

keysMethod · 0.80

Tested by

no test coverage detected