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