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 🙏

© 2024 – Pkg Stats / Ryan Hefner

intl-plural-rules-polyfill

v1.0.3

Published

A simple Intl.PluralRules polyfill

Downloads

204

Readme

intl-plural-rules-polyfill

npm version npm downloads npm size coverage

A simple Intl.PluralRules polyfill. Can be imported as "cardinals"-only. Created as part of relative-time-format.

Install

npm install intl-plural-rules-polyfill --save

If you're not using a bundler then use a standalone version from a CDN.

Use

import PluralRules from "intl-plural-rules-polyfill"

const pluralRules = new PluralRules("en", {
  style: "cardinal" // "cardinal" is the default. Other options: "ordinal".
})

pluralRules.select(0) // "other"
pluralRules.select(1) // "one"

The possible return values are:

  • zero
  • one
  • two
  • few
  • many
  • other

For more info on which is which read the official Unicode CLDR documentation. Unicode CLDR (Common Locale Data Repository) is an industry standard and is basically a collection of formatting rules for all locales (date, time, currency, measurement units, numbers, etc).

Cardinals

If the app only uses "cardinals" type and doesn't use "ordinals" then the polyfill can be imported as "cardinals"-only.

import PluralRules from "intl-plural-rules-polyfill/cardinal"

Under the hood

To determine whether a number is one, few, or something else, this polyfill uses Unicode CLDR rules for formatting plurals compiled into javascript by make-plural. These rules are number quantifying functions (one for each locale) which can tell if a number should be treated as zero, one, two, few, many or other. Knowing how these pluralization rules work is not required but anyway here are some links for curious advanced readers: rules explanation, list of rules for all locales, list of rules for all locales in JSON format (part of cldr-core/supplemental package), converting those rules to javascript functions.

Plural rule functions (./source/ordinals.js and ./source/cardinals.js) are generated by running:

npm install make-plural@latest --save-dev
npm run generate

CDN

One can use any npm CDN service, e.g. unpkg.com or jsdelivr.net

<script src="https://unpkg.com/intl-plural-rules-polyfill@[version]/bundle/polyfill.js"></script>

<script>
  new PluralRules('en').select(0)
</script>

where [version] is an npm package version range (for example, 0.2.x or ^0.2.0).

License

MIT