* Convert table data to CSV string
(headers: string[], rows: string[][])
| 54 | * Convert table data to CSV string |
| 55 | */ |
| 56 | function toCsv(headers: string[], rows: string[][]): string { |
| 57 | const escapeCell = (cell: string): string => { |
| 58 | if (cell.includes(',') || cell.includes('"') || cell.includes('\n')) { |
| 59 | return `"${cell.replace(/"/g, '""')}"` |
| 60 | } |
| 61 | return cell |
| 62 | } |
| 63 | |
| 64 | const headerLine = headers.map(escapeCell).join(',') |
| 65 | const dataLines = rows.map((row) => row.map(escapeCell).join(',')) |
| 66 | |
| 67 | return [headerLine, ...dataLines].join('\n') |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * CSV Table Editor Component |
no outgoing calls
no test coverage detected