possessive-js
v0.2.2
Published
A small JavaScript library for formatting singular English possessive forms
Downloads
37
Maintainers
Readme
possessive-js
A small JavaScript library for formatting singular English possessive forms with predictable defaults and ESM-first package support.
Features
- Small public API
- ESM-first usage and package exports
- Singular possessive formatting for common English cases
- Configurable handling for words ending in
s - Special-case pronoun exceptions such as
it -> its - Case-preserving output for lowercase, uppercase, and title-case inputs
- Published TypeScript declarations
- Zero runtime dependencies
Installation
npm install possessive-jsRequires Node.js 18 or newer.
Usage
import Possessive from "possessive-js";
const possessive = new Possessive();
possessive.makePossessive("John"); // => "John's"
possessive.makePossessive("Chris"); // => "Chris'"
possessive.makePossessive("It"); // => "Its"
possessive.makePossessive("Strauss"); // => "Strauss'"
const alternative = new Possessive({ style: "alternative" });
alternative.makePossessive("Chris"); // => "Chris's"CommonJS compatibility:
const Possessive = require("possessive-js");
const possessive = new Possessive();
possessive.makePossessive("John"); // => "John's"API
Generated API reference: docs/API.md
new Possessive(options?)
const possessive = new Possessive({
style: "standard"
});Options:
style:"standard"or"alternative". Controls whether words ending insbecomeChris'orChris's.
makePossessive(noun)
Formats a singular noun or name into its possessive form.
Examples:
John -> John'sChris -> Chris'James -> James'Strauss -> Strauss'It -> ItsTHEY -> THEIR
Notes:
- Input is trimmed before formatting.
- Custom exceptions take precedence over the built-in suffix rules.
- Existing possessive strings are not specially detected or normalized.
- Mixed-case inputs are handled conservatively.
- The package is intentionally English-only.
Real-World Use Cases
- Generated UI labels:
${possessive.makePossessive(companyName)} settings - Profile and ownership pages:
${possessive.makePossessive(userName)} dashboard - CMS and publishing systems generating titles from author or organization names
- Emails, exports, and PDFs that need the same possessive formatting rules as the main app
addException(noun, possessiveForm)
Registers a custom exact-word exception before suffix rules are applied.
const possessive = new Possessive();
possessive.addException("boss", "bosses'");
possessive.makePossessive("boss"); // => "bosses'"
possessive.makePossessive("Boss"); // => "Bosses'"
possessive.makePossessive("BOSS"); // => "BOSSES'"Non-goals
- Plural possessives are out of scope.
- The library does not attempt full grammar or language detection.
- Non-English language support is out of scope.
- Mixed-case inputs are handled conservatively rather than with linguistic inference.
If your product localizes beyond English, use this package only for the English slice of that localization system.
Development
npm run format
npm run lint
npm run changelog
npm run docs
npm run verifydocs regenerates the API reference from JSDoc comments in src/index.js.
changelog generates draft release notes from Conventional Commit history. Review and edit the result manually before committing it.
verify runs linting, coverage, build, CJS/ESM smoke tests, API docs generation, and a package dry-run.
License
MIT © Sunan Regi Maunakea
