js-mdict
Version:
mdict (*.mdx, *.mdd) file reader. Licensed under AGPL-3.0 for better community cooperation and commercial value protection.
79 lines (78 loc) • 2.45 kB
TypeScript
import { Mdict } from './mdict.js';
import { KeyWordItem } from './mdict-base.js';
export interface FuzzyWord extends KeyWordItem {
recordStartOffset: number;
recordEndOffset: number;
keyText: string;
keyBlockIdx: number;
ed: number;
}
export declare class MDX extends Mdict {
/**
* lookup the word
* @tests ok
* @param word search word
* @returns word definition
*/
lookup(word: string): {
keyText: string;
definition: string | null;
};
/**
* lookup all entries matching the word
* useful when dictionary has duplicate keys (e.g., main entry + image + link)
* @param word search word
* @returns array of all matching entries
*/
lookupAll(word: string): Array<{
keyText: string;
definition: string | null;
}>;
fetch(keywordItem: KeyWordItem): {
keyText: string;
definition: string | null;
};
/**
* search the prefix like the phrase in the dictionary
* @tests ok
* @param prefix prefix search phrase
* @returns the prefix related list
*/
prefix(prefix: string): KeyWordItem[];
/**
* search matched list of associate words
* @tests ok
* @param phrase associate search likely workds
* @returns matched list
*/
associate(phrase: string): KeyWordItem[];
/**
* suggest the phrase with the edit distance
* @tests ok
* @param phrase search phrase
* @param distance edit distance
* @returns the suggest list
*/
suggest(phrase: string, distance: number): KeyWordItem[];
fetch_definition(keywordItem: KeyWordItem): {
keyText: string;
definition: string | null;
};
/**
* fuzzy search words list
* @tests ok
* @param word search word
* @param fuzzy_size the fuzzy workd size
* @param ed_gap edit distance
* @returns fuzzy word list
*/
fuzzy_search(word: string, fuzzy_size: number, ed_gap: number): FuzzyWord[];
/**
* search words that contain the specified substring
* @param substring the text to search for
* @param caseSensitive whether to perform case-sensitive search (default: false)
* @param limit maximum number of results to return (default: 1000)
* @returns list of keywords containing the substring
*/
contains(substring: string, caseSensitive?: boolean, limit?: number): KeyWordItem[];
}