Implement utils tests

This commit is contained in:
2025-05-26 20:35:02 +02:00
parent e5569fc4a5
commit 49cac03db8
5 changed files with 526 additions and 0 deletions

View File

@@ -16,6 +16,9 @@ const UNITS: readonly ByteUnit[] = ['B', 'KB', 'MB', 'GB'] as const;
export const formatBytes = (bytes: number): string => {
let size: number = bytes;
let unitIndex: number = 0;
if (size < 0) {
throw new Error('Byte size cannot be negative');
}
while (size >= 1024 && unitIndex < UNITS.length - 1) {
size /= 1024;
unitIndex++;