0.0.10 • Published 6 months ago

pluralize-tool v0.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

pluralize-tool

pluralize-tool is a simple utility for pluralizing words based on the number. It handles pluralization rules, special cases, and works for languages like Russian, where the word form changes depending on the number.

Installation

npm install pluralize-tool

Usage

Importing the library

import plural from 'pluralize-tool';

const appleCount = 3;
const result = plural(appleCount, ['яблоко', 'яблока', 'яблок']);

console.log(result);  // Outputs: "яблока"

Special Cases

You can define special cases where certain numbers (e.g., 0, 1) have custom plural forms:

const specialCases = {
  0: 'пусто',
};

const result = plural(0, ['яблоко', 'яблока', 'яблок'], specialCases);

console.log(result);  // Outputs: "пусто"

Structure titles

The titles array must always contain exactly three word forms to handle different pluralization rules. Here's how the array should be structured:

  • First form (nominative singular): Used for numbers ending in 1, except those ending in 11. Example: "яблоко", "человек", "рыба".

  • Second form (genitive singular): Used for numbers ending in 2, 3, 4, except those ending in 12, 13, 14. Example: "яблока", "человека", "рыбы".

  • Third form (genitive plural): Used for numbers ending in 0, 5-9, and for all numbers from 11 to 19. Example: "яблок", "людей", "рыб".

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago