@sinchsmb/ui-kit
Version:
UI kit for SinchSMB frontend
12 lines (9 loc) • 397 B
text/typescript
export function getRadix(bytes: number) {
return bytes === 0 ? 0 : Math.floor(Math.log(bytes) / Math.log(1024));
}
export function getUnit(digit: number) {
return ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][digit];
}
export function humanizeFileSize(bytes: number, radix = 0, decimals = 2) {
return parseFloat((bytes / Math.pow(1024, radix)).toFixed(decimals)).toString();
}