gamebrary/src/utils.js
2021-02-17 17:51:49 -07:00

10 lines
294 B
JavaScript

// 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]}`;
};