(bytes: number)
| 72 | * @returns Formatted string like "1.5 KB" or "2.3 MB" |
| 73 | */ |
| 74 | export function formatBytes(bytes: number): string { |
| 75 | if (bytes < 1024) { |
| 76 | return `${bytes} B`; |
| 77 | } |
| 78 | |
| 79 | if (bytes < 1024 * 1024) { |
| 80 | return `${(bytes / 1024).toFixed(1)} KB`; |
| 81 | } |
| 82 | |
| 83 | return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; |
| 84 | } |