| export function capitalize(name: string) { | |
| return name.charAt(0).toUpperCase() + name.slice(1); | |
| } | |
| export function formatBytes(bytes: number): string { | |
| if (!Number.isFinite(bytes) || bytes <= 0) return "0 B"; | |
| const k = 1024; | |
| const sizes = ["B", "KB", "MB", "GB", "TB"]; | |
| const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1); | |
| return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`; | |
| } |