i did stuff

This commit is contained in:
grngxd 2025-07-31 14:45:38 +01:00
parent 67d53818f3
commit 3fb2883091
8 changed files with 105 additions and 10 deletions

13
lib.ts Normal file
View file

@ -0,0 +1,13 @@
export const formatSize = (bytes: number): string => {
const units = ["B", "KB", "MB", "GB", "TB"];
let size = bytes;
let unit = units[0];
for (let i = 0; i < units.length; i++) {
if (size < 1024 || i === units.length - 1) {
unit = units[i];
break;
}
size /= 1024;
}
return `${size % 1 === 0 ? size : size.toFixed(2)} ${unit}`;
}