pluralize-camelcase
v1.0.0
Published
camelCase-aware wrapper around the pluralize library
Maintainers
Readme
pluralize-camelcase
A camelCase-aware wrapper around the pluralize library.
The upstream pluralize library lowercases input before processing, which breaks camelCase words — singularize('intendedUses') returns 'intendedus' instead of 'intendedUse' (issue #8). This package fixes that by isolating the final camelCase segment, applying the operation only to that segment, and reassembling the result.
Installation
npm install pluralize-camelcaseUsage
The API mirrors pluralize directly:
const pluralize = require('pluralize-camelcase');
pluralize.singular('intendedUses') // 'intendedUse'
pluralize.plural('intendedUse') // 'intendedUses'
pluralize.isPlural('intendedUses') // true
pluralize.isSingular('intendedUse') // true
// count-based form
pluralize('intendedUse', 2) // 'intendedUses'
pluralize('intendedUse', 1) // 'intendedUse'
pluralize('intendedUse', 2, true) // '2 intendedUses'Works for any depth of camelCase nesting:
pluralize.singular('codeStatuses') // 'codeStatus'
pluralize.singular('dataTypes') // 'dataType'
pluralize.singular('UsesCases') // 'UsesCase'Roundtrip guarantee: plural(singular(x)) === x for any valid plural camelCase word.
Rule customization
Irregular rules and custom regex rules are passed through to the underlying pluralize library:
pluralize.addIrregularRule('person', 'people');
pluralize.addPluralRule(/quiz$/i, 'quizzes');
pluralize.addSingularRule(/quizzes$/i, 'quiz');
pluralize.addUncountableRule('sheep');How it works
lastCamelBoundary scans right-to-left for the last lowercase→uppercase transition in the word (e.g. intendedUses → index 8, the U in Uses). The prefix (intended) is kept verbatim and only the final segment (Uses) is handed off to pluralize, then the two parts are rejoined.
Words with no camelCase boundary (e.g. uses, statuses) are passed directly to pluralize unchanged.
