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

Function normalizeResult

website/src/worker/normalizeResult.ts:21–66  ·  view source on GitHub ↗
(
  immutableFormaters: Array<DevToolsFormatter>,
  result: unknown
)

Source from the content-addressed store, hash-verified

19}
20
21export default function normalizeResult(
22 immutableFormaters: Array<DevToolsFormatter>,
23 result: unknown
24): JsonMLElementList | Element {
25 const formatter = getFormatter(immutableFormaters, result);
26
27 if (!formatter) {
28 if (Array.isArray(result) && result[0] === 'object' && result[1]?.object) {
29 // handle special case for deep objects
30 const objectFormatter = getFormatter(
31 immutableFormaters,
32 result[1].object
33 );
34
35 if (objectFormatter) {
36 return normalizeResult(immutableFormaters, result[1].object);
37 }
38 }
39
40 if (typeof result !== 'string' && isElement(result)) {
41 return normalizeElement(immutableFormaters, result);
42 }
43
44 if (typeof result === 'string') {
45 return result;
46 }
47
48 return JSON.stringify(result);
49 }
50
51 const header = formatter.header(result) ?? [];
52
53 let body: JsonMLElementList | null = formatter.hasBody(result)
54 ? formatter.body(result)
55 : null;
56
57 if (body) {
58 body = body.map((item) => normalizeElement(immutableFormaters, item));
59 }
60
61 if (!body) {
62 return ['span', header];
63 }
64
65 return ['span', header, body];
66}
67
68function normalizeElement(
69 immutableFormaters: Array<DevToolsFormatter>,

Callers 3

index.tsFile · 0.85
normalizeElementFunction · 0.85

Calls 4

isElementFunction · 0.90
getFormatterFunction · 0.85
normalizeElementFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected