Pretty Letter – don't screw up in grammar!
This package can help you with choosing correct letter for your word depending on quantity. Can be used for Russian, Ukrainian and other languages that have the same plural rules
You should pass a number on which the choice of letter depends as a first argument and array of three letters to choose from as a second argument.
Imagine you're dealing only with digits.
letters must be a letter you always use for 1,
letters must be a letter you always use for 2..4,
letters must be a letter you always use for 5..9 and 0
For example, we want to build a message, that contains info about comments count:
// Importing library old-school wayconst pl =// Or importing as ES6 module// import pl from 'pretty-letter'const commentsCount = 220const ending = // imagine "1 комментарий", "2 комментария", "5 комментариев"const message = ` комментари`console // 220 комментариев
You could even build the entire word just like this:
const pl =const commentsCount = 220const word = // imagine "1 комментарий", "2 комментария", "5 комментариев"const message = ` `console // 220 комментариев
Module works pretty fine with any numbers, even with negative numbers and fractional numbers.