UNPKG

2.52 kBMarkdownView Raw
1Helps you to decline words in **Russian**, **Ukrainian** and **English** languages.
2
3## Installation
4`decline-word` is available via npm:
5``` bash
6$ npm i decline-word
7```
8
9## Usage
10### For **Russian** and **Ukrainian** languages.
111st parameter: **amount** of item(s)
122nd: main word **body** (unchangeable part of word for each form)
133nd (optional, dafault = `''`): word ending for **1 item**
144th (optional, dafault = `''`): word ending for **2 items**
155th (optional, dafault = `''`): word ending for **5 items**
16``` js
17const declineWord = require('decline-word');
18
19console.log(12, declineWord(12, 'яблок', 'о', 'а')); // 12 яблок
20console.log(22, declineWord(22, 'яблок', 'о', 'а')); // 22 яблока
21console.log(159, declineWord(159, 'яблок', 'о', 'а')); // 159 яблок
22console.log(1151, declineWord(1151, 'яблок', 'о', 'а')); // 1151 яблоко
23
24console.log(1, declineWord(1, 'апельсин', '', 'и', 'ів')); // 1 апельсин
25console.log(11, declineWord(11, 'апельсин', '', 'и', 'ів')); // 11 апельсинів
26console.log(84, declineWord(84, 'апельсин', '', 'и', 'ів')); // 84 апельсини
27console.log(147, declineWord(147, 'апельсин', '', 'и', 'ів')); // 147 апельсинів
28```
29
30### For **English** language.
31There is some difference of default parameter values comparing with the Russian and Ukrainian languages.
321st parameter: **amount** of item(s)
332nd: main word **body** (unchangeable part of word for each form)
343nd (optional, dafault = `''`): word ending for **1 item**
354th (optional, dafault = `'s'`): word ending for **2 items**
365th (optional, dafault = `<4th parameter>`): word ending for **5 items**
37That is made for more convenience using with English words.
38``` js
39const declineWord = require('decline-word');
40
41console.log(1, declineWord(1, 'door')); // 1 door
42console.log(10, declineWord(10, 'doors')); // 10 doors
43
44console.log(11, declineWord(11, 'hero', '', 'es')); // 11 heroes
45console.log(21, declineWord(21, 'hero', '', 'es')); // 21 hero
46
47console.log(5, declineWord(5, 'cand', 'y', 'ies')); // 5 candies
48console.log(101, declineWord(101, 'cand', 'y', 'ies')); // 101 candy
49
50// declineWord(31, 't', 'ooth', 'eeth') or...
51console.log(31, declineWord(31, '', 'tooth', 'teeth')); // 31 tooth
52console.log(32, declineWord(32, '', 'tooth', 'teeth')); // 32 teeth
53```
54
55Your improve suggestions and bug reports are welcome any time.