@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
54 lines (53 loc) • 1.8 kB
TypeScript
/**
* A table of conversions (either input to output, or output to input) for
* a word. Uses the following syntax:
*
* ```text
* # for input-output conversion
* ICONV <number of entries>
* ICONV <pattern> <replacement>
*
* # for output-input conversion
* OCONV <number of entries>
* OCONV <pattern> <replacement>
* ```
*
* Typically, a `pattern` and its `replacement` are just simple strings.
* This feature is usually used just for normalizing strings containing
* unusual typographics, like trigraphs and fancy apostrophes.
*
* `pattern` does have an unusual undocumented syntax feature: If the `_`
* underscore character is in the pattern, it may be transformed in one of
* three ways:
*
* - At the start of the `pattern`: Denotes a `RegExp` `^` anchor.
* - At the end of the `pattern`: Denotes a `RegExp` `$` anchor.
* - Everywhere else: Entirely ignored.
*
* Due to this undocumented feature, patterns are compiled to `RegExp`
* rather than left as simple strings.
*/
export declare class ConvTable {
/** The list of patterns and their replacements. */
table: {
pattern: RegExp;
replacement: string;
}[];
/**
* @param pairs - A list of string pair tuples that denotes a pattern and
* its replacement.
*/
constructor(pairs: [string, string][]);
/**
* Applies this table's rules against a word and returns the resulting
* string. Uses the following algorithm, to prevent recursion:
*
* - For each position in the word:
* - ...find any matching rules
* - ...choose the one that has the longest pattern
* - ...apply its replacement, and shift the current position past the replacement
*
* @param word - The word to transform.
*/
match(word: string): string;
}