Sid-WC121
initial
c21180c
Raw History Blame Contribute Delete
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`;
}