revert changes

This commit is contained in:
mhsanaei 2024-10-17 10:34:30 +02:00
parent 99cadf7652
commit 514c4909a4
No known key found for this signature in database
GPG key ID: 4DACC0663B5986F5

View file

@ -1,19 +1,25 @@
const ONE_KB = 1024;
const units = ["B", "KB", "MB", "GB", "TB", "PB"];
const ONE_MB = ONE_KB * 1024;
const ONE_GB = ONE_MB * 1024;
const ONE_TB = ONE_GB * 1024;
const ONE_PB = ONE_TB * 1024;
function sizeFormat(size) {
if (size < 0) {
return "0 B";
if (size <= 0) return "0 B";
if (size < ONE_KB) {
return size.toFixed(0) + " B";
} else if (size < ONE_MB) {
return (size / ONE_KB).toFixed(2) + " KB";
} else if (size < ONE_GB) {
return (size / ONE_MB).toFixed(2) + " MB";
} else if (size < ONE_TB) {
return (size / ONE_GB).toFixed(2) + " GB";
} else if (size < ONE_PB) {
return (size / ONE_TB).toFixed(2) + " TB";
} else {
return (size / ONE_PB).toFixed(2) + " PB";
}
let index = 0;
while (size >= ONE_KB && index < units.length - 1) {
size /= ONE_KB;
index++;
}
return `${size.toFixed(index === 0 ? 0 : 2)} ${units[index]}`;
}
function cpuSpeedFormat(speed) {