* Detects the CSV delimiter from a header line by frequency. Mirrors the file viewer's * client-side heuristic (comma / tab / semicolon) so server-streamed previews match.
(line: string)
| 29 | * client-side heuristic (comma / tab / semicolon) so server-streamed previews match. |
| 30 | */ |
| 31 | function detectDelimiter(line: string): string { |
| 32 | const commaCount = (line.match(/,/g) || []).length |
| 33 | const tabCount = (line.match(/\t/g) || []).length |
| 34 | const semiCount = (line.match(/;/g) || []).length |
| 35 | if (tabCount > commaCount && tabCount > semiCount) return '\t' |
| 36 | if (semiCount > commaCount) return ';' |
| 37 | return ',' |
| 38 | } |
| 39 | |
| 40 | function cell(value: unknown): string { |
| 41 | return truncate(String(value ?? ''), MAX_CELL_LENGTH) |
no outgoing calls
no test coverage detected