(sizeInBytes: number)
| 7 | * @example formatFileSize(1536) → "1.5KB" |
| 8 | */ |
| 9 | export function formatFileSize(sizeInBytes: number): string { |
| 10 | const kb = sizeInBytes / 1024 |
| 11 | if (kb < 1) { |
| 12 | return `${sizeInBytes} bytes` |
| 13 | } |
| 14 | if (kb < 1024) { |
| 15 | return `${kb.toFixed(1).replace(/\.0$/, '')}KB` |
| 16 | } |
| 17 | const mb = kb / 1024 |
| 18 | if (mb < 1024) { |
| 19 | return `${mb.toFixed(1).replace(/\.0$/, '')}MB` |
| 20 | } |
| 21 | const gb = mb / 1024 |
| 22 | return `${gb.toFixed(1).replace(/\.0$/, '')}GB` |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Formats milliseconds as seconds with 1 decimal place (e.g. `1234` → `"1.2s"`). |
no outgoing calls
no test coverage detected