A lightweight utility to format numbers with SI unit prefixes (k, M, G, etc.).
npm install format-si-unit
# or
bun add format-si-unit
import { formatSiUnit } from "format-si-unit"
console.log(formatSiUnit(1500)) // "1.5k"
console.log(formatSiUnit(1_000_000)) // "1M"
console.log(formatSiUnit(0.001)) // "1m"
console.log(formatSiUnit(0)) // "0"
console.log(formatSiUnit()) // ""
- Supports SI prefixes from pico (p) to tera (T)
- Handles null and undefined inputs
- Returns numbers with up to 3 significant digits
- Automatically selects the most appropriate SI prefix
- TypeScript support included
To install dependencies:
bun install
To run tests:
bun test
To build:
bun run build
MIT