MCPcopy
hub / github.com/loggerhead/json4u / parseAndFormat

Function parseAndFormat

src/lib/worker/command/parse.ts:18–41  ·  view source on GitHub ↗
(text: string, options?: ParseAndFormatOptions)

Source from the content-addressed store, hash-verified

16}
17
18export async function parseAndFormat(text: string, options?: ParseAndFormatOptions): Promise<ParsedTree> {
19 // 5MB costs 240ms
20 const tree = parseJSON(text, options);
21
22 if (options?.kind === "main") {
23 getViewState().setTree(tree);
24 }
25
26 if (!tree.valid()) {
27 if (options?.format) {
28 tree.text = prettyFormat(text, options);
29 }
30 return { treeObject: tree.toObject() };
31 }
32
33 if (options?.format) {
34 // 5MB costs 69ms
35 tree.stringify(options);
36 } else if (!isEmpty(tree.nestNodeMap)) {
37 tree.stringifyNestNodes();
38 }
39
40 return { treeObject: tree.toObject() };
41}

Callers 1

doExpectFunction · 0.90

Calls 7

parseJSONFunction · 0.90
prettyFormatFunction · 0.90
setTreeMethod · 0.80
validMethod · 0.80
toObjectMethod · 0.80
stringifyMethod · 0.80
stringifyNestNodesMethod · 0.80

Tested by 1

doExpectFunction · 0.72