mirror of
https://bitbucket.org/Mattrixwv/mattrixwvreactcomponents.git
synced 2025-12-06 13:43:59 -05:00
10 lines
354 B
TypeScript
10 lines
354 B
TypeScript
export function humanReadableBytes(bytes: number, decimals: number = 2): string{
|
|
if(bytes === 0){
|
|
return "0 Bytes";
|
|
}
|
|
|
|
const sizes = [ "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ];
|
|
const power = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
return `${parseFloat((bytes / Math.pow(1024, power)).toFixed(decimals))} ${sizes[power]}`;
|
|
}
|