mirror of
https://github.com/logos-storage/logos-storage-marketplace-ui.git
synced 2026-01-11 18:03:12 +00:00
17 lines
376 B
TypeScript
17 lines
376 B
TypeScript
export const Bytes = {
|
|
pretty(bytes: number) {
|
|
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
|
if (bytes == 0) {
|
|
return "0 B";
|
|
}
|
|
|
|
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
|
|
|
|
if (i == 0) {
|
|
return bytes.toFixed(1) + " " + sizes[i];
|
|
}
|
|
|
|
return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
|
|
}
|
|
|
|
} |