@tanishiking/aho-corasick
Version:
TypeScript implementation of the Aho-Corasick algorithm for efficient string matching
35 lines (34 loc) • 1.1 kB
TypeScript
import { TrieConfig, defaultConfig } from './trie-config';
import { Emit } from './emit';
/**
* Aho-Corasick implementation based on http://cr.yp.to/bib/1975/aho.pdf
* Port of
* robert-bor/aho-corasick https://github.com/robert-bor/aho-corasick and
* hankcs/aho-corasick https://github.com/hankcs/aho-corasick
*/
export declare class Trie {
private failureStateConstructed;
private readonly rootState;
private options;
constructor(keywords?: string[], options?: Partial<TrieConfig>);
addKeyword(keyword: string): void;
/**
* Find keywords from given text.
*
* @param text - The text to search for keywords.
*/
parseText(text: string): Emit[];
/**
* Jump to the next state, using both goto and failure.
*
* @param currentState - Current state.
* @param char - Accepted character.
* @returns Jumped state.
*/
private getState;
private checkForConstructedFailureStates;
private constructFailureStates;
private removePartialMatches;
private toEmits;
}
export { TrieConfig, defaultConfig, Emit };