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

Function csv2json

src/lib/worker/command/csv.ts:13–33  ·  view source on GitHub ↗
(text: string, options: CsvOptions = {})

Source from the content-addressed store, hash-verified

11}
12
13export function csv2json(text: string, options: CsvOptions = {}): CsvResult {
14 const { data, errors, meta } = Papa.parse(text as any, {
15 header: options.withHeader,
16 skipEmptyLines: true,
17 });
18
19 let error = "";
20
21 if (errors.length > 0) {
22 error = errors[0].code;
23 } else if (text.trim().length === 0) {
24 error = "EmptyInput";
25 } else if (meta.aborted) {
26 error = "ParseError";
27 }
28
29 return {
30 text: JSON.stringify(data),
31 errorKey: error ? `CsvErr${error}` : undefined,
32 };
33}
34
35export function json2csv(treeObject: TreeObject): CsvResult {
36 const tree = Tree.fromObject(treeObject);

Callers

nothing calls this directly

Calls 1

stringifyMethod · 0.80

Tested by

no test coverage detected