(n, units = {})
| 3 | // explicitly so this remains pure and testable. Callers supply |
| 4 | // t('dash.acct.unitK') / t('dash.acct.unitM'). |
| 5 | export function formatCompact(n, units = {}) { |
| 6 | const { unitK = 'k', unitM = 'M' } = units |
| 7 | const num = Number(n) || 0 |
| 8 | if (num < 1000) return String(num) |
| 9 | if (num < 1_000_000) { |
| 10 | const k = num / 1000 |
| 11 | const formatted = k >= 100 ? Math.round(k) : (Math.round(k * 10) / 10) |
| 12 | return `${formatted}${unitK}` |
| 13 | } |
| 14 | const m = num / 1_000_000 |
| 15 | return `${Math.round(m * 10) / 10}${unitM}` |
| 16 | } |
nothing calls this directly
no outgoing calls
no test coverage detected