node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

pluralize

Pluralize

NPM version NPM downloads Build status Test coverage File Size CDNJS Greenkeeper badge

Pluralize and singularize any word.

Installation

npm install pluralize --save
yarn add pluralize
bower install pluralize --save

Node

var pluralize = require('pluralize')

AMD

define(function (require, exports, module) {
  var pluralize = require('pluralize')
})

<script> tag

<script src="pluralize.js"></script>

Why?

This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.

Usage

pluralize('test') //=> "tests" 
pluralize('test', 1) //=> "test" 
pluralize('test', 5) //=> "tests" 
pluralize('test', 1, true) //=> "1 test" 
pluralize('test', 5, true) //=> "5 tests" 
pluralize('蘋果', 2, true) //=> "2 蘋果" 
 
pluralize.plural('regex') //=> "regexes" 
pluralize.addPluralRule(/gex$/i, 'gexii')
pluralize.plural('regex') //=> "regexii" 
 
pluralize.singular('singles') //=> "single" 
pluralize.addSingularRule(/singles$/i, 'singular')
pluralize.singular('singles') //=> "singular" 
 
pluralize.plural('irregular') //=> "irregulars" 
pluralize.addIrregularRule('irregular', 'regular')
pluralize.plural('irregular') //=> "regular" 
 
pluralize.plural('paper') //=> "papers" 
pluralize.addUncountableRule('paper')
pluralize.plural('paper') //=> "paper" 
 
pluralize.isPlural('test') //=> false 
pluralize.isSingular('test') //=> true 

License

MIT