import { SensitiveWord, DetectionResult, FilterOptions, WhitelistEntry, BatchDetectionResult, WordListExport } from './types'; /** * Main filter class for detecting sensitive words */ export declare class SensitiveWordFilter { private trie; private customWords; private allWords; private defaultOptions; private fuzzyMatcher; private whitelist; private whitelistEntries; constructor(options?: FilterOptions); /** * Build the whitelist set from entries */ private buildWhitelistSet; /** * Load default words from database */ private loadDefaultWords; /** * Rebuild the trie with current words and options */ private rebuildTrie; /** * Add a custom sensitive word */ addWord(word: SensitiveWord): void; /** * Add multiple custom words */ addWords(words: SensitiveWord[]): void; /** * Remove a custom word */ removeWord(word: string): void; /** * Clear all custom words */ clearCustomWords(): void; /** * Get all custom words */ getCustomWords(): SensitiveWord[]; /** * Update filter options */ setOptions(options: Partial): void; /** * Add a word to the whitelist * @param word - Word or entry to whitelist */ addToWhitelist(word: string | WhitelistEntry): void; /** * Add multiple words to the whitelist * @param words - Words or entries to whitelist */ addManyToWhitelist(words: (string | WhitelistEntry)[]): void; /** * Remove a word from the whitelist * @param word - Word to remove */ removeFromWhitelist(word: string): void; /** * Clear the entire whitelist */ clearWhitelist(): void; /** * Get all whitelisted words * @returns Array of whitelist entries */ getWhitelist(): WhitelistEntry[]; /** * Check if a word is whitelisted * @param word - Word to check * @returns True if the word is whitelisted */ isWhitelisted(word: string): boolean; /** * Get current options */ getOptions(): FilterOptions; /** * Escape special regex characters in a string * @param str - String to escape * @returns Escaped string safe for use in RegExp */ private escapeRegex; /** * Check if a matched word is actually a standalone word in the text * or if it only appears as part of other words * @param text - The original text * @param matchWord - The matched word to check * @returns True if the word exists standalone (not just as part of another word) */ private existsAsStandaloneWord; /** * Check if the matched word only appears inside safe context words * @param text - The original text * @param matchWord - The matched word to check * @returns True if match only appears in safe words (false positive) */ private isOnlyInSafeContext; /** * Check if a match should be filtered out based on context * @param text - Original text * @param match - The match to check * @param contextAware - Whether to use context-aware detection * @returns True if the match should be kept, false if it's a false positive */ private shouldKeepMatch; /** * Detect sensitive words in text */ detect(text: string, options?: Partial): DetectionResult; /** * Check if text contains sensitive words */ hasMatch(text: string, options?: Partial): boolean; /** * Clean text by replacing sensitive words */ clean(text: string, options?: Partial): string; /** * Perform fuzzy matching against all words */ private fuzzyMatchWords; /** * Replace matches in text */ private replaceMatches; /** * Get statistics about the word database */ getStats(): { totalWords: number; customWords: number; defaultWords: number; whitelistCount: number; byLanguage: { en: number; ar: number; }; bySeverity: { [key: number]: number; }; byCategory: { [key: string]: number; }; }; /** * Detect sensitive words in multiple texts at once * More efficient than calling detect() multiple times * * @param texts - Array of texts to check * @param options - Optional filter options * @returns Batch detection result with all results and timing */ detectBatch(texts: string[], options?: Partial): BatchDetectionResult; /** * Check if any of the texts contain sensitive words * Stops at first match for efficiency * * @param texts - Array of texts to check * @param options - Optional filter options * @returns True if any text contains sensitive words */ hasMatchInAny(texts: string[], options?: Partial): boolean; /** * Clean multiple texts at once * * @param texts - Array of texts to clean * @param options - Optional filter options * @returns Array of cleaned texts */ cleanBatch(texts: string[], options?: Partial): string[]; /** * Async version of detect for non-blocking processing * Useful for processing large texts in web workers or server environments * * @param text - Text to check * @param options - Optional filter options * @returns Promise with detection result */ detectAsync(text: string, options?: Partial): Promise; /** * Async batch detection with chunked processing * Prevents blocking the event loop for large batches * * @param texts - Array of texts to check * @param options - Optional filter options * @param chunkSize - Number of texts to process per chunk (default: 100) * @returns Promise with batch detection result */ detectBatchAsync(texts: string[], options?: Partial, chunkSize?: number): Promise; /** * Export custom words to a portable format * * @returns Exportable word list object */ exportCustomWords(): WordListExport; /** * Import words from an exported word list * * @param wordList - Word list to import * @param replace - If true, replaces existing custom words; if false, merges */ importWords(wordList: WordListExport, replace?: boolean): void; /** * Export custom words as JSON string * * @returns JSON string of custom words */ exportToJSON(): string; /** * Import words from JSON string * * @param json - JSON string to import * @param replace - If true, replaces existing custom words */ importFromJSON(json: string, replace?: boolean): void; /** * Export whitelist to portable format * * @returns Array of whitelist entries */ exportWhitelist(): WhitelistEntry[]; /** * Import whitelist entries * * @param entries - Whitelist entries to import * @param replace - If true, replaces existing whitelist */ importWhitelist(entries: WhitelistEntry[], replace?: boolean): void; } //# sourceMappingURL=filter.d.ts.map