Erik Römmelt d20e8a9d10 Fix EsLint Brackets (error markup 'const'). | 6 years ago | |
---|---|---|
.. | ||
LICENSE | 6 years ago | |
Readme.md | 6 years ago | |
package.json | 6 years ago | |
pluralize.js | 6 years ago |
Pluralize and singularize any word.
npm install pluralize --save
yarn add pluralize
bower install pluralize --save
var pluralize = require('pluralize')
define(function (require, exports, module) {
var pluralize = require('pluralize')
})
<script>
tag<script src="pluralize.js"></script>
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.
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
MIT