2022-04-27 23:52:45 -04:00
|
|
|
const UNITS = [
|
2022-05-03 16:28:43 -04:00
|
|
|
{ name: 'GB', size: Math.pow(10, 9) },
|
|
|
|
{ name: 'MB', size: Math.pow(10, 6) },
|
|
|
|
{ name: 'KB', size: Math.pow(10, 3) },
|
2022-04-27 23:52:45 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
function displaySize(bytes) {
|
|
|
|
for (const unit of UNITS) {
|
|
|
|
if (bytes >= unit.size) {
|
|
|
|
return `${(bytes / unit.size).toFixed(1)}${unit.name}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `${bytes}B`;
|
|
|
|
}
|