pluralize-esm
TypeScript icon, indicating that this package has built-in type declarations

9.0.5 • Public • Published

Pluralize

NPM version NPM downloads Build Status GitHub Super-Linter File Size

Pluralize and singularize any word. A fork of pluralize

Installation

npm install pluralize-esm

Node.js

var pluralize = require('pluralize-esm')

ESM

import pluralize from 'pluralize-esm'

Why?

This module uses a predefined 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"
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

License

MIT

/pluralize-esm/

    Package Sidebar

    Install

    npm i pluralize-esm

    Weekly Downloads

    91,642

    Version

    9.0.5

    License

    MIT

    Unpacked Size

    76.7 kB

    Total Files

    9

    Last publish

    Collaborators

    • christianhg
    • joan_miralles_paez
    • jwoods-sanity
    • armandocerna
    • daniel.malmer
    • jordanl17
    • tambet
    • jtpetty
    • drewsanity
    • refiito
    • sergeisarviro
    • ash
    • indrek.karner
    • cngonzalez-sanity
    • rdunk
    • rneatherway-sanity
    • ricokahler
    • pedro-sanity
    • jonabc
    • kenjonespizza
    • pauloborgesf
    • binoy14
    • simen.svale
    • svirs
    • josh_sanity_io
    • joneidejohnsen
    • nina.andal
    • rankers
    • snorreeb
    • mattcraig
    • vincentquigley
    • stipsan
    • michael-sanity
    • rubioz
    • tonina
    • ritasdias
    • simeonsanity
    • kmelve
    • bjoerge
    • rexxars
    • skogsmaskin
    • robinpyon
    • mariuslundgard
    • sanity-io
    • evenw
    • radhe_sanity
    • rbotten
    • judofyr
    • obliadp
    • dcilke
    • fredcarlsen
    • hermanw
    • sgulseth
    • atombender