npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kodozorro/pluralizer

v1.2.0

Published

Chooses right plural form for different languages. Was made for React native purpose on TypeScript.

Downloads

4

Readme

@kodozorro/pluralizer

npm gitHub

Chooses right plural form for different languages. Was made for React native purpose with TypeScript.

List of languages it can work with

  • Asian, Persian, Turkic/Altaic (Turkish), Thai, Lao
  • Germanic, Finno-Ugric, Language isolate, Latin/Greek, Semitic (Hebrew), Romanic, Vietnamese
  • Romanic (French, Brazilian Portuguese)
  • Baltic (Latvian)
  • Celtic (Scottish Gaelic)
  • Romanic (Romanian)
  • Baltic (Lithuanian)
  • Belarusian, Russian, Ukrainian
  • Slavic (Slovak, Czech)
  • Slavic (Polish)
  • Slavic (Slovenian, Sorbian)
  • Celtic (Irish Gaelic)
  • Semitic (Arabic)
  • Semitic (Maltese)
  • Icelandic, Macedonian
  • Welsh
  • Slavic (Bosnian, Croatian, Serbian)

Why should I use it?

Well, let me try to explain.

Imagine you need to make dynamic forms of ome words in your app. With i18n, for more than one language. If it's Germanic language family, it'll be easy because they have 2 plural forms just. But if it's Russian? With 3 forms and some exceptions? Or even Semitic (Arabic)? With 6 forms and exceptions also? And you need to make a lot of translation work with plural forms, understand how to manage with words depending on number if it's dynamic.

This small tool can do it for you.

Install

This package uses react-native-localize to get current locale on phone. It works both on Android and IPhones. So, please install it too.

$ npm install @kodozorro/pluralizer
$ npm install react-native-localize

Usage

This tool works with prepared words, it doesn't generate anything!!

import pluralize from "@kodozorro/pluralizer";

/**
 * @param {number}  number - A number, which is used for plural or singular form.
 * @param {string[]} words - An array of words, which you want to be pluralized.
 * @param {boolean} [withNumber] - optional param, if true retuns string with a number before word.
 * @param {boolean} [after] - optional param, if true returns string with a number after word.
 * @param {string} [locale] - optional param, if you hve ready locale code, you can pass it.
 * @returns {string} This is the result word with needed plural or singular form.
 */

// Provide array of words with all plural forms in right order.

<Text>{'Some text that includes dynamic number of birds.'}</Text>
<Text>{'I have' + number + pluralize(number, ["Bird", "Birds"])}</Text>
//=> "I have 5 Birds"

<Text>{'Какой-то текст с динамическим изменением числа чего-то или кого-то.'}</Text>
<Text>{'У меня в квартире живёт' + number + pluralize(number, ["Синица", "Синицы", "Синиц"])}</Text>
//=> "У меня в квартире живёт 5 Синиц"


// Simplest example.
pluralize(5, ["Bird", "Birds"]);
//=> "Birds"

pluralize(5, ["Синица", "Синицы", "Синиц"]);
//=> "Синиц"

// Example that returns also a number not only string
pluralize(3, ["Bird", "Birds"], true);
//=> "3 Birds"

pluralize(3, ["Синица", "Синицы", "Синиц"], true);
//=> "3 Синицы"

// Number after word
pluralize(1, ["Bird", "Birds"], true, true);
//=> "Bird 1"

pluralize(1, ["Синица", "Синицы", "Синиц"], true, true);
//=> "Синица 1"

// If you have already your locale language code.
pluralize(0, ["Bird", "Birds"], true, true, "en");
//=> "Birds 0"

pluralize(0, ["Синица", "Синицы", "Синиц"], true, true, "en");
//=> "Синиц 0"

Prepare your plural forms

You must provide your array of words, which can be used. Translation of that is your responsibility.

You must know the plural rule of your language!! But, I'll show them further.

Please follow the correct order of the forms!!!

For example, if it is word Bird you want to pluralize, than you must have an array like this:

["Bird", "Birds"];

Due to two plural forms in English.

If it is Russian language, than array of three words:

["Синица", "Синицы", "Синиц"];

Due to three plural forms in these language.

List of Plural Rules in different language families

Provided by MDN

Plural rule #0 (1 form) Asian, Persian, Turkic/Altaic (Turkish), Thai, Lao

Families: Asian (Chinese, Japanese, Korean), Persian, Turkic/Altaic (Turkish), Thai, Lao

  • everything: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, …

Plural rule #1 (2 forms): Germanic, Finno-Ugric, Language isolate, Latin/Greek, Semitic (Hebrew), Romanic, Vietnamese

Families: Germanic (Danish, Dutch, English, Faroese, German, Norwegian, Swedish), Finno-Ugric (Estonian, Finnish, Hungarian), Language isolate (Basque), Latin/Greek (Greek), Semitic (Hebrew), Romanic (Italian, Portuguese, Spanish, Catalan), Vietnamese

  • is 1: 1
  • everything else: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, …

Plural rule #2 (2 forms): Romanic (French, Brazilian Portuguese),

Families: Romanic (French, Brazilian Portuguese)

  • is 0 or 1: 0, 1
  • everything else: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …

Plural rule #3 (3 forms): Baltic (Latvian)

Families: Baltic (Latvian)

  • ends in 0: 0
  • ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, …
  • everything else: 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 47, 48, 49, 52, 53, …

Plural rule #4 (4 forms): Celtic (Scottish Gaelic)

Families: Celtic (Scottish Gaelic)

  • is 1 or 11: 1, 11
  • is 2 or 12: 2, 12
  • is 3-10 or 13-19: 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19
  • everything else: 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …

Plural rule #5 (3 forms): Romanic (Romanian)

Families: Romanic (Romanian)

  • is 1: 1
  • is 0 or ends in 01-19, excluding 1: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, …
  • everything else: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, …

Plural rule #6 (3 forms): Baltic (Lithuanian)

Families: Baltic (Lithuanian)

  • ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, …
  • ends in 0 or ends in 11-19: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, …
  • everything else: 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 47, 48, 49, 52, 53, 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 66, 67, 68, 69, 72, 73, …

Plural rule #7 (3 forms): Belarusian, Russian, Ukrainian

Families: Belarusian, Russian, Ukrainian

  • ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, …
  • ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104, 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164, 172, 173, 174, 182, 183, …
  • everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49, 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, …, 112, 113, ..., 212, 213, ...

Plural rule #8 (3 forms): Slavic (Slovak, Czech)

Families: Slavic (Slovak, Czech)

  • is 1: 1
  • is 2-4: 2, 3, 4
  • everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, …

Plural rule #9 (3 forms): Slavic (Polish)

Families: Slavic (Polish)

  • is 1: 1
  • ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104, 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164, 172, 173, 174, 182, 183, …
  • everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30, 31, 35, 36, 37, 38, 39, 40, 41, 45, 46, 47, 48, 49, 50, 51, 55, 56, 57, 58, 59, 60, 61, 65, 66, 67, 68, …

Plural rule #10 (4 forms): Slavic (Slovenian, Sorbian)

Families: Slavic (Slovenian, Sorbian)

  • ends in 01: 1, 101, 201, …
  • ends in 02: 2, 102, 202, …
  • ends in 03-04: 3, 4, 103, 104, 203, 204, …
  • everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, …

Plural rule #11 (5 forms): Celtic (Irish Gaelic)

Families: Celtic (Irish Gaelic)

  • is 1: 1
  • is 2: 2
  • is 3-6: 3, 4, 5, 6
  • is 7-10: 7, 8, 9, 10
  • everything else: 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, …

Plural rule #12 (6 forms): Semitic (Arabic)

Families: Semitic (Arabic)

  • is 1: 1
  • is 2: 2
  • ends in 03-10: 3, 4, 5, 6, 7, 8, 9, 10, 103, 104, 105, 106, 107, 108, 109, 110, 203, 204, 205, 206, 207, 208, 209, 210, …
  • everything else but is 0 and ends in 00-02, excluding 0-2: 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, …
  • ends in 00-02, excluding 0-2: 100, 101, 102, 200, 201, 202, … is 0: 0

Plural rule #13 (4 forms): Semitic (Maltese)

Families: Semitic (Maltese)

  • is 1: 1
  • is 0 or ends in 01-10, excluding 1: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, …
  • ends in 11-19: 11, 12, 13, 14, 15, 16, 17, 18, 19, 111, 112, 113, 114, 115, 116, 117, 118, 119, 211, 212, 213, 214, 215, 216, 217, 218, 219, …
  • everything else: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, …

Plural rule #14 (3 forms): unused

Families: unused

  • ends in 1: 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 201, 211, 221, 231, 241, 251, 261, 271, 281, 291, …
  • ends in 2: 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152, 162, 172, 182, 192, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, …
  • everything else: 0, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 43, 44, 45, 46, 47, 48, 49, 50, 53, 54, 55, 56, 57, 58, 59, 60, 63, …

Plural rule #15 (2 forms): Icelandic, Macedonian

Families: Icelandic, Macedonian

  • ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, …
  • everything else: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, …

Plural rule #16 (5 forms): Celtic (Breton)

Families: Celtic (Breton)

  • ends in 1, excluding 11, 71, 91: 21, 31, 41, 51, 61, 81, 101, 121, 131, 141, 151, 161, 181, 201, 221, 231, 241, 251, 261, 281, ...
  • ends in 2, excluding 12, 72, 92: 2, 22, 32, 42, 52, 62, 82, 102, 122, 132, 142, 152, 162, 182, 202, 222, 232, 242, 252, 262, 282, ...
  • ends in 3, 4 or 9 excluding 13, 14, 19, 73, 74, 79, 93, 94, 99: 3, 4, 9, 23, 24, 29, 33, 34, 39, 43, 44, 49, 53, 54, 59, ...
  • ends in 000000: 1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000, ...
  • everything else: 0, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 30, 35, 36, 37, 38, 40, ...

Plural rule #17 (2 forms): Ecuador indigenous languages (Shuar)

Families: Ecuador indigenous languages (Shuar)

  • is 0: 0
  • everything else: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …

Plural rule #18 (6 forms): Welsh

Families: Welsh

  • is 0: 0
  • is 1: 1
  • is 2: 2
  • is 3: 3
  • is 6: 6
  • everything else: 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, …

Plural rule #19 (3 forms): Slavic (Bosnian, Croatian, Serbian)

Families: Slavic (Bosnian, Croatian, Serbian)

  • ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, …
  • ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104, 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164, 172, 173, 174, 182, 183, …
  • everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49, 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, …, 112, 113, ..., 212, 213, ...