MCPcopy Create free account
hub / github.com/JS-DevTools/ono / prettyPrintValue

Function prettyPrintValue

test/utils/compare-pojo.js:108–141  ·  view source on GitHub ↗
(value, indent)

Source from the content-addressed store, hash-verified

106}
107
108function prettyPrintValue (value, indent) {
109 let type = typeof value;
110
111 switch (type) {
112 case "string":
113 return JSON.stringify(value);
114
115 case "number":
116 case "boolean":
117 case "undefined":
118 case "symbol":
119 return String(value);
120
121 case "function":
122 return `[function ${value.name}]`;
123
124 default:
125 if (value === null) {
126 return "null";
127 }
128 else if (typeof value.toJSON === "function") {
129 return prettyPrintValue(value.toJSON(), indent);
130 }
131 else {
132 let str = String(value);
133 if (str === "[object Object]") {
134 return prettyPrint(value, `${indent} `);
135 }
136 else {
137 return str;
138 }
139 }
140 }
141}

Callers 1

prettyPrintFunction · 0.85

Calls 2

prettyPrintFunction · 0.85
toJSONMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…