@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
114 lines (113 loc) • 5.22 kB
TypeScript
import type { Aff, Flag, Flags } from "./index.js";
/** Base class for the {@link Prefix}/{@link Suffix} classes. Won't work by itself. */
export declare abstract class Affix {
/** The {@link Flag} that denotes the "name" for this affix. */
flag: Flag;
/**
* If true, this affix is allowed to have the opposite form of this
* affix, i.e. if a {@link Suffix} would be allowed to have a
* {@link Prefix}, and vice versa.
*/
crossproduct: boolean;
/**
* What is "stripped" from the stem when this affix is applied. e.g. this
* would be `"e"` for the suffix `"or"` (as in `create`, `creator`)
*/
strip: string;
/**
* What to add when this affix is applied. e.g. this would be `"or"` in
* the transformation needed for `create`, `creator`.
*/
add: string;
/** {@link Flags} this affix has been marked with. */
flags: Flags;
/**
* `RegExp` tested against a word to determine if this affix is relevant
* to said word. This doesn't check if the word *has* this affix, just if
* it *can* have this affix.
*/
conditionRegex: RegExp;
/** `RegExp` tested against a word to determine if said word has this affix. */
lookupRegex: RegExp;
/**
* `RegExp` tested against a word to match the specific section of said
* word that would need to be stripped to apply this affix.
*/
replaceRegex: RegExp;
/**
* @param flag - {@link Flag} that this affix will be labled with.
* @param crossproduct - Sets the {@link Affix.crossproduct} state, with
* the string "Y" meaning `true` and everything else meaning `false`.
* @param strip - What this affix should strip from a word to be applied.
* If given as the string "0", that means not to strip anything.
* @param add - What to add to a word when this affix is applied. If
* given as the string "0", that means to add nothing.
* @param aff - The {@link Aff} data to use when parsing flags.
*/
constructor(flag: Flag, crossproduct: string, strip: string, add: string, aff: Aff);
/**
* Determines if a word matches the conditions of this affix.
*
* @param word - The word to check against this affix's conditions.
*/
relevant(word: string): boolean;
/**
* Determines if a word already has this affix applied to it.
*
* @param word - The word to check for if this affix is already present.
*/
on(word: string): boolean;
/**
* Applies this affix to a word, returning the word as a transformed string.
*
* @param word - The word to apply the transformation to.
*/
apply(word: string): string;
/**
* Determines if this affix has the given flag.
*
* @param flag - The flag to check for. Can be undefined, which will return false.
*/
has(flag?: Flag): boolean;
/**
* Determines if this affix is compatible with a set of flags, meaning
* that the affix's flags are present in the flag set given.
*
* @param required - The flags this affix must have.
* @param forbidden - An optional set of flags which has the inverse
* effect, meaning that this affix's flags *cannot* be found in this set.
*/
compatible(required: Flags, forbidden?: Flags): boolean;
}
/** An {@link Affix} that is applied to or found at the beginning of a stem. */
export declare class Prefix extends Affix {
/**
* @param flag - {@link Flag} that this affix will be labled with.
* @param crossproduct - Sets the {@link Affix.crossproduct} state, with
* the string "Y" meaning `true` and everything else meaning `false`.
* @param strip - What this affix should strip from a word to be applied.
* If given as the string "0", that means not to strip anything.
* @param add - What to add to a word when this affix is applied. If
* given as the string "0", that means to add nothing.
* @param condition - A `RegExp` like pattern to check against a word to
* see if this affix is relevant.
* @param aff - The {@link Aff} data to use when parsing flags.
*/
constructor(flag: string, crossproduct: string, strip: string, add: string, condition: string, aff: Aff);
}
/** An {@link Affix} that is applied to or can be found at the end of a stem. */
export declare class Suffix extends Affix {
/**
* @param flag - {@link Flag} that this affix will be labled with.
* @param crossproduct - Sets the {@link Affix.crossproduct} state, with
* the string "Y" meaning `true` and everything else meaning `false`.
* @param strip - What this affix should strip from a word to be applied.
* If given as the string "0", that means not to strip anything.
* @param add - What to add to a word when this affix is applied. If
* given as the string "0", that means to add nothing.
* @param condition - A `RegExp` like pattern to check against a word to
* see if this affix is relevant.
* @param aff - The {@link Aff} data to use when parsing flags.
*/
constructor(flag: string, crossproduct: string, strip: string, add: string, condition: string, aff: Aff);
}