Unicode CLDR pluralization rules as JavaScript functions for internationalization applications
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Cardinal-only pluralization functions optimized for when ordinal pluralization is not needed. These functions are more memory-efficient as they don't include ordinal logic.
All 217 language functions support cardinal pluralization only, without the ordinal parameter.
/**
* Determines the cardinal plural category for a number
* @param n - The number to pluralize (number or string)
* @returns The appropriate cardinal plural category
*/
(n: number | string) => PluralCategory;
type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";import { en, fr, ar, pl } from "make-plural/cardinals";All 217 languages are available with the same coverage as the main plurals module, but only for cardinal numbers:
Examples by Complexity:
Simple Two-Category Languages:
en - English: Returns "one" | "other"de - German: Returns "one" | "other"nl - Dutch: Returns "one" | "other"sv - Swedish: Returns "one" | "other"Three-Category Languages:
fr - French: Returns "one" | "many" | "other"pt - Portuguese: Returns "one" | "many" | "other"es - Spanish: Returns "one" | "many" | "other"Four-Category Languages:
pl - Polish: Returns "one" | "few" | "many" | "other"ru - Russian: Returns "one" | "few" | "many" | "other"uk - Ukrainian: Returns "one" | "few" | "many" | "other"Complex Six-Category Languages:
ar - Arabic: Returns "zero" | "one" | "two" | "few" | "many" | "other"cy - Welsh: Returns "zero" | "one" | "two" | "few" | "many" | "other"Single-Category Languages:
zh - Chinese: Returns "other"ja - Japanese: Returns "other"ko - Korean: Returns "other"vi - Vietnamese: Returns "other"Basic Cardinal Usage:
import { en, fr, ar, pl } from "make-plural/cardinals";
// English - simple binary system
en(0); // 'other'
en(1); // 'one'
en(2); // 'other'
en(100); // 'other'
// French - 0 and 1 are singular, 2+ is plural
fr(0); // 'one'
fr(1); // 'one'
fr(2); // 'many'
fr(100); // 'many'
// Arabic - complex 6-category system
ar(0); // 'zero'
ar(1); // 'one'
ar(2); // 'two'
ar(3); // 'few' (3-10)
ar(11); // 'many' (11-99)
ar(100); // 'other' (100, 200, 300...)
ar(101); // 'few' (101-110)Decimal Number Support:
import { en, ar, fr } from "make-plural/cardinals";
// English treats all decimals as 'other'
en(1.0); // 'one'
en(1.5); // 'other'
en(2.0); // 'other'
// French decimal handling
fr(0.5); // 'one' (0 ≤ n < 2)
fr(1.9); // 'one'
fr(2.0); // 'many'
// Arabic decimal handling
ar(0.5); // 'other'
ar(1.0); // 'one'
ar(1.5); // 'other'String Input Support:
import { pl, ru } from "make-plural/cardinals";
// Polish with string numbers
pl("1"); // 'one'
pl("2"); // 'few'
pl("5"); // 'many'
// Russian with string numbers
ru("1"); // 'one' (1, 21, 31...)
ru("2"); // 'few' (2-4, 22-24...)
ru("5"); // 'many' (0, 5-20, 25-30...)Arabic (ar) Rules:
zero: n = 0one: n = 1two: n = 2few: n % 100 in 3-10many: n % 100 in 11-99other: everything elsePolish (pl) Rules:
one: n = 1few: n % 10 in 2-4 && n % 100 not in 12-14many: n % 10 = 0 || n % 10 in 5-9 || n % 100 in 11-14other: everything else (decimals)French (fr) Rules:
one: 0 ≤ n < 2many: n ≥ 2other: not an integerRussian (ru) Rules:
one: n % 10 = 1 && n % 100 ≠ 11few: n % 10 in 2-4 && n % 100 not in 12-14many: n % 10 = 0 || n % 10 in 5-9 || n % 100 in 11-14other: not an integerCardinal-only functions are more memory-efficient than the combined plurals functions:
// More memory efficient for cardinal-only use
import { en, fr } from "make-plural/cardinals";
// Less efficient if you only need cardinals
import { en, fr } from "make-plural";Use cardinal-only functions when:
Avoid when: