npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@se-oss/compact-number

v1.0.0

Published

A lightweight library for compact number formatting and parsing.

Readme

@se-oss/compact-number

CI NPM Version MIT License Install Size

@se-oss/compact-number is a lightweight, fast, and highly customizable library for compact number formatting and parsing, offering robust internationalization support.


📦 Installation

npm install @se-oss/compact-number

pnpm

pnpm install @se-oss/compact-number

yarn

yarn add @se-oss/compact-number

📖 Usage

compactNumber

Format a number into a compact, human-readable string.

import { compactNumber } from '@se-oss/compact-number';

console.log('Formatting 1234:', compactNumber(1234));
// => 1.2K

console.log('Formatting 1500000:', compactNumber(1500000));
// => 1.5M

console.log(
  'Formatting -1234 with precision 2:',
  compactNumber(-1234, { maximumFractionDigits: 2 })
);
// => -1.23K

uncompactNumber

Parse a compacted string back into a number.

import { uncompactNumber } from '@se-oss/compact-number';

console.log(uncompactNumber('1.2K'));
// => 1200

console.log(uncompactNumber('1.5M'));
// => 1500000

console.log(uncompactNumber('-1.23K'));
// => -1230

💡 Advanced Usage

You can dynamically load locales from the cldr-numbers-full package instead of bundling them. This is useful for applications that support many languages.

First, install the CLDR data package:

pnpm add cldr-numbers-full

Loading a Single Locale

To keep your bundle size small, you can import and register individual locales as needed. This works in any environment.

import { compactNumber, store } from '@se-oss/compact-number';
// Import any CLDR locale data directly
import ca from 'cldr-numbers-full/main/ca/numbers.json';

// Register the Catalan locale from the raw CLDR data
store.registerFromCLDR(ca);

// You can now format numbers using the 'ca' locale
console.log(compactNumber(12345, { locale: 'ca' }));
// => 12,3 mil

Loading All Locales (Node.js)

In Node.js environments, you can register all available CLDR locales at once using registerFullCLDR. This is useful for servers that need to handle many different locales.

import { compactNumber, store } from '@se-oss/compact-number';

// Register all CLDR locales
await store.registerFullCLDR();

// Now you can format numbers in any of the registered locales
console.log(compactNumber(12345, { locale: 'ja' })); // Japanese
// => 1.2万

console.log(compactNumber(54321, { locale: 'fr' })); // French
// => 54,3 k

Note: This function only works in Node.js. It will throw an error in the browser to prevent bundling the entire cldr-numbers-full package.

🌍 Using Locales

By default, only the en locale is registered. To use other locales, you must import and register them. This ensures that unused locales are not included in your final bundle.

import { compactNumber, es, store } from '@se-oss/compact-number';

// Register the Spanish (es) locale
store.register(es);

console.log(compactNumber(1234, { locale: 'es' }));
// => 1.2 mil

📚 Documentation

For all configuration options, please see the API docs.

🚀 Performance

@se-oss/compact-number is designed for speed. Our benchmarks show it's significantly faster than Intl.NumberFormat for compact number formatting.

| Library | Operations/second (hz) | | :------------------------- | :--------------------- | | @se-oss/compact-number | 274,863.69 | | Intl.NumberFormat | 22,298.90 | | Performance Difference | ~12.33x faster |

Benchmark script: src/index.bench.ts

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! 🙏

License

MIT © Shahrad Elahi and contributors.