1 | [![All dependencies](https://img.shields.io/librariesio/release/npm/decline-word/1.3.1?style=flat-square "All dependencies of decline-word@1.3.1")](https://libraries.io/npm/decline-word/1.3.1)
|
2 | [![Reported vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/decline-word@1.3.1?style=flat-square "Reported vulnerabilities of decline-word@1.3.1")](https://snyk.io/test/npm/decline-word/1.3.1)
|
3 | [![Commits](https://flat.badgen.net/github/commits/ArthurKa/decline-word)](https://github.com/ArthurKa/decline-word/commits/master)
|
4 | [![NPM-version](https://img.shields.io/badge/npm-v1.3.1-blue.svg?style=flat-square&&logo=npm "Current NPM-version")](https://www.npmjs.com/package/decline-word/v/1.3.1)
|
5 | [![Total downloads](https://img.shields.io/npm/dt/decline-word?style=flat-square "Total downloads for all the time")](https://npm-stat.com/charts.html?package=decline-word)
|
6 | [![Developed by](https://img.shields.io/badge/developed_by-ArthurKa-blueviolet.svg?style=flat-square "Have any questions? You are always welcome.")](https://github.com/ArthurKa/decline-word/issues)\
|
7 | [![Publish size](https://flat.badgen.net/packagephobia/publish/decline-word@1.3.1?label=publish 'Publish size of decline-word@1.3.1')](https://packagephobia.now.sh/result?p=decline-word@1.3.1)
|
8 | [![Install size](https://flat.badgen.net/packagephobia/install/decline-word@1.3.1?label=install 'Install size of decline-word@1.3.1')](https://packagephobia.now.sh/result?p=decline-word@1.3.1)
|
9 | [![Minified size](https://img.shields.io/bundlephobia/min/decline-word@1.3.1?style=flat-square&label=minified "Minified size of decline-word@1.3.1")](https://bundlephobia.com/result?p=decline-word@1.3.1)
|
10 | [![Minified + gzipped size](https://img.shields.io/bundlephobia/minzip/decline-word@1.3.1?style=flat-square&label=minzipped "Minified + gzipped size of decline-word@1.3.1")](https://bundlephobia.com/result?p=decline-word@1.3.1)
|
11 |
|
12 | # decline-word@1.3.1
|
13 |
|
14 | Helps you to inflect words of **Russian**, **Ukrainian** and **English** languages.\
|
15 | It may work for some other languages, who knows.
|
16 |
|
17 | ## Installation
|
18 | `decline-word` is available via npm:
|
19 | ``` bash
|
20 | $ npm i decline-word@1.3.1
|
21 | ```
|
22 |
|
23 | ## Usage
|
24 | ### For Russian and Ukrainian languages:
|
25 | | Parameter | Required | Default value | Value |
|
26 | |-----------|----------|---------------|-----------------------------------------------------------------|
|
27 | | 1st | true | | **amount** of items |
|
28 | | 2nd | true | | **main part** of the word (unchangeable beginning of each form) |
|
29 | | 3rd | false | `''` | word ending for **1 item** |
|
30 | | 4th | false | `''` | word ending for **2 items** |
|
31 | | 5th | false | `''` | word ending for **5 items** |
|
32 |
|
33 | ```ts
|
34 | import declineWord from 'decline-word';
|
35 |
|
36 | console.log(`12 ${declineWord(12, 'яблок', 'о', 'а')}`); // 12 яблок
|
37 | console.log(`22 ${declineWord(22, 'яблок', 'о', 'а')}`); // 22 яблока
|
38 | console.log(`159 ${declineWord(159, 'яблок', 'о', 'а')}`); // 159 яблок
|
39 | console.log(`1151 ${declineWord(1151, 'яблок', 'о', 'а')}`); // 1151 яблоко
|
40 |
|
41 | console.log(`1 ${declineWord(1, 'апельсин', '', 'и', 'ів')}`); // 1 апельсин
|
42 | console.log(`11 ${declineWord(11, 'апельсин', '', 'и', 'ів')}`); // 11 апельсинів
|
43 | console.log(`84 ${declineWord(84, 'апельсин', '', 'и', 'ів')}`); // 84 апельсини
|
44 | console.log(`147 ${declineWord(147, 'апельсин', '', 'и', 'ів')}`); // 147 апельсинів
|
45 |
|
46 | console.log(`0 ${declineWord(0, '', 'гра', 'гри', 'ігор')}`); // 0 ігор
|
47 | console.log(`1 ${declineWord(1, '', 'гра', 'гри', 'ігор')}`); // 1 гра
|
48 | console.log(`4 ${declineWord(4, '', 'гра', 'гри', 'ігор')}`); // 4 гри
|
49 | console.log(`25 ${declineWord(25, '', 'гра', 'гри', 'ігор')}`); // 25 ігор
|
50 | ```
|
51 |
|
52 | ### For English language:
|
53 | There are some differences of parameter default values comparing to Russian and Ukrainian languages.
|
54 |
|
55 | | Parameter | Required | Default value | Value |
|
56 | |-----------|----------|-------------------|-----------------------------------------------------------------|
|
57 | | 1st | true | | **amount** of items |
|
58 | | 2nd | true | | **main part** of the word (unchangeable beginning of each form) |
|
59 | | 3rd | false | `''` | word ending for **1 item** |
|
60 | | 4th | false | `'s'` | word ending for **2 items** |
|
61 | | 5th | false | `<4th parameter>` | word ending for **5 items** |
|
62 |
|
63 | This difference makes more convenience for using English words.
|
64 |
|
65 | Note: `decline-word` declines English words incorrect according to language rules. Just because of `if not equal to one` is very simple check algorithm (and I'm too lazy to change already made one) this package declines them according to Russian/Ukrainian language rules. Do not use `decline-word` for English language if you want to decline words correctly.
|
66 |
|
67 | ```ts
|
68 | import declineWord from 'decline-word';
|
69 |
|
70 | console.log(`1 ${declineWord(1, 'door')}`); // 1 door
|
71 | console.log(`10 ${declineWord(10, 'door')}`); // 10 doors
|
72 |
|
73 | console.log(`11 ${declineWord(11, 'hero', '', 'es')}`); // 11 heroes
|
74 | console.log(`21 ${declineWord(21, 'hero', '', 'es')}`); // 21 hero (but correct is "heros")
|
75 |
|
76 | console.log(`5 ${declineWord(5, 'cand', 'y', 'ies')}`); // 5 candies
|
77 | console.log(`101 ${declineWord(101, 'cand', 'y', 'ies')}`); // 101 candy (but correct is "candies")
|
78 |
|
79 | // declineWord(31, 't', 'ooth', 'eeth') or...
|
80 | console.log(`31 ${declineWord(31, '', 'tooth', 'teeth')}`); // 31 tooth (but correct is "teeth")
|
81 | console.log(`32 ${declineWord(32, '', 'tooth', 'teeth')}`); // 32 teeth
|
82 | ```
|
83 |
|
84 | ## Advanced usage
|
85 | ```ts
|
86 | import { declineWrapper } from 'decline-word';
|
87 |
|
88 | const declApples = declineWrapper('яблок', 'о', 'а');
|
89 | const declOranges = declineWrapper('апельсин', '', 'а', 'ов');
|
90 | const declPears = declineWrapper('груш', 'а', 'и');
|
91 |
|
92 | for(let i = 0; i <= 6; i++) {
|
93 | console.log(`${i} ${declApples(i)} | ${i} ${declOranges(i)} | ${i} ${declPears(i)}`);
|
94 | }
|
95 |
|
96 | /*
|
97 | 1st iteration: '0 яблок | 0 апельсинов | 0 груш'
|
98 | 2nd iteration: '1 яблоко | 1 апельсин | 1 груша'
|
99 | 3rd iteration: '2 яблока | 2 апельсина | 2 груши'
|
100 | 4th iteration: '3 яблока | 3 апельсина | 3 груши'
|
101 | 5th iteration: '4 яблока | 4 апельсина | 4 груши'
|
102 | 6th iteration: '5 яблок | 5 апельсинов | 5 груш'
|
103 | 7th iteration: '6 яблок | 6 апельсинов | 6 груш'
|
104 | */
|
105 | ```
|
106 |
|
107 | ### Declination of cases:
|
108 | ```ts
|
109 | import { declineWrapper } from 'decline-word';
|
110 |
|
111 | // Nominative case, именительный падеж, називний відмінок
|
112 | const nomCase = declineWrapper('падеж', '', 'а', 'ей');
|
113 | console.log('один', nomCase(1)); // один падеж
|
114 | console.log('два', nomCase(2)); // два падежа
|
115 | console.log('пять', nomCase(5)); // пять падежей
|
116 |
|
117 | // Genitive case, родительный падеж, родовий відмінок
|
118 | const genCase = declineWrapper('падеж', 'а', 'ей', 'ей');
|
119 | console.log('одного', genCase(1)); // одного падежа
|
120 | console.log('двух', genCase(2)); // двух падежей
|
121 | console.log('пяти', genCase(5)); // пяти падежей
|
122 |
|
123 | // Dative case, дательный падеж, давальний відмінок
|
124 | const datCase = declineWrapper('падеж', 'у', 'ам', 'ам');
|
125 | console.log('одному', datCase(1)); // одному падежу
|
126 | console.log('двум', datCase(2)); // двум падежам
|
127 | console.log('пяти', datCase(5)); // пяти падежам
|
128 |
|
129 | // Accusative case, винительный падеж, знахідний відмінок
|
130 | const accCase = declineWrapper('падеж', '', 'а', 'ей');
|
131 | console.log('один', accCase(1)); // один падеж
|
132 | console.log('два', accCase(2)); // два падежа
|
133 | console.log('пять', accCase(5)); // пять падежей
|
134 |
|
135 | // Instrumental case, творительный падеж, орудний відмінок
|
136 | const insCase = declineWrapper('падеж', 'ом', 'ами', 'ами');
|
137 | console.log('одним', insCase(1)); // одним падежом
|
138 | console.log('двумя', insCase(2)); // двумя падежами
|
139 | console.log('пятью', insCase(5)); // пятью падежами
|
140 |
|
141 | // Prepositional case, предложный падеж, місцевий відмінок
|
142 | const prepCase = declineWrapper('падеж', 'е', 'ах', 'ах');
|
143 | console.log('на одном', prepCase(1)); // на одном падеже
|
144 | console.log('на двух', prepCase(2)); // на двух падежах
|
145 | console.log('на пяти', prepCase(5)); // на пяти падежах
|
146 | ```
|
147 |
|
148 | ## Testing
|
149 | ``` bash
|
150 | $ npm test
|
151 | ```
|
152 |
|
153 | ## See also
|
154 | - [word-decliner](https://www.npmjs.com/package/word-decliner)
|
155 |
|
156 | ---
|
157 |
|
158 | Your improve suggestions and bug reports [are welcome](https://github.com/ArthurKa/decline-word/issues) any time.
|