uploading files and a lot more
This commit is contained in:
12
ui/utils/formatBytes.ts
Normal file
12
ui/utils/formatBytes.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function formatBytes(bytes: number, decimalPlaces = 2) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const k = 1024;
|
||||
const dm = decimalPlaces;
|
||||
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user