Gathering detailed insights and metrics for intl-pluralrules
Gathering detailed insights and metrics for intl-pluralrules
Gathering detailed insights and metrics for intl-pluralrules
Gathering detailed insights and metrics for intl-pluralrules
npm install intl-pluralrules
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
41 Stars
166 Commits
7 Forks
5 Watching
2 Branches
4 Contributors
Updated on 16 Aug 2024
JavaScript (96.39%)
HTML (3.61%)
Cumulative downloads
Total Downloads
Last day
22%
66,585
Compared to previous day
Last week
9.6%
317,573
Compared to previous week
Last month
14.6%
1,313,833
Compared to previous month
Last year
2%
13,742,374
Compared to previous year
A spec-compliant implementation & polyfill for Intl.PluralRules,
including the selectRange(start, end)
method introduced in Intl.NumberFormat v3.
Also useful if you need proper support for minimumFractionDigits
,
which are only supported in Chrome 77 & later.
For a polyfill without selectRange()
and with IE 11 support, please use intl-pluralrules@1
.
npm install intl-pluralrules
To use as a polyfill, just import it to ensure that Intl.PluralRules
is
available in your environment:
1import 'intl-pluralrules'
If Intl.PluralRules
already exists,
includes a selectRange()
method,
and supports multiple locales,
the polyfill will not be loaded.
A complete implementation of PluralRules is available as
intl-pluralrules/plural-rules
, if you'd prefer using it without modifying your
Intl
object, or if you wish to use it rather than your environment's own:
1import PluralRules from 'intl-pluralrules/plural-rules' 2 3new PluralRules('en').select(1) // 'one' 4new PluralRules('en', { minimumSignificantDigits: 3 }).select(1) // 'other' 5new PluralRules('en').selectRange(0, 1) // 'other' 6new PluralRules('fr').selectRange(0, 1) // 'one'
In order to support all available locales, their data needs to be included in
the package. This means that when minified and gzipped, the above-documented
usage adds about 7kB to your application's production size. If this is a
concern, you can use intl-pluralrules/factory
and make-plural to build a
PluralRules class with locale support limited to only what you actually use.
Thanks to tree-shaking, this example that only supports English and French minifies & gzips to 1472 bytes. Do note that this size difference is only apparent with minified production builds.
1import getPluralRules from 'intl-pluralrules/factory' 2import { en, fr } from 'make-plural/plurals' 3import { en as enCat, fr as frCat } from 'make-plural/pluralCategories' 4import { en as enRange, fr as frRange } from 'make-plural/ranges' 5 6const sel = { en, fr } 7const getSelector = lc => sel[lc] 8 9const cat = { en: enCat, fr: frCat } 10const getCategories = (lc, ord) => cat[lc][ord ? 'ordinal' : 'cardinal'] 11 12const range = { en: enRange, fr: frRange } 13const getRangeSelector = lc => range[lc] 14 15const PluralRules = getPluralRules( 16 Intl.NumberFormat, // Not available in IE 10 17 getSelector, 18 getCategories, 19 getRangeSelector 20) 21export default PluralRules
All arguments of
getPluralRules(NumberFormat, getSelector, getCategories, getRangeSelector)
are required.
NumberFormat
should be Intl.NumberFormat
, or an implementation which
supports at least the "en"
locale and all of the min/max digit count
options.getSelector(lc)
should return a function(n, ord)
returning the plural
category of n
, using cardinal plural rules (by default), or ordinal rules if
ord
is true. n
may be a number, or the formatted string representation of
a number. This may be called with any user-provided string lc
, and should
return undefined
for invalid or unsupported locales.getCategories(lc, ord)
should return the set of available plural categories
for the locale, either for cardinals (by default), or ordinals if ord
is
true. This function will be called only with values for which getSelector
returns a function.getRangeSelector(lc)
should return a function(start, end)
returning the
plural category of the range. start
and end
are the plural categories of
the corresponding values.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/18 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More