@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
73 lines (72 loc) • 2.57 kB
TypeScript
/**
* A table for metaphone transformations. These transformations may provide
* superior suggestions because they describe similar sounding (as in
* spoken) syllables, which will be used by the suggestion engine to find
* words that may not be spelled similarly but *sound* similar.
*
* It roughly uses the following syntax:
*
* ```text
* PHONE <number of entries>
* PHONE <pattern> <replacement>
* ```
*
* `replacement` is a simple string, with the special value `_`
* (underscore) meaning an empty string. `pattern` is complex, and
* currently isn't very well documented. Additionally, both Spylls and
* Espells do not fully implement Hunspell's more intricate details, such
* as rule prioritizing and concepts like "follow-up rules".
*
* Dictionaries that use this feature are unfortunately quite rare.
*/
export declare class PhonetTable {
rules: Record<string, PhonetTableRule[]>;
constructor(table: [string, string][]);
/**
* Returns the metaphone representation of a word.
*
* @param word - The word to transform.
*/
metaphone(word: string): string;
}
/**
* An individual phonetic table rule.
*
* @see {@link PhonetTable}
*/
declare class PhonetTableRule {
/** The `RegExp` used for checking if this rule applies. */
search: RegExp;
/** The string to represent a matched phoneme with. */
replacement: string;
/** If true, this rule only applies at the start of a word. */
start: boolean;
/** If true, this rule only applies at the end of a word. */
end: boolean;
/** Currently unusued in both Spylls and Espells. */
followup: boolean;
/** Currently unusued in both Spylls and Espells. */
priority: number;
constructor(
/** The `RegExp` used for checking if this rule applies. */
search: RegExp,
/** The string to represent a matched phoneme with. */
replacement: string,
/** If true, this rule only applies at the start of a word. */
start?: boolean,
/** If true, this rule only applies at the end of a word. */
end?: boolean,
/** Currently unusued in both Spylls and Espells. */
followup?: boolean,
/** Currently unusued in both Spylls and Espells. */
priority?: number);
/**
* Checks if a rule is matched by this rule, and if it is, returns the
* `RegExpExecArray` match, otherwise returning false.
*
* @param word - The word to check.
* @param pos - The position in the word to check.
*/
match(word: string, pos: number): false | RegExpExecArray;
}
export {};