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

anyamount

v1.0.0

Published

Tiny smart number formatter — one function, three modes (smart, currency, unit), any Intl locale.

Readme


One function. Smart defaults. Any locale. ~0.7kb gzip. Zero dependencies.

Intl.NumberFormat is powerful. anyamount makes it usable.

Built for dashboards, feeds, pricing pages, file lists, and stats — anywhere a raw number should read like a person wrote it. No locale files. No plugins. No config.

import { anyamount } from "anyamount";

anyamount(1234567);
// "1.2M"  — smart mode (default)

anyamount(42);
// "42"

anyamount(1999, { mode: "currency", currency: "EUR" });
// "€1,999.00"

anyamount(3.2, { mode: "unit", unit: "gigabyte" });
// "3.2 GB"

anyamount(120, { mode: "unit", unit: "kilometer-per-hour", locale: "ru" });
// "120 км/ч"

install

npm install anyamount

usage

anyamount(value);
anyamount(value, options);

value is a number or a bigint — every mode accepts both. ±Infinity formats as the locale's infinity symbol ("∞"); NaN throws.

anyamount(1234567);
anyamount(0.1234);
anyamount(-42.5);
anyamount(123456789012345678901n);   // beyond MAX_SAFE_INTEGER, no precision loss

modes

The mode option picks the rendering strategy. Default is "smart".

smart

Context-aware. Compact notation for big numbers, plain formatting for small ones — the cutoff is |value| >= 10000.

anyamount(1234567, { locale: "en" });   // "1.2M"
anyamount(10000, { locale: "en" });     // "10K"
anyamount(9999, { locale: "en" });      // "9,999"
anyamount(42, { locale: "en" });        // "42"
anyamount(0.1234, { locale: "en" });    // "0.12"

anyamount(1234567, { locale: "en", style: "long" });
// "1.2 million"

anyamount(1234567, { locale: "en", digits: 2 });
// "1.23M"

Fraction digits default to 2 for plain numbers and 1 for compact ones.

Reads: locale, style, digits.

currency

Money via the Intl.NumberFormat currency style. currency is required — any ISO 4217 code.

anyamount(1999, { mode: "currency", currency: "EUR", locale: "en" });
// "€1,999.00"

anyamount(1999, { mode: "currency", currency: "RSD", locale: "sr" });
// "1.999,00 RSD"

anyamount(1999, { mode: "currency", currency: "JPY", locale: "ja" });
// "¥1,999"  — JPY has no minor unit, Intl knows

anyamount(1999.99, { mode: "currency", currency: "EUR", locale: "en", digits: 0 });
// "€2,000"

Fraction digits default to the currency's own (2 for EUR, 0 for JPY).

Reads: locale, currency, digits.

unit

Measurements via the Intl.NumberFormat unit style. unit is required — any sanctioned identifier, including compound "<unit>-per-<unit>" pairs. The unit option is typed as a union, so your editor autocompletes it.

anyamount(3.2, { mode: "unit", unit: "gigabyte", locale: "en" });
// "3.2 GB"

anyamount(120, { mode: "unit", unit: "kilometer-per-hour", locale: "en" });
// "120 km/h"

anyamount(3.2, { mode: "unit", unit: "gigabyte", locale: "en", style: "long" });
// "3.2 gigabytes"

anyamount(5, { mode: "unit", unit: "kilometer", locale: "en", style: "narrow" });
// "5km"

Fraction digits default to 2.

Reads: locale, unit, style, digits.


options

| Option | Type | Default | Used by | | ---------- | --------------------------------- | -------------- | ------------- | | mode | "smart" \| "currency" \| "unit" | "smart" | — | | locale | string \| string[] | runtime locale | all | | currency | string (ISO 4217) | — (required) | currency | | unit | sanctioned unit identifier | — (required) | unit | | style | "long" \| "short" \| "narrow" | "short" | smart, unit | | digits | number (max fraction digits) | smart default | all |

The options type is a discriminated union on mode — TypeScript requires currency in currency mode and unit in unit mode at compile time, and rejects options that don't belong to the mode. From plain JavaScript, the same rules hold at runtime: a missing currency or unit throws a clear TypeError, and stray options are ignored.


parts

anyamountParts() accepts the same arguments as anyamount() and returns the Intl.NumberFormat.formatToParts output unchanged — style the number apart from the currency symbol or unit, or rebuild the string your own way.

import { anyamountParts } from "anyamount";

anyamountParts(1999, { mode: "currency", currency: "EUR", locale: "en" });
// [
//   { type: "currency", value: "€" },
//   { type: "integer", value: "1" },
//   { type: "group", value: "," },
//   { type: "integer", value: "999" },
//   { type: "decimal", value: "." },
//   { type: "fraction", value: "00" },
// ]

// React: shrink the currency symbol
anyamountParts(price, { mode: "currency", currency: "EUR" }).map((p, i) =>
  p.type === "currency" ? <small key={i}>{p.value}</small> : p.value,
);

locales

Pass any valid BCP 47 tag — including regional variants like en-GB, zh-TW, pt-BR. Fallback arrays also work.

anyamount(1234567, { locale: "ru" });   // "1,2 млн"
anyamount(1234567, { locale: "de" });   // "1,2 Mio."
anyamount(1234567, { locale: "ja" });   // "123.5万"
anyamount(1234567, { locale: ["sr-Latn-RS", "en"] });

anyamount(1999, { mode: "currency", currency: "USD", locale: "de" });
// "1.999,00 $"

When omitted, native Intl uses the runtime locale.

Output is pure — no Date.now(), no environment reads — so server and client render identically. SSR-safe by construction.


vs the alternatives

| | anyamount | pretty-bytes | filesize | numeral | | ------------------- | :--------: | :----------: | :------: | :-----: | | gzip | ~0.7kb | ~1kb | ~3kb | ~5kb | | currency | yes | no | no | yes | | units beyond bytes | yes | no | no | no | | localized output | 200+ locales | partial | partial | manual locale files | | dependencies | 0 | 0 | 0 | 0 |


limitations

Honest ones:

  • No byte auto-scaling yet. anyamount(3200000000, { mode: "unit", unit: "byte" }) will not pick GB for you — pass the unit you want. Auto-scaling is planned for a future minor.
  • No percent mode, no ranges, no parsing. Deliberately one function, three modes.
  • Exact output strings come from Intl and may vary between ICU versions — don't snapshot them across environments.
  • Sanctioned units only. Intl supports a fixed list of unit identifiers (and -per- compounds of them) — no arbitrary custom units.

stability

anyamount follows semver. The 1.x API is stable: new options arrive in minors, breaking changes only in majors. Exact formatted strings come from Intl and may vary between ICU versions, so never assert on them across environments.


compatibility

Node.js 18+ · Chrome 77+ · Firefox 78+ · Safari 14.1+ · Edge Runtime · Cloudflare Workers · Deno

CI runs the full suite on Node 20, 22, and 24.


part of the any* family

  • anywhen — tiny smart date formatter. One function, three modes, any locale.
  • anyamount — you are here.