anyplural — plurals: One item or five, first or twenty-first — the right wording every time, even where there are six forms.
▸about anyplural
Picks the right plural form for a count and formats the two together — "1 item", "5 items", "5 лет", "3rd".
- wraps
- Intl.PluralRules, with Intl.NumberFormat for the count
- install
- npm install anyplural
- runtime
- Node 18+, every modern browser, Deno, Bun, edge runtimes.
- docs
- anyfamily.site/docs/anyplural
- playground
- run the family on StackBlitz
why
n === 1 ? "item" : "items" is wrong in most languages — Russian has three forms, Arabic six, ordinals differ again. anyplural asks the runtime for the category, falls back along CLDR's own chain, and formats the number in the same locale. ~0.7 kB.
usage
anyplural(5, { one: "item", other: "items" }) // "5 items"
anyplural(5, { one: "год", few: "года", many: "лет" }, { locale: "ru" }) // "5 лет"
anyplural(0, { zero: "no mail", one: "letter", other: "letters" }) // "no mail"
anyplural(3, { one: "st", two: "nd", few: "rd", other: "th" }, { type: "ordinal" }) // "3rd"
anyplural(1500, { other: "items" }, { locale: "en" }) // "1,500 items"not for
Full message formatting with placeholders (ICU MessageFormat) — this is one number and one word.