active-inflector

raw JSON →
0.1.0 verified Fri May 01 auth: no javascript

Active Inflector is a JavaScript/TypeScript library for pluralizing and singularizing words, aiming for full compatibility with Ruby on Rails' ActiveSupport::Inflector. Version 0.1.0 is the latest stable release, with infrequent updates. It provides both default export of an Inflector class with static methods and convenient standalone singularize/pluralize functions. Key differentiators: Rails-compatible custom rules (irregular, uncountable, uncountable), supports numeric pluralization (e.g., pluralize(2, 'taco') → '2 tacos'), and ships TypeScript types. Requires ESM and environment support for JS private fields.

error ERR_REQUIRE_ESM
cause Trying to require() an ESM-only package.
fix
Use import { Inflector } from 'active-inflector' or dynamic import().
error TypeError: Inflector.inflector is undefined
cause Using default import instead of named import Inflector class.
fix
Ensure import is correct: import { Inflector } from 'active-inflector'. The Inflector class is exported as a named export, not default.
error SyntaxError: Unexpected private field
cause Environment does not support JavaScript private class fields (# syntax).
fix
Use a transpiler like Babel with @babel/plugin-proposal-private-methods or target a newer runtime (Node >=12, modern browsers).
breaking Package is ESM-only. CJS require() causes runtime error 'ERR_REQUIRE_ESM'.
fix Use dynamic import() or switch to ESM in your project.
gotcha Inflector.inflector.singularize() vs singularize() directly: both work, but the static method via Inflector.inflector is the only way to access custom rules after they are set.
fix Use Inflector.inflector.singularize() when you need custom rules to apply, otherwise standalone singularize() is fine.
gotcha Numeric pluralize overload expects count as first argument. Passing a string number will not work correctly.
fix Ensure the first argument is a number, not a string. E.g., pluralize(2, 'taco') not pluralize('2', 'taco').
breaking Requires JavaScript environment that supports private class fields (e.g., Node.js 12+, modern browsers). Running in older environments may throw SyntaxError.
fix Transpile with Babel/TypeScript targeting older environments, or use a polyfill for private fields.
deprecated Package is very early (v0.1.0); API may change without major version bump.
fix Pin to exact version and monitor releases.
npm install active-inflector
yarn add active-inflector
pnpm add active-inflector

Demonstrates basic singularize/pluralize, numeric pluralization, and custom irregular/uncountable rules.

import { Inflector, singularize, pluralize } from 'active-inflector';

// Basic singularization/pluralization
console.log(singularize('tacos')); // 'taco'
console.log(pluralize('taco')); // 'tacos'

// Numeric pluralization
console.log(pluralize(2, 'taco')); // '2 tacos'
console.log(pluralize(2, 'tacos', { withoutCount: true })); // 'tacos'

// Custom irregular and uncountable rules
Inflector.inflector.irregular('person', 'people');
Inflector.inflector.uncountable('sheep');
console.log(pluralize('person')); // 'people'
console.log(pluralize('sheep')); // 'sheep'