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.
- 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
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β
- verbalizer (default instance) β shared instance of
Verbalizer
. - Pluralizer β Similar class for noun pluralization.
Summaryβ
Use the Verbalizer
class for custom rules and isolated configurations.
Use the verbalizer
instance for quick, standard useβcases.