What is plur?
The plur npm package is designed to easily pluralize words. It allows you to get the plural form of a word based on the count provided. This can be particularly useful in applications where you need to display text that dynamically changes based on a quantity (e.g., item counts, messages, etc.).
What are plur's main functionalities?
Pluralizing a word
This feature allows you to pluralize a single word based on a count. If the count is more than one, it returns the plural form of the word.
"const plur = require('plur');\nconsole.log(plur('unicorn', 2)); // 'unicorns'"
Custom plural forms
This feature allows you to specify a custom plural form for a word. This is useful for words that do not follow regular pluralization rules.
"const plur = require('plur');\nconsole.log(plur('radius', 2, 'radii')); // 'radii'"
Other packages similar to plur
pluralize
The pluralize package offers similar functionality to plur, allowing for the pluralization of words. It goes a step further by also supporting singularization, counting, and adding functionality to work with irregular words and uncountable nouns. This makes it a bit more versatile compared to plur.
inflection
Inflection is another npm package that provides methods for transforming words between singular and plural forms, among other string transformations like camelizing, underscoring, and humanizing. It offers a broader set of string manipulation functionalities compared to plur, making it suitable for applications that require more than just pluralization.
plur
Naively pluralize a word
Install
$ npm install --save plur
Usage
var plur = require('plur');
plur('unicorn', 4);
plur('hero', 'heroes', 4);
Words ending in s, x, z, ch, sh will be pluralized with -es, like
foxes. Words ending in y will be pluralized by replacing y with -ies as
in puppies. The plural suffix will match the case of the last letter in the word.
API
plur(word, [plural], count)
word
Type: string
Word to pluralize.
plural
Type: string
Default: word
+ s
Pluralized word.
count
Type: number
Count to determine whether to use singular or plural.
License
MIT © Sindre Sorhus