transbeam/static/js/util.js

15 lines
355 B
JavaScript
Raw Normal View History

2022-04-27 23:52:45 -04:00
const UNITS = [
{ 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`;
}