Download console/src/lib/csv.ts from bryceweiner/fly-trader: direct link, hf CLI and curl.
- Browser
- Download file 780 Bytes
-
https://huggingface.co/bryceweiner/fly-trader/resolve/main/console/src/lib/csv.ts
- Command line
-
hf download hf://bryceweiner/fly-trader/console/src/lib/csv.ts
-
curl -L -o csv.ts https://huggingface.co/bryceweiner/fly-trader/resolve/main/console/src/lib/csv.ts
780 Bytes
| /** Rows as CSV (RFC 4180 quoting), downloaded as a file — the tables' "Download" button. */ | |
| export function toCsv(headers: string[], rows: unknown[][]): string { | |
| const cell = (v: unknown): string => { | |
| if (v === null || v === undefined) return '' | |
| const s = typeof v === 'object' ? JSON.stringify(v) : String(v) | |
| return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s | |
| } | |
| return [headers.map(cell).join(','), ...rows.map((r) => r.map(cell).join(','))].join('\r\n') | |
| } | |
| export function download(filename: string, text: string, type = 'text/csv'): void { | |
| const url = URL.createObjectURL(new Blob([text], { type })) | |
| const a = document.createElement('a') | |
| a.href = url | |
| a.download = filename | |
| a.click() | |
| setTimeout(() => URL.revokeObjectURL(url), 1000) | |
| } | |