gamebrary/src/utils.js

11 lines
294 B
JavaScript
Raw Normal View History

2021-02-18 00:51:49 +00:00
// eslint-disable-next-line
export const bytesToSize = (bytes) => {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return '0 Byte';
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 0);
return `${Math.round(bytes / (1024 ** i), 2)} ${sizes[i]}`;
};