Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Oct 17, 2024
1 parent 99cadf7 commit 514c490
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions web/assets/js/util/common.js
Original file line number Diff line number Diff line change
@@ -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";
}

let index = 0;

while (size >= ONE_KB && index < units.length - 1) {
size /= ONE_KB;
index++;
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";
}

return `${size.toFixed(index === 0 ? 0 : 2)} ${units[index]}`;
}

function cpuSpeedFormat(speed) {
Expand Down

0 comments on commit 514c490

Please sign in to comment.