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

intl-number-formatter

v1.0.1

Published

A flexible number formatting library using Intl.NumberFormat with fallbacks

Readme

IntlFormatter

A flexible and robust number formatting library that provides a consistent interface for formatting numbers across different locales and formats. It gracefully handles browser compatibility issues and provides fallbacks for unsupported features.

Installation

npm install intl-number-formatter

Basic Usage

import { IntlFormatter } from 'intl-formatter';
// Create a formatter instance with default options
const formatter = new IntlFormatter();
// Basic number formatting
formatter.format(1234.567); // "1,234.57"
// Currency formatting
formatter.formatCurrency(1234.567, { currency: 'USD' }); // "$1,234.57"
// Percentage formatting
formatter.formatPercent(0.1234); // "12.3%"

Features

  • Locale and Format Fallbacks: Automatically falls back to a more basic format if the locale and format are not supported.
  • Flexible Options: Provides a wide range of options to customize the formatting style and precision.
  • Browser Compatibility: Uses Intl.NumberFormat under the hood, ensuring compatibility with modern browsers.

Available Formats

  • Currency: Formats a number as a currency string.
  • Decimal: Formats a number as a decimal string.
  • Percent: Formats a number as a percentage string.
  • Scientific: Formats a number in scientific notation.
  • Unit: Formats a number as a unit string.
  • Custom: Formats a number as a custom string.

Available Units

  • Mass: Formats a number as a mass unit (e.g. grams, kilograms).
  • Time: Formats a number as a time unit (e.g. seconds, minutes, hours).
  • Length: Formats a number as a length unit (e.g. meters, kilometers).
  • Volume: Formats a number as a volume unit (e.g. liters, milliliters).
  • Speed: Formats a number as a speed unit (e.g. meters per second, kilometers per hour).
  • Temperature: Formats a number as a temperature unit (e.g. Celsius, Fahrenheit).

Format currency

const formatter = new IntlFormatter();
formatter.formatCurrency(1234.567, { currency: 'USD' }); // "$1,234.57"

Format percent

formatter.formatPercent(0.1234); // "12.3%"

Format unit

formatter.formatUnit(1234.567, { unit: 'meter' }); // "1,234.57 m"

Format custom

formatter.formatCustom(1234.567, (formattedValue) => `${formattedValue} meters`); // "1,234.57 meters"

Format range

formatter.formatRange(1234.567, 1234.567); // "1,234.57 - 1,234.57"

Format compact

formatter.formatCompact(1234.567); // "1.23K"

Format scientific

formatter.formatScientific(1234.567); // "1.234567E3"

Unit Long and Narrow Form

formatter.getUnitLongForm('meter'); // "meter"
formatter.getUnitNarrowForm('meter'); // "m"

Available Options

| Option | Type | Default | Description | Available Options | |--------|------|---------|-------------|-------------------| | locale | string | navigator.language or 'en-US' | The locale to use for formatting | Any valid locale string (e.g. 'en-US', 'fr-FR', 'de-DE') | | style | string | 'decimal' | The formatting style | 'decimal', 'currency', 'percent', 'unit' | | notation | string | 'standard' | The notation to use | 'standard', 'scientific', 'engineering', 'compact' | | minimumFractionDigits | number | 0 | Minimum number of fraction digits to use | 0-20 | | maximumFractionDigits | number | 2 | Maximum number of fraction digits to use | 0-20 | | minimumSignificantDigits | number | undefined | Minimum number of significant digits | 1-21 | | maximumSignificantDigits | number | undefined | Maximum number of significant digits | 1-21 | | useGrouping | boolean | string | true | Whether to use grouping separators | true, false, 'always', 'auto', 'min2' | | roundingMode | string | 'halfEven' | The rounding mode to use | 'ceil', 'floor', 'expand', 'trunc', 'halfCeil', 'halfFloor', 'halfExpand', 'halfTrunc', 'halfEven' | | currency | string | undefined | The currency code | Any valid ISO 4217 currency code (e.g. 'USD', 'EUR', 'JPY') | | currencyDisplay | string | 'symbol' | How to display the currency | 'symbol', 'narrowSymbol', 'code', 'name' | | currencySign | string | undefined | The currency sign to use | 'standard', 'accounting' | | unit | string | undefined | The unit to use for unit formatting | Any valid unit identifier (e.g. 'meter', 'liter', 'celsius') | | unitDisplay | string | 'short' | How to display the unit | 'short', 'long', 'narrow' | | signDisplay | string | 'auto' | When to display the sign | 'auto', 'never', 'always', 'exceptZero' | | compactDisplay | string | 'short' | Compact notation display style | 'short', 'long' |

License

This project is licensed under the MIT License. See the LICENSE file for details.