Registry / serialization / make-plural

make-plural

JSON →
library8.1.0jsnpmunverified

make-plural provides JavaScript functions that implement the Unicode CLDR pluralization rules for approximately 220 languages. It handles both cardinal (e.g., 'one book') and ordinal (e.g., '1st book') pluralization categories. As of version 8.1.0, the library is actively maintained with regular updates to support the latest CLDR versions, ensuring accuracy for new locales and rule changes. Key differentiators include its pre-compiled, runtime-dependency-free functions, optimized for tree-shaking with ES modules, which can result in very small bundle sizes when only specific locales are imported. It is used internally by the `intl-pluralrules` polyfill and offers companion packages `make-plural-cli` and `make-plural-compiler` for custom build generation. The project maintains a steady release cadence, often tied to new CLDR versions or feature enhancements like compact notation support, ensuring current and accurate pluralization logic.

npm install make-plural
INSTALL
IMPORT
SIG · MAKE-PLURAL
M
make-plural
serializationjavascriptv8.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

en
import { en } from 'make-plural'
const { en } = require('make-plural')
Since v8.0.0, make-plural is ESM-only. The main export (`make-plural`) provides a combined function for cardinal and ordinal plurals.
en
import { en } from 'make-plural/cardinals'
import * as Cardinals from 'make-plural/cardinals'
Use named imports from sub-paths like `make-plural/cardinals` for optimal tree-shaking, otherwise bundlers might include all locales.
LocalePluralFunc
import type { LocalePluralFunc } from 'make-plural'
TypeScript type for pluralization functions, useful for explicit typing in consumers.
pt_PT
import * as Categories from 'make-plural/pluralCategories'; Categories.pt_PT
import * as Categories from 'make-plural/pluralCategories'; Categories['pt-PT']
The locale code `pt-PT` is transformed to `pt_PT` (with an underscore) for JavaScript identifier compatibility when accessed as an object key from the exports.

Demonstrates cardinal and ordinal pluralization for English and French, including specific locale imports for tree-shaking and accessing plural categories for different languages, highlighting locale key transformations.

import { en, fr } from 'make-plural'; import { en as ordinalEn } from 'make-plural/ordinals'; import * as Categories from 'make-plural/pluralCategories'; // Cardinal pluralization console.log('English cardinal for 1:', en(1)); // 'one' console.log('English cardinal for 2:', en(2)); // 'other' console.log('French cardinal for 1:', fr(1)); // 'one' console.log('French cardinal for 2:', fr(2)); // 'one' console.log('French cardinal for 3:', fr(3)); // 'other' // Ordinal pluralization using the combined function (second argument `true`) console.log('English ordinal for 1:', en(1, true)); // 'one' console.log('English ordinal for 2:', en(2, true)); // 'two' console.log('English ordinal for 3:', en(3, true)); // 'few' // Ordinal pluralization using the dedicated ordinals module console.log('English ordinal (dedicated module) for 3:', ordinalEn(3)); // 'few' // Accessing plural categories for a locale const enCategories = Categories.en.cardinal; console.log('English cardinal categories:', enCategories); // ['one', 'other'] const ptPtCategories = Categories.pt_PT.cardinal; // Note: pt-PT becomes pt_PT console.log('Portuguese (Portugal) cardinal categories:', ptPtCategories); // ['one', 'other'] // Example with string representation of a number console.log('English cardinal for "1.0":', en('1.0')); // 'other'
Debug
Known issues
breakingThe `make-plural` package dropped CommonJS exports, becoming an ES module-only package. Projects using `require()` will fail.
fix
Migrate all imports from `require('make-plural')` to `import { ... } from 'make-plural'` syntax and ensure your build environment supports ES modules.
affects: >=8.0.0
breakingThe `make-plural` package license changed to the OSI-approved Unicode Data Files and Software License. Additionally, generated functions now use ES6 `const` and `=>` syntax.
fix
Review the new license for compliance. For environments not supporting ES6 (e.g., IE 11), ensure your build process includes transpilation (e.g., Babel) for ES6+ syntax.
affects: >=7.0.0
gotchaFor optimal bundle size and effective tree-shaking, always use named imports when importing specific locales (e.g., `import { en } from 'make-plural/cardinals'`) instead of wildcard imports (e.g., `import * as Cardinals from 'make-plural/cardinals'`) from sub-paths.
fix
Refactor your imports to target specific locale functions using named imports to allow bundlers to remove unused code.
affects: >=1.0.0
gotchaThe locale code `pt-PT` (Portuguese as spoken in Portugal) is transformed to `pt_PT` for JavaScript identifier compatibility when accessed as an object key (e.g., from `make-plural/pluralCategories`).
fix
When accessing the `pt-PT` locale as a property from exported objects, use the underscore-separated `pt_PT` identifier.
affects: >=1.0.0
gotchaThe `make-plural/ordinals` module provides ordinal pluralization functions but covers a slightly smaller subset of locales compared to the main `make-plural` or `make-plural/cardinals` modules due to limitations in CLDR data availability for ordinal rules.
fix
Be aware that not all locales supported for cardinal plurals will have corresponding ordinal pluralization rules via `make-plural/ordinals`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: make_plural__WEBPACK_IMPORTED_MODULE_0__.en is not a function
Attempting to use `make-plural` with CommonJS `require()` syntax or an outdated bundler configuration after v8.0.0.
fix
Update your code to use ES module `import { en } from 'make-plural'` syntax and ensure your build system supports ES modules.
SyntaxError: Unexpected token 'const' or SyntaxError: Unexpected token '=>'
Running code generated by `make-plural@7.0.0` or later in an environment that does not support ES6 syntax without proper transpilation.
fix
Configure your build process (e.g., Babel) to transpile ES6+ syntax to a compatible target for your deployment environment.
TypeError: Cannot read properties of undefined (reading 'cardinal')
Attempting to access the `pt-PT` locale directly using the hyphenated string as a JavaScript object key from exports like `pluralCategories`.
fix
Use the transformed identifier `pt_PT` (with an underscore) when accessing the Portuguese (Portugal) locale, e.g., `Categories.pt_PT`.
My bundle size is unexpectedly large despite only using a few locales.
Using wildcard imports (e.g., `import * as Plurals from 'make-plural/plurals'`) instead of named imports, which prevents effective tree-shaking by bundlers.
fix
Refactor your imports to use named imports for specific locales, e.g., `import { en, fr } from 'make-plural/cardinals'`.
Upgrade
Version history
8.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Resources
make-plural — npm install make-plural · libregistry