find-partial-anagrams
Version:
Takes a set of letters and returns all the words in a given word list that can be made using all or a subset of those letters.
36 lines (35 loc) • 1.7 kB
TypeScript
declare const wildcard = "?";
/** Represents a single uppercase letter. */
export type UpperCaseLetter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
/** Represents a single lowercase letter. */
export type LowerCaseLetter = Lowercase<UpperCaseLetter>;
/** Represents any single letter. */
export type Letter = LowerCaseLetter | UpperCaseLetter;
/** Represents a single letter or a wildcard character. */
export type Char = Letter | typeof wildcard;
/** Checks whether the passed value is a valid `Char`. */
export declare function isChar(input: unknown): input is Char;
/**
* Takes a set of letters and returns all the words in a given word list
* that can be made using all or a subset of those letters.
*
* @param input A string or array of characters that may appear in matches
* @param wordList An array of words to check for matches with your input
* @returns Items from `wordList` that are partial anagrams of your `input`
*/
export declare function findPartialAnagrams(input: string | Char[], wordList: string[]): string[];
/**
* Compresses a word list using incremental encoding.
*
* @param wordList An array of words to compress
* @returns An array of encoded words that can be passed to `decompressWordList`
*/
export declare function compressWordList(wordList: string[]): string[];
/**
* Decompresses a word list that uses incremental encoding.
*
* @param compressedWordList An array of encoded words from `compressWordList`
* @returns An array of decoded words
*/
export declare function decompressWordList(compressedWordList: string[]): string[];
export {};