https://github.com/limpix31/madnum
Transform large numbers to length-friendly string
https://github.com/limpix31/madnum
Last synced: 3 months ago
JSON representation
Transform large numbers to length-friendly string
- Host: GitHub
- URL: https://github.com/limpix31/madnum
- Owner: LIMPIX31
- Created: 2022-05-08T17:29:10.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-02T15:39:00.000Z (almost 3 years ago)
- Last Synced: 2025-08-16T08:43:31.912Z (12 months ago)
- Language: TypeScript
- Size: 2.32 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Madnum
Transform large numbers to length-friendly string
The transform algorithm uses the **`"aa" notation`**
```ts
import { format } from 'madnum'
// or default import
import madnum from 'madnum'
// Default usage
format(1000) // 1 K
format(1e6) // 1 M
format(1.5e6) // 1.5 M
// The "aa" notation example
format(1e15) // 1 AA
// With options
format(123456789, {
intl: (num) => num.toFixed(2),
format: (base, unit) => `${base}${unit.toLowerCase()}`
}) // 123.46m
// Intl.NumberFormat
const formatter = new Intl.NumberFormat('en', {
minimumFractionDigits: 0,
maximumFractionDigits: 1,
})
format(-123114511661, {
intl: (num) => formatter.format(num),
format: (base, unit) => `${base}${unit.toLowerCase()}`
}) // -123.1b
// Can handle infinity-like numbers
format(1e1000) // ∞
format(Infinity) // ∞
format(-Infinity) // -∞
```