@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
87 lines (86 loc) • 3.07 kB
TypeScript
import { CapType } from "../constants.js";
/**
* A class containing casing-related algorithms for a language. This is a
* class so that it may be extended by subclasses, e.g. German which has
* special handling of the "sharp S" character.
*/
export declare class Casing {
/**
* Guess a word's capitalization.
*
* @param word - The word to check.
*/
guess(word: string): CapType;
/**
* Lowercases a word. This returns an array of potential variations of
* lowercasing. This is done because certain languages (really, just
* German) have multiple ways of representing the same word in lowercase.
*
* @param word - The word to lowercase.
*/
lower(word: string): string[];
/**
* Uppercases a word.
*
* @param word - The word to uppercase.
*/
upper(word: string): string;
/**
* Titlecases a word.
*
* @param word - The word to titlecase.
*/
capitalize(word: string): string[];
/**
* Lowercases just the first letter of a word. Returns an array for the
* same reasons as {@link Casing.lower}.
*
* @param word - The word to lowercase the first letter of.
*/
lowerfirst(word: string): string[];
/**
* Returns a list of potential ways a word may have been cased in the
* dictionary, if we consider it to be spelled correctly but potentially
* *cased* incorrectly. The first item in the returned list will be the
* {@link CapType} of the given word.
*
* @param word - The word to return the variations of.
*/
variants(word: string): [CapType, ...string[]];
/**
* Returns a list of potential ways a word might have been cased if it
* seems to be a misspelling. The first item in the list will be the
* {@link CapType} of the given word.
*
* @param word - The word to return the corrections of.
*/
corrections(word: string): [CapType, ...string[]];
/**
* Used by the suggestion algorithm. If a misspelled word has been found
* in the dictionary, but is inconsistent with the casing of the word
* found in the dictionary, this method will be used to attempt to
* "coerce" the dictionary word to be cased like how the original misspelling was.
*
* @param word - The word to coerce.
* @param cap - The {@link CapType} to coerce the word to.
*/
coerce(word: string, cap: CapType): string;
}
/**
* A special subclass of {@link Casing} for Turkic languages, which have
* unique rules for lowercasing and uppercasing the characters `İ,I`, `i,ı`.
*/
export declare class TurkicCasing extends Casing {
private replaceMapping;
lower(word: string): string[];
upper(word: string): string;
}
/**
* A special subclass of {@link Casing} for German, which has a unique rule
* where `"SS"` can be lowercased as both `"ss"` *and* `“ß”`.
*/
export declare class GermanCasing extends Casing {
private sharpVariants;
lower(word: string): string[];
guess(word: string): CapType;
}