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