e0615fa867
📁 Changed TDrive root folder
12 lines
364 B
TypeScript
12 lines
364 B
TypeScript
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
if (!+bytes) return '0 KB';
|
|
|
|
const k = 1024;
|
|
const dm = decimals < 0 ? 0 : decimals;
|
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
};
|