Spaces:
Sleeping
Sleeping
| export function formatBytes(bytes: number): string { | |
| if (!Number.isFinite(bytes)) return "0 B"; | |
| const units = ["B", "KB", "MB", "GB"]; | |
| let value = bytes; | |
| let idx = 0; | |
| while (value >= 1024 && idx < units.length - 1) { | |
| value /= 1024; | |
| idx += 1; | |
| } | |
| const digits = value >= 10 || idx === 0 ? 0 : 1; | |
| return `${value.toFixed(digits)} ${units[idx]}`; | |
| } | |