UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

130 lines (129 loc) 4.94 kB
/** * @class Handles English verb conjugation between base, past tense, and past participle forms. * * - Provides methods to convert verbs between base, past, and past participle forms, check verb forms, and manage custom conjugation rules. * - Supports adding custom conjugation rules and irregular verbs. * - Automatically handles common irregular verbs like "go" to "went" (past) and "gone" (past participle). * - Automatically loads common irregular verbs and conjugation rules. * - Preserves case sensitivity of input verbs. * - This class is useful for natural language processing tasks, such as chatbots, text analysis, or content generation systems requiring accurate verb conjugation. * * @remarks * For ready to use instance, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/verbalizer verbalizer} instead. * * @example * const myVerbalizer = new Verbalizer(); * myVerbalizer.toPast('run'); // "ran" * myVerbalizer.toParticiple('go'); // "gone" * myVerbalizer.toBase('went'); // "go" */ export declare class Verbalizer { #private; /** * Initializes `Verbalizer` with default rules and irregular verbs. * Automatically loads irregular verbs and conjugation rules for base, past and past participle forms. */ constructor(); /** * * Add a new base tense conjugation rule. * @param rule Pattern to match past/participle form of verbs. * @param replacement Replacement pattern for base tense form. * @example * verbalizer.addBaseRule(/ied$/i, 'y'); */ addBaseRule(rule: RegExp, replacement: string): void; /** * * Add a new past tense conjugation rule. * @param rule Pattern to match base verbs. * @param replacement Replacement pattern for past tense form. * @example * verbalizer.addPastRule(/e$/i, 'ed'); */ addPastRule(rule: RegExp, replacement: string): void; /** * * Add a new past participle conjugation rule. * @param rule Pattern to match base verbs. * @param replacement Replacement pattern for past participle form. * @example * verbalizer.addParticipleRule(/e$/i, 'ed'); */ addParticipleRule(rule: RegExp, replacement: string): void; /** * * Add a custom irregular verb. * @param base Base form of the verb. * @param past Past tense form. * @param participle Past participle form. * @example * verbalizer.addIrregular('swim', 'swam', 'swum'); */ addIrregular(base: string, past: string, participle: string): void; /** * * Convert a verb to its past tense form. * @param verb Base form of the verb. * @returns Past tense form of the verb. * @example * verbalizer.toPast('walk'); // "walked" * verbalizer.toPast('run'); // "ran" */ toPast(verb: string): string; /** * * Convert a verb to its past participle form. * @param verb Base form of the verb. * @returns Past participle form of the verb. * @example * verbalizer.toParticiple('walk'); // "walked" * verbalizer.toParticiple('go'); // "gone" */ toParticiple(verb: string): string; /** * * Convert a verb to its base form. * @param verb Past or past participle form of the verb. * @returns Base form of the verb. * @example * verbalizer.toBase('went'); // "go" * verbalizer.toBase('walked'); // "walk" */ toBase(verb: string): string; /** * * Check if a given verb is in its past tense form. * @param verb Verb to check. * @returns True if the verb is in past tense, otherwise false. * @example * verbalizer.isPast('ran'); // true * verbalizer.isPast('run'); // false */ isPast(verb: string): boolean; /** * * Check if a given verb is in its past participle form. * @param verb Verb to check. * @returns True if the verb is in past participle form, otherwise false. * @example * verbalizer.isParticiple('gone'); // true * verbalizer.isParticiple('go'); // false */ isParticiple(verb: string): boolean; /** * * Check if a given verb is in its base form. * @param verb Verb to check. * @returns True if the verb is in base form, otherwise false. * @example * verbalizer.isBase('run'); // true * verbalizer.isBase('ran'); // false */ isBase(verb: string): boolean; } /** * Default shared instance of {@link https://toolbox.nazmul-nhb.dev/docs/classes/Verbalizer Verbalizer}. * * - Use this when you don’t need multiple configurations. * - It comes preloaded with standard conjugation rules and irregular verbs. * - * * @example * import { verbalizer } from 'nhb-toolbox'; * * verbalizer.toPast('run'); // "ran" * verbalizer.toParticiple('go'); // "gone" * verbalizer.toBase('went'); // "go" */ export declare const verbalizer: Verbalizer;