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