1.0.15 • Published 4 years ago

pretty-letter v1.0.15

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Pretty Letter – don't screw up in grammar!

Build Status

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[0] must be a letter you always use for 1, letters[1] must be a letter you always use for 2..4, letters[2] 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 way
const pl = require('pretty-letter')
// Or importing as ES6 module
// import pl from 'pretty-letter'

const commentsCount = 220
const ending = pl(commentsCount, ['й', 'я', 'ев']) // imagine "1 комментарий", "2 комментария", "5 комментариев"
const message = `${commentsCount} комментари${ending}`

console.log(message) // 220 комментариев

You could even build the entire word just like this:

const pl = require('pretty-letter')

const commentsCount = 220
const word = pl(commentsCount, ['комментарий', 'комментария', 'комментариев']) // imagine "1 комментарий", "2 комментария", "5 комментариев"
const message = `${commentsCount} ${word}`

console.log(message) // 220 комментариев

Module works pretty fine with any numbers, even with negative numbers and fractional numbers.

1.0.15

4 years ago

1.0.14

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago