CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-make-plural

Unicode CLDR pluralization rules as JavaScript functions for internationalization applications

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cardinal-pluralization.mddocs/

Cardinal Pluralization

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.

Capabilities

Cardinal Functions

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 Pattern

import { en, fr, ar, pl } from "make-plural/cardinals";

Language Functions

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"

Usage Examples

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...)

Language-Specific Rules

Arabic (ar) Rules:

  • zero: n = 0
  • one: n = 1
  • two: n = 2
  • few: n % 100 in 3-10
  • many: n % 100 in 11-99
  • other: everything else

Polish (pl) Rules:

  • one: n = 1
  • few: n % 10 in 2-4 && n % 100 not in 12-14
  • many: n % 10 = 0 || n % 10 in 5-9 || n % 100 in 11-14
  • other: everything else (decimals)

French (fr) Rules:

  • one: 0 ≤ n < 2
  • many: n ≥ 2
  • other: not an integer

Russian (ru) Rules:

  • one: n % 10 = 1 && n % 100 ≠ 11
  • few: n % 10 in 2-4 && n % 100 not in 12-14
  • many: n % 10 = 0 || n % 10 in 5-9 || n % 100 in 11-14
  • other: not an integer

Memory Efficiency

Cardinal-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";

When to Use Cardinals

Use cardinal-only functions when:

  1. Memory constraints: Working in memory-constrained environments
  2. Bundle size: Need to minimize JavaScript bundle size
  3. Cardinal-only: Your application only deals with cardinal numbers (counts, quantities)
  4. Performance: Need maximum performance for cardinal pluralization

Avoid when:

  1. Mixed usage: You need both cardinal and ordinal pluralization
  2. Future flexibility: You might need ordinals later
  3. Code simplicity: Using one import pattern is preferred

docs

cardinal-pluralization.md

core-pluralization.md

example-values.md

index.md

ordinal-pluralization.md

plural-categories.md

range-pluralization.md

tile.json