15 lines
355 B
JavaScript
15 lines
355 B
JavaScript
|
const UNITS = [
|
||
|
{ name: 'GB', size: Math.pow(2, 30) },
|
||
|
{ name: 'MB', size: Math.pow(2, 20) },
|
||
|
{ name: 'KB', size: Math.pow(2, 10) },
|
||
|
];
|
||
|
|
||
|
function displaySize(bytes) {
|
||
|
for (const unit of UNITS) {
|
||
|
if (bytes >= unit.size) {
|
||
|
return `${(bytes / unit.size).toFixed(1)}${unit.name}`;
|
||
|
}
|
||
|
}
|
||
|
return `${bytes}B`;
|
||
|
}
|