Skip to main content

Verbalizer - Manage Verb Forms

Verbalizer​

The Verbalizer class provides a low‑level API to handle English verb conjugation between base, past tense, and past participle forms.
It supports irregular verbs, regular conjugation rules, and allows you to extend or customize the behavior by adding new rules.

When to Use
  • You need multiple independent configurations.
  • You want to add or override rules without affecting the shared verbalizer instance.

✨ Features​

  • βœ… Convert verbs between base, past tense, and past participle forms
  • βœ… Built‑in default rules loaded on construction
  • βœ… Manage rules dynamically:
    • addBaseRule()
    • addPastRule()
    • addParticipleRule()
    • addIrregular()
  • βœ… Automatically handles irregular verbs (e.g. go β†’ went β†’ gone)
  • βœ… Preserves case sensitivity of input verbs
Alert

All methods return the trimmed verb if the input has trailing spaces.


πŸ“¦ Import​

import { Verbalizer } from 'nhb-toolbox';

πŸš€ Usage​

const myVerbalizer = new Verbalizer();

myVerbalizer.toPast('run'); // "ran"
myVerbalizer.toParticiple('go'); // "gone"
myVerbalizer.toBase('went'); // "go"
myVerbalizer.isPast('ran'); // true

πŸ”§ Extending Rules​

You can modify your instance without affecting others:

// Add a custom base rule
myVerbalizer.addBaseRule(/ied$/i, 'y');

// Add a custom past tense rule
myVerbalizer.addPastRule(/e$/i, 'ed');

// Add a custom past participle rule
myVerbalizer.addParticipleRule(/e$/i, 'ed');

// Add an irregular verb
myVerbalizer.addIrregular('swim', 'swam', 'swum');

πŸ› οΈ API Overview​

constructor()​

Initializes with built‑in rules and irregular verbs.


toPast(verb)​

Convert a verb to its past tense form.

myVerbalizer.toPast('walk'); // "walked"
myVerbalizer.toPast('run'); // "ran"

toParticiple(verb)​

Convert a verb to its past participle form.

myVerbalizer.toParticiple('walk'); // "walked"
myVerbalizer.toParticiple('go'); // "gone"

toBase(verb)​

Convert a verb to its base form.

myVerbalizer.toBase('went'); // "go"
myVerbalizer.toBase('walked'); // "walk"

isPast(verb)​

Check if a verb is in past tense form.

myVerbalizer.isPast('ran'); // true
myVerbalizer.isPast('run'); // false

isPastParticiple(verb)​

Check if a verb is in past participle form.

myVerbalizer.isPastParticiple('gone'); // true
myVerbalizer.isPastParticiple('go'); // false

isBase(verb)​

Check if a verb is in base form.

myVerbalizer.isBase('run'); // true
myVerbalizer.isBase('ran'); // false

addBaseRule(rule, replacement)​

Add a new base tense conjugation rule.

myVerbalizer.addBaseRule(/ied$/i, 'y');

addPastRule(rule, replacement)​

Add a new past tense conjugation rule.

myVerbalizer.addPastRule(/e$/i, 'ed');

addParticipleRule(rule, replacement)​

Add a new past participle conjugation rule.

myVerbalizer.addParticipleRule(/e$/i, 'ed');

addIrregular(base, past, participle)​

Add an irregular verb.

myVerbalizer.addIrregular('swim', 'swam', 'swum');

See also​


Summary​

Use the Verbalizer class for custom rules and isolated configurations.
Use the verbalizer instance for quick, standard use‑cases.