Initial commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export const formatFileSize = (value) => {
|
||||
const bytes = Number(value);
|
||||
if (!Number.isFinite(bytes) || bytes <= 0) {
|
||||
return '0 B';
|
||||
}
|
||||
|
||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
|
||||
let index = 0;
|
||||
let amount = bytes;
|
||||
|
||||
while (amount >= 1024 && index < units.length - 1) {
|
||||
amount /= 1024;
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return `${amount.toFixed(2)} ${units[index]}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user