{"id":15648841,"url":"https://github.com/eemeli/intl-pluralrules","last_synced_at":"2025-04-10T03:53:38.756Z","repository":{"id":1614314,"uuid":"43270787","full_name":"eemeli/intl-pluralrules","owner":"eemeli","description":"Polyfill for Intl.PluralRules","archived":false,"fork":false,"pushed_at":"2023-07-06T15:02:27.000Z","size":647,"stargazers_count":42,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T03:53:29.074Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/intl-pluralrules","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eemeli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"eemeli"}},"created_at":"2015-09-28T00:02:33.000Z","updated_at":"2025-02-20T00:06:42.000Z","dependencies_parsed_at":"2024-06-18T13:58:07.638Z","dependency_job_id":"b689c7cd-bb5c-4980-99e3-ef1e6178c6c9","html_url":"https://github.com/eemeli/intl-pluralrules","commit_stats":{"total_commits":154,"total_committers":6,"mean_commits":"25.666666666666668","dds":"0.038961038961038974","last_synced_commit":"80ea5c7deb3f66c6470d5c33d50e6c91d8426aed"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fintl-pluralrules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fintl-pluralrules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fintl-pluralrules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fintl-pluralrules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eemeli","download_url":"https://codeload.github.com/eemeli/intl-pluralrules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154998,"owners_count":21056542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:26:38.199Z","updated_at":"2025-04-10T03:53:38.737Z","avatar_url":"https://github.com/eemeli.png","language":"JavaScript","funding_links":["https://github.com/sponsors/eemeli"],"categories":[],"sub_categories":[],"readme":"# intl-pluralrules\n\nA spec-compliant implementation \u0026 polyfill for [Intl.PluralRules],\nincluding the `selectRange(start, end)` method introduced in [Intl.NumberFormat v3].\nAlso useful if you need proper support for [`minimumFractionDigits`],\nwhich are only supported in Chrome 77 \u0026 later.\n\nFor a polyfill without `selectRange()` and with IE 11 support, please use `intl-pluralrules@1`.\n\n[intl.pluralrules]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules\n[intl.numberformat v3]: https://github.com/tc39/proposal-intl-numberformat-v3/\n[`minimumfractiondigits`]: https://bugs.chromium.org/p/v8/issues/detail?id=8866\n\n## Installation\n\n```\nnpm install intl-pluralrules\n```\n\n## Polyfill\n\nTo use as a polyfill, just import it to ensure that `Intl.PluralRules` is\navailable in your environment:\n\n```js\nimport 'intl-pluralrules'\n```\n\nIf `Intl.PluralRules` already exists,\nincludes a `selectRange()` method,\nand supports [multiple locales](https://nodejs.org/api/intl.html),\nthe polyfill will not be loaded.\n\n## Ponyfill\n\nA complete implementation of PluralRules is available as\n`intl-pluralrules/plural-rules`, if you'd prefer using it without modifying your\n`Intl` object, or if you wish to use it rather than your environment's own:\n\n```js\nimport PluralRules from 'intl-pluralrules/plural-rules'\n\nnew PluralRules('en').select(1) // 'one'\nnew PluralRules('en', { minimumSignificantDigits: 3 }).select(1) // 'other'\nnew PluralRules('en').selectRange(0, 1) // 'other'\nnew PluralRules('fr').selectRange(0, 1) // 'one'\n```\n\n## Factory\n\nIn order to support all available locales, their data needs to be included in\nthe package. This means that when minified and gzipped, the above-documented\nusage adds about 7kB to your application's production size. If this is a\nconcern, you can use `intl-pluralrules/factory` and [make-plural] to build a\nPluralRules class with locale support limited to only what you actually use.\n\n[make-plural]: https://www.npmjs.com/package/make-plural\n\nThanks to tree-shaking, this example that only supports English and French\nminifies \u0026 gzips to 1472 bytes. Do note that this size difference is only\napparent with minified production builds.\n\n```js\nimport getPluralRules from 'intl-pluralrules/factory'\nimport { en, fr } from 'make-plural/plurals'\nimport { en as enCat, fr as frCat } from 'make-plural/pluralCategories'\nimport { en as enRange, fr as frRange } from 'make-plural/ranges'\n\nconst sel = { en, fr }\nconst getSelector = lc =\u003e sel[lc]\n\nconst cat = { en: enCat, fr: frCat }\nconst getCategories = (lc, ord) =\u003e cat[lc][ord ? 'ordinal' : 'cardinal']\n\nconst range = { en: enRange, fr: frRange }\nconst getRangeSelector = lc =\u003e range[lc]\n\nconst PluralRules = getPluralRules(\n  Intl.NumberFormat, // Not available in IE 10\n  getSelector,\n  getCategories,\n  getRangeSelector\n)\nexport default PluralRules\n```\n\nAll arguments of\n`getPluralRules(NumberFormat, getSelector, getCategories, getRangeSelector)`\nare required.\n\n- `NumberFormat` should be `Intl.NumberFormat`, or an implementation which\n  supports at least the `\"en\"` locale and all of the min/max digit count\n  options.\n- `getSelector(lc)` should return a `function(n, ord)` returning the plural\n  category of `n`, using cardinal plural rules (by default), or ordinal rules if\n  `ord` is true. `n` may be a number, or the formatted string representation of\n  a number. This may be called with any user-provided string `lc`, and should\n  return `undefined` for invalid or unsupported locales.\n- `getCategories(lc, ord)` should return the set of available plural categories\n  for the locale, either for cardinals (by default), or ordinals if `ord` is\n  true. This function will be called only with values for which `getSelector`\n  returns a function.\n- `getRangeSelector(lc)` should return a `function(start, end)` returning the\n  plural category of the range. `start` and `end` are the plural categories of\n  the corresponding values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fintl-pluralrules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feemeli%2Fintl-pluralrules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fintl-pluralrules/lists"}