(n: number)
| 14 | const UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; |
| 15 | |
| 16 | export function formatBytes(n: number): string { |
| 17 | let v = n; |
| 18 | let i = 0; |
| 19 | while (v >= 1024 && i < UNITS.length - 1) { |
| 20 | v /= 1024; |
| 21 | i++; |
| 22 | } |
| 23 | if (i === 0) return `${Math.round(v)} B`; |
| 24 | const s = v.toFixed(1).replace(/\.0$/, ''); |
| 25 | return `${s} ${UNITS[i]}`; |
| 26 | } |
| 27 | |
| 28 | function num(v: unknown): v is number { |
| 29 | return typeof v === 'number' && Number.isFinite(v); |
no outgoing calls
no test coverage detected