Files
no-copy-frontend/src/app/lib/convertBytes.ts
T
2026-02-04 13:21:32 +07:00

20 lines
312 B
TypeScript

export function convertBytes(bytes: number) {
if (!bytes) {
return 0;
}
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return '0 B';
let i = 0;
let value = bytes;
while (value >= 1024 && i < units.length - 1) {
value /= 1024;
i++;
}
return `${value.toFixed(1)} ${units[i]}`;
}