Skip to content package
pluralize v7.0.0 Pluralize and singularize any word
node >=4 0 deps cjs open source
overview readme
license MIT
deps 0
unpacked Unknown
files Unknown
node >=4 $ npm install pluralize@7.0.0n npmREADME GitHub-flavored package documentation.
downloads Across all versions, last 30 days.
59,615,142 weekly +1.2%
224,063,191 in 30 days
Oct 16 → Nov 14 hover or arrows
compatibility Runtime metadata.
keywords Tagged topics.
plural plurals pluralize singular singularize inflection
versions Latest published May 25, 2019
maintainers Registry package owners.
install size Estimated unpacked size across 1 packages.
17.3 kB
Includes dependencies.
contents Pluralize
Pluralize and singularize any word.
Installation
npm install pluralize --save
yarn add pluralize
bower install pluralize --save copy
Node
var pluralize = require ( 'pluralize' ) copy
AMD
define ( function (require, exports, module) {
var pluralize = require ( 'pluralize' )
}) copy
<script> tag
< script src = "pluralize.js" ></ script > copy
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
word: string The word to pluralize
count: number How many of the word exist
inclusive: boolean Whether to prefix with the number (e.g. 3 ducks)
Examples:
pluralize ( 'test' ) //=> "tests"
pluralize ( 'test' , 0 ) //=> "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 蘋果"
// Example of new plural rule:
pluralize. plural ( 'regex' ) //=> "regexes"
License
MIT
pluralize.
addPluralRule
(
/gex$/
i
,
'gexii'
)
pluralize. plural ( 'regex' ) //=> "regexii"
// Example of new singular rule:
pluralize. singular ( 'singles' ) //=> "single"
pluralize. addSingularRule ( /singles$/ i , 'singular' )
pluralize. singular ( 'singles' ) //=> "singular"
// Example of new irregular rule, e.g. "I" -> "we":
pluralize. plural ( 'irregular' ) //=> "irregulars"
pluralize. addIrregularRule ( 'irregular' , 'regular' )
pluralize. plural ( 'irregular' ) //=> "regular"
// Example of uncountable rule (rules without singular/plural in context):
pluralize. plural ( 'paper' ) //=> "papers"
pluralize. addUncountableRule ( 'paper' )
pluralize. plural ( 'paper' ) //=> "paper"
// Example of asking whether a word looks singular or plural:
pluralize. isPlural ( 'test' ) //=> false
pluralize. isSingular ( 'test' ) //=> true
copy