mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Implement utils tests
This commit is contained in:
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user