Spaces:
Sleeping
Sleeping
Download frontend/src/lib/csv.ts from Sid-WC121/visual-notebook: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/spaces/Sid-WC121/visual-notebook/resolve/main/frontend/src/lib/csv.ts
- Command line
-
hf download hf://spaces/Sid-WC121/visual-notebook/frontend/src/lib/csv.ts
-
curl -L -o csv.ts https://huggingface.co/spaces/Sid-WC121/visual-notebook/resolve/main/frontend/src/lib/csv.ts
825 Bytes
| /** CSV download helper */ | |
| export function downloadBlob(blob: Blob, filename: string) { | |
| const url = window.URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = filename; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| window.URL.revokeObjectURL(url); | |
| } | |
| /** Parse a CSV string into rows */ | |
| export function parseCSVPreview(csvText: string, maxRows = 5): string[][] { | |
| const lines = csvText.split('\n').slice(0, maxRows); | |
| return lines.map((line) => line.split(',').map((cell) => cell.trim())); | |
| } | |
| /** File size formatter */ | |
| export function formatFileSize(bytes: number): string { | |
| if (bytes < 1024) return `${bytes} B`; | |
| if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; | |
| return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; | |
| } | |