Coder Social home page Coder Social logo

numd's Introduction

numd Build Status

Pluralize a word

  • 1 dollar, 5 dollars
  • 1 рубль, 2 рубля, 5 рублей

Install

npm install --save numd

Usage

import numd from 'numd';

numd(2, 'dollar', 'dollars'); // 2 dollars
numd(14, 'рубль', 'рубля', 'рублей'); // 14 рублей

API

numd([num, ]word[, singular], plural)

Return a string if num is defined:

numd(1, 'dollar', 'dollars'); // 1 dollar
numd(1, 'рубль', 'рубля', 'рублей'); // 1 рубль

otherwise return a function:

const rur = numd('рубль', 'рубля', 'рублей');
rur(4); // 4 рубля
rur(51); // 51 рубль

num

Type: number

Count to determine a word.

word

Type: string

Word in the nominative singular.

singular

Type: string

Word in the genitive singular, not used for English words and some other languages.

plural

Type: string

Word in the plural/genitive plural.

License

MIT

numd's People

Contributors

andrepolischuk avatar iamstarkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

numd's Issues

less responsibility is more flexibility

for jsunderhood.ru header, I already use numd for pluralizing, but I also want to use typographic-numbers, but it seems to be impossible, because numd consume number and simple string with it this number inside.

Is it possible for numd to become more flexible and to return only one of plural form. Usage will look like this:

import numd from 'numd';
import numbers from 'typographic-numbers';

const fellas = 1455;
const plural = numd('человек', 'человека', 'людей');

// this is doable now
const simple = `${fellas} ${plural(fellas)}`;  // 1455 человек

// this is not, but desired
const adv = `${numbers(fellas)} ${plural(fellas)}`;  // 1 455 человек

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.