MCPcopy
hub / github.com/C4illin/ConvertX / toCSV

Function toCSV

src/converters/vcf.ts:47–55  ·  view source on GitHub ↗
(data: Record<string, string>[])

Source from the content-addressed store, hash-verified

45}
46
47export function toCSV(data: Record<string, string>[]): string {
48 if (!data.length) return "";
49 const first = data[0];
50 if (!first) return "";
51 const headers = Object.keys(first);
52 const escape = (str: string) => `"${str.replace(/"/g, '""')}"`;
53 const rows = data.map((row) => headers.map((h) => escape(row[h] || "")).join(","));
54 return [headers.join(","), ...rows].join("\n");
55}
56
57export async function convert(
58 filePath: string,

Callers 2

vcf.test.tsFile · 0.90
convertFunction · 0.85

Calls 1

escapeFunction · 0.85

Tested by

no test coverage detected