Yet another pluralization library but this time primarly in Russian 🇷🇺
PRs are welcome to add another languages
npm install pluralizer-ru
Import language-based function from module as
import { pluralizeRu } from 'pluralizer-ru'
Pass amount of items and pluralization options as a second argument
pluralizeRu(items.length, {
single: 'результат',
some: 'результата',
many: 'результатов',
})
Second argument is pluralization object which accepts 3-4 keys for:
Key | Condition, val = total items |
---|---|
single | val % 10 === 1 && val % 100 !== 11 |
some | `val % 10 >= 2 && val % 10 <= 4 && (val % 100 < 10 |
many | other cases but 0 |
none | (optional) - n === 0 . If was not passed 0 value will be pluralized as many |
pluralizeRu(0, {
single: 'результат',
some: 'результата',
many: 'результатов',
}) // 0 результатов
pluralizeRu(0, {
single: 'результат',
some: 'результата',
many: 'результатов',
none: '(ничего)',
}) // 0 (ничего)
Sometimes you need to show something but 0 for no results, e.g. "No results". Pass its value as 3rd argument
pluralizeRu(0, {
single: 'результат',
some: 'результата',
many: 'результатов',
none: 'ничего',
}, 'Нет') // Нет ничего
If your design requires to put value and title on different sites, e.g statistics cards, set false
as 4th argument
pluralizeRu(0, {
single: 'результат',
some: 'результата',
many: 'результатов',
none: 'ничего',
}, 0, false) // ничего
Open-source under MIT license
We are using Bun
bun test