Spaces:
Sleeping
Sleeping
File size: 368 Bytes
1643ce8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | 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]}`;
}
|