(data: Record<string, string>[])
| 45 | } |
| 46 | |
| 47 | export 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 | |
| 57 | export async function convert( |
| 58 | filePath: string, |
no test coverage detected