Pluralize
Pluralize and singularize any word.
This was forked from https://github.com/plurals/pluralize.
It was refactored into TS and there is now a build step added. Everything else remains the same.
Installation
npm install pluralize --save
yarn add pluralize
Node (ES2015 Module)
import pluralize from 'pluralize';
Node
const pluralize = require('pluralize');
AMD
define(function (require, exports, module) {
const 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
word: string
The word to pluralizecount: number
How many of the word existinclusive: boolean
Whether to prefix with the number (e.g. 3 ducks)
Examples:
pluralize('test');
pluralize('test', 0);
pluralize('test', 1);
pluralize('test', 5);
pluralize('test', 1, true);
pluralize('test', 5, true);
pluralize('蘋果', 2, true);
pluralize.plural('regex');
pluralize.addPluralRule(/gex$/i, 'gexii');
pluralize.plural('regex');
pluralize.singular('singles');
pluralize.addSingularRule(/singles$/i, 'singular');
pluralize.singular('singles');
pluralize.plural('irregular');
pluralize.addIrregularRule('irregular', 'regular');
pluralize.plural('irregular');
pluralize.plural('paper');
pluralize.addUncountableRule('paper');
pluralize.plural('paper');
pluralize.isPlural('test');
pluralize.isSingular('test');
License
MIT