web/ProcessingQueueItem: format file size to be readable
This commit is contained in:
14
web/src/lib/util.ts
Normal file
14
web/src/lib/util.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const formatFileSize = (size: number | undefined) => {
|
||||
size ||= 0;
|
||||
|
||||
// gigabyte, megabyte, kilobyte, byte
|
||||
const units = ['G', 'M', 'K', ''];
|
||||
while (size >= 1024 && units.length > 1) {
|
||||
size /= 1024;
|
||||
units.pop();
|
||||
}
|
||||
|
||||
const roundedSize = parseFloat(size.toFixed(2));
|
||||
const unit = units[units.length - 1] + "B";
|
||||
return `${roundedSize} ${unit}`;
|
||||
}
|
||||
Reference in New Issue
Block a user