format-si-unit
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

format-si-unit

A lightweight utility to format numbers with SI unit prefixes (k, M, G, etc.).

Installation

npm install format-si-unit
# or
bun add format-si-unit

Usage

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()) // ""

Features

  • 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

Development

To install dependencies:

bun install

To run tests:

bun test

To build:

bun run build

License

MIT

/format-si-unit/

    Package Sidebar

    Install

    npm i format-si-unit

    Weekly Downloads

    6,720

    Version

    0.0.3

    License

    none

    Unpacked Size

    5.36 kB

    Total Files

    6

    Last publish

    Collaborators

    • seveibar