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

Function toJS

src/toJS.ts:13–44  ·  view source on GitHub ↗
(
  value: unknown
)

Source from the content-addressed store, hash-verified

11): Array<unknown> | { [key: string]: unknown };
12export function toJS(value: unknown): unknown;
13export function toJS(
14 value: unknown
15): Array<unknown> | { [key: string]: unknown } | unknown {
16 if (!value || typeof value !== 'object') {
17 return value;
18 }
19 if (!isCollection(value)) {
20 if (!isDataStructure(value)) {
21 return value;
22 }
23 // @ts-expect-error until Seq has been migrated to TypeScript
24 value = Seq(value);
25 }
26 if (isKeyed(value)) {
27 const result: { [key: string]: unknown } = {};
28 // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
29 value.__iterate((v, k) => {
30 if (isProtoKey(k)) {
31 return;
32 }
33
34 result[k] = toJS(v);
35 });
36 return result;
37 }
38 const result: Array<unknown> = [];
39 // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
40 value.__iterate((v: unknown) => {
41 result.push(toJS(v));
42 });
43 return result;
44}

Callers 2

toJSMethod · 0.90
toJSFunction · 0.90

Calls 7

isCollectionFunction · 0.90
SeqClass · 0.90
isKeyedFunction · 0.90
isProtoKeyFunction · 0.90
isDataStructureFunction · 0.85
pushMethod · 0.65
__iterateMethod · 0.45

Tested by

no test coverage detected