UNPKG

allprofanity

Version:

A blazing-fast, multi-language profanity filter with advanced algorithms (Aho-Corasick, Bloom Filters) delivering 664% faster performance on large texts, intelligent leet-speak detection, and pattern-based context analysis

76 lines (75 loc) 1.74 kB
/** * Aho-Corasick algorithm implementation for efficient multi-pattern string matching */ export interface Match { pattern: string; start: number; end: number; patternIndex: number; } export declare class AhoCorasick { private root; private patterns; private compiled; constructor(patterns?: string[]); /** * Create a new trie node */ private createNode; /** * Add patterns to the automaton */ addPatterns(patterns: string[]): void; /** * Add a single pattern to the automaton */ addPattern(pattern: string): void; /** * Build the Aho-Corasick automaton */ private buildAutomaton; /** * Build the trie structure */ private buildTrie; /** * Build failure links using BFS */ private buildFailureLinks; /** * Build output links for failure transitions */ private buildOutputLinks; /** * Find all pattern matches in the given text */ findAll(text: string): Match[]; /** * Check if text contains any patterns */ hasMatch(text: string): boolean; /** * Find first match in text */ findFirst(text: string): Match | null; /** * Get the patterns stored in this automaton */ getPatterns(): string[]; /** * Clear all patterns and reset the automaton */ clear(): void; /** * Get statistics about the automaton */ getStats(): { patternCount: number; nodeCount: number; averagePatternLength: number; }; /** * Count total nodes in the trie */ private countNodes; }