MCPcopy Index your code
hub / github.com/angular/angular-cli / isJSONSerializable

Function isJSONSerializable

packages/angular/cli/src/utilities/memoize.ts:57–77  ·  view source on GitHub ↗

Method to check if the values are JSON serializable

(value: unknown)

Source from the content-addressed store, hash-verified

55
56/** Method to check if the values are JSON serializable */
57function isJSONSerializable(value: unknown): boolean {
58 if (!isNonPrimitive(value)) {
59 // Can be seralized since it's a primitive.
60 return true;
61 }
62
63 let nestedValues: unknown[] | undefined;
64 if (Array.isArray(value)) {
65 // It's an array, check each item.
66 nestedValues = value;
67 } else if (Object.prototype.toString.call(value) === '[object Object]') {
68 // It's a plain object, check each value.
69 nestedValues = Object.values(value);
70 }
71
72 if (!nestedValues || nestedValues.some((v) => !isJSONSerializable(v))) {
73 return false;
74 }
75
76 return true;
77}

Callers 1

memoizeFunction · 0.85

Calls 3

isNonPrimitiveFunction · 0.85
callMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected