mirror of
https://github.com/romancm/gamebrary
synced 2024-12-19 15:53:06 +00:00
11 lines
294 B
JavaScript
11 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]}`;
|
||
|
};
|