Skip to main content

Pluralize Strings and More...

The pluralizer is a default shared instance of the Pluralizer class.
It comes preloaded with standard English rules, irregular forms, and uncountable nouns.

Acknowledgement

This utility is heavily inspired by Blake Embrey’s excellent pluralize package.

  • Many of the core regular expressions, irregular word mappings, and uncountable word lists were studied and adapted from the original implementation.
  • Additional improvements, extensions, and refactoring were made to fit the needs of this project, but full credit goes to the author for the foundational work and inspiration.

Many thanks to the author for the original work and inspiration.

When to Use
  • Use this instance when you don’t need multiple configurations.
  • If you need isolated or custom rules, you can create your own Pluralizer instance.

✨ Features​

  • βœ… Convert words between singular and plural.
  • βœ… Built‑in support for irregular forms (e.g. child β†’ children).
  • βœ… Handles uncountable nouns (e.g. fish, information).
  • βœ… Modify rules dynamically at runtime:
    • Add pluralization or singularization rules.
    • Add irregular forms.
    • Add uncountable words or regex patterns.

πŸ“¦ Import​

import { pluralizer } from 'nhb-toolbox';

πŸš€ Quick Usage​

pluralizer.pluralize('child'); // "children"
pluralizer.pluralize('category', { count: 3 }); // "categories"
pluralizer.pluralize('child', { count: 1, inclusive: true }); // "1 child"

πŸ”§ Extending Rules​

Since pluralizer is an actual instance of Pluralizer, you can extend or modify it at runtime:

// Add a custom plural rule
pluralizer.addPluralRule(/(foo)$/i, '$1bars');

// Add a custom singular rule
pluralizer.addSingularRule(/(bars)$/i, '$1');

// Add an uncountable noun
pluralizer.addUncountable('luggage');

// Add an irregular word
pluralizer.addIrregular('cactus', 'cacti');

These modifications affect all consumers of the shared instance.


πŸ— Need your own configuration?​

If you want an isolated instance with its own rules, instantiate the class directly:

import { Pluralizer } from 'nhb-toolbox';

const myPluralizer = new Pluralizer();
myPluralizer.addPluralRule(/(baz)$/i, '$1zes');
console.log(myPluralizer.pluralize('baz')); // bazzes

See the Pluralizer class docs for full details.


See also​


Summary​

Use pluralizer for common use‑cases. Create new Pluralizer() for isolated/custom rules.