Nervously Proposing Marriage
    Have ideas to improve npm?Join in the discussion! »

    pretty-letter
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.15 • Public • Published

    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.

    Install

    npm i pretty-letter

    DownloadsWeekly Downloads

    15

    Version

    1.0.15

    License

    ISC

    Unpacked Size

    6.21 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar