import { d as DetectionResult, c as DetectionMatch, S as SeverityLevel, P as ProfanityCategory, L as LanguageCode, e as DetectorConfig, A as AnalysisOptions, F as FilterMode, C as CustomWord, f as LanguageDetection, E as EnhancedDetectionMatch$1, h as StaticLanguageData } from './index-DQqlnMYl.cjs'; export { D as DatabaseStats, a as DetectionError, b as DetectionErrorType, g as LanguageMetadata, W as WordEntry } from './index-DQqlnMYl.cjs'; /** * Comprehensive detection result system with detailed analysis and metadata */ /** * Performance metrics for detection operation */ interface PerformanceMetrics { /** Total processing time in milliseconds */ totalTime: number; /** Time spent on language detection */ languageDetectionTime: number; /** Time spent on text normalization */ normalizationTime: number; /** Time spent on pattern matching */ matchingTime: number; /** Time spent on context analysis */ contextAnalysisTime: number; /** Time spent on filtering */ filteringTime: number; /** Number of characters processed */ charactersProcessed: number; /** Processing rate in characters per millisecond */ processingRate: number; } /** * Statistical analysis of detection results */ interface DetectionStatistics { /** Total words in the text */ totalWords: number; /** Total unique words detected */ uniqueProfaneWords: number; /** Percentage of text that is profane */ profanityDensity: number; /** Distribution by severity level */ severityDistribution: Record; /** Distribution by category */ categoryDistribution: Record; /** Distribution by language */ languageDistribution: Record; /** Average confidence score */ averageConfidence: number; /** Confidence score distribution */ confidenceDistribution: { high: number; medium: number; low: number; }; } /** * Context information about the analyzed text */ interface TextContext { /** Detected text type (social media, formal, email, etc.) */ textType: 'unknown' | 'social_media' | 'formal' | 'email' | 'chat' | 'article' | 'comment'; /** Estimated reading level */ readingLevel: 'elementary' | 'middle' | 'high_school' | 'college' | 'graduate'; /** Emotional tone indicators */ emotionalTone: { aggressive: number; neutral: number; positive: number; negative: number; }; /** Presence of special patterns */ patterns: { hasUrls: boolean; hasEmails: boolean; hasMentions: boolean; hasHashtags: boolean; hasEmojis: boolean; hasRepeatedChars: boolean; hasAllCaps: boolean; }; } /** * Detailed position information for matches */ interface MatchPosition { /** Absolute character position in text */ absoluteStart: number; absoluteEnd: number; /** Line number (1-based) */ lineNumber: number; /** Column position in line (1-based) */ columnStart: number; columnEnd: number; /** Word index in text */ wordIndex: number; /** Sentence index */ sentenceIndex: number; } /** * Enhanced detection match with additional metadata */ interface EnhancedDetectionMatch extends DetectionMatch { /** Detailed position information */ position: MatchPosition; /** Context around the match */ context: { before: string; after: string; sentence: string; }; /** Alternative suggestions for replacement */ suggestions: string[]; /** Reason for detection */ detectionReason: string; /** Whether this is a fuzzy match */ isFuzzyMatch: boolean; /** Edit distance for fuzzy matches */ editDistance?: number; /** Original match score before confidence adjustments */ rawScore: number; } /** * Enhanced detection result with comprehensive analysis */ interface EnhancedDetectionResult extends DetectionResult { /** Enhanced matches with additional metadata */ enhancedMatches: EnhancedDetectionMatch[]; /** Performance metrics */ performance: PerformanceMetrics; /** Statistical analysis */ statistics: DetectionStatistics; /** Text context information */ textContext: TextContext; /** Warnings about potential issues */ warnings: string[]; /** Recommendations for improvement */ recommendations: string[]; /** Detection metadata */ metadata: { version: string; algorithm: string; configHash: string; timestamp: Date; }; } /** * Builder for creating detection results with comprehensive analysis */ declare class DetectionResultBuilder { private result; private startTime; private performanceMarkers; constructor(originalText?: string); /** * Mark a performance checkpoint */ markPerformance(label: string): void; /** * Set detected languages */ setLanguages(languages: LanguageCode[]): this; /** * Add detection matches */ addMatches(matches: DetectionMatch[]): this; /** * Set filtered text */ setFilteredText(filteredText: string): this; /** * Set overall confidence */ setConfidence(confidence: number): this; /** * Add a warning */ addWarning(warning: string): this; /** * Add a recommendation */ addRecommendation(recommendation: string): this; /** * Set configuration hash for caching */ setConfigHash(hash: string): this; /** * Build the final result */ build(): EnhancedDetectionResult; /** * Enhance a basic match with additional metadata */ private enhanceMatch; /** * Calculate detailed position information */ private calculatePosition; /** * Extract context around a match */ private extractContext; /** * Generate replacement suggestions */ private generateSuggestions; /** * Get reason for detection */ private getDetectionReason; /** * Calculate edit distance between two strings */ private calculateEditDistance; /** * Update statistics based on matches */ private updateStatistics; /** * Calculate performance metrics */ private calculatePerformanceMetrics; /** * Analyze text context */ private analyzeTextContext; /** * Generate recommendations based on analysis */ private generateRecommendations; /** * Count words in text */ private countWords; } /** * Main profanity detection class with comprehensive analysis capabilities */ declare class ContentShieldDetector { private config; private matcher; private filterEngine; private languageDetector; private isInitialized; private configHash; constructor(config?: Partial); /** * Initialize the detector with language data */ initialize(_dataPath?: string): Promise; /** * Analyze text for profanity with comprehensive results */ analyze(text: string, options?: Partial): Promise; /** * Enhanced analysis with detailed metrics and context */ analyzeEnhanced(text: string, options?: Partial): Promise; /** * Check if text contains multiple Unicode scripts */ private hasMultipleScripts; /** * Quick check if text contains profanity */ isProfane(text: string): Promise; /** * Filter profanity from text */ filter(text: string, mode?: FilterMode): Promise; /** * Batch analyze multiple texts (basic implementation) * Note: Enhanced batch analysis is available via performance optimizations */ batchAnalyzeBasic(texts: string[], options?: Partial): Promise; /** * Get detection statistics */ getStats(): { isInitialized: boolean; configHash: string; matcherStats: { totalLanguages: number; totalWords: number; trieStats: Record; }; filterStats: { customReplacements: number; categoryReplacements: number; currentMode: FilterMode; preserveStructure: boolean; }; supportedLanguages: LanguageCode[]; }; /** * Add custom words to the detector */ addCustomWords(customWords: CustomWord[]): void; /** * Update detector configuration */ updateConfig(config: Partial): void; /** * Get current configuration */ getConfig(): DetectorConfig; /** * Reset detector (clear cache and reinitialize) */ reset(): Promise; /** * Export detector configuration for serialization */ exportConfig(): object; /** * Import detector configuration */ importConfig(exportedConfig: { config?: DetectorConfig; }): void; /** * Ensure detector is initialized */ private ensureInitialized; /** * Create matcher configuration from detector config */ private createMatcherConfig; /** * Create filter configuration from detector config */ private createFilterConfig; /** * Calculate overall confidence based on matches */ private calculateOverallConfidence; /** * Add warnings and recommendations to the result builder */ private addWarningsAndRecommendations; /** * Merge analysis options with defaults */ private mergeAnalysisOptions; /** * Generate configuration hash for caching */ private generateConfigHash; /** * Merge configuration with defaults */ private mergeWithDefaults; /** * PERFORMANCE OPTIMIZATIONS */ private analysisCache; private readonly MAX_ANALYSIS_CACHE_SIZE; private analysisCacheHits; private analysisCacheMisses; /** * Cached analysis with intelligent cache management */ analyzeCached(text: string, options?: Partial): Promise; /** * Batch analysis for multiple texts - significantly more efficient */ batchAnalyze(texts: string[], options?: Partial): Promise; /** * Memory-efficient streaming analysis for large datasets */ batchAnalyzeStream(texts: Iterable, options?: Partial): AsyncGenerator; /** * Worker thread support for large text processing * * NOTE: This is currently optimized for single-threaded performance. * With our fuzzy search optimizations, single-threaded analysis is already * very fast (<20ms for 10k words). Chunking adds overhead without actual * worker threads, so we use the optimized single-threaded path. * * True worker thread parallelization would require: * 1. Serialization/deserialization of language data * 2. Worker thread pool management * 3. Inter-process communication overhead * * For most use cases, the current single-threaded performance is sufficient. */ analyzeWithWorkers(text: string, options?: Partial): Promise; /** * Lazy initialization of language data for memory efficiency */ private lazyLoadedLanguages; ensureLanguageLoaded(language: LanguageCode, _dataPath?: string): Promise; /** * Generate cache key for analysis */ private generateAnalysisCacheKey; /** * Get performance statistics */ getPerformanceStats(): { analysisCacheHits: number; analysisCacheMisses: number; analysisCacheHitRate: number; analysisCacheSize: number; lazyLoadedLanguages: number; }; /** * Clear all caches and reset performance counters */ clearCaches(): void; /** * Memory optimization - force garbage collection */ optimizeMemory(): void; /** * Warm up caches with common patterns */ warmUpCaches(commonTexts: string[]): Promise; } /** * Language detection for profanity filtering * Enhanced with advanced language detection capabilities */ declare class LanguageDetector { private engine; constructor(options?: { cacheEnabled?: boolean; minTextLength?: number; maxSampleLength?: number; }); /** * Detect the language of the given text */ detect(text: string): Promise; /** * Get the most likely language from detection results */ getPrimaryLanguage(detections: LanguageDetection[]): LanguageCode; /** * Detect language synchronously for performance-critical operations */ detectSync(text: string): LanguageDetection[]; /** * Get the primary language synchronously */ getPrimaryLanguageSync(text: string): LanguageCode; /** * Check if text contains mixed languages */ hasMixedLanguages(text: string, threshold?: number): boolean; /** * Get confidence for a specific language */ getLanguageConfidence(text: string, language: LanguageCode): number; /** * Clear the detection cache */ clearCache(): void; /** * Get cache statistics */ getCacheStats(): { size: number; maxSize: number; }; } /** * Advanced filtering engine with multiple modes and structure preservation * Supports censoring, removal, replacement, and custom filtering strategies */ /** * Configuration for filtering operations */ interface FilterConfig { /** Filtering mode to apply */ mode: FilterMode; /** Character to use for censoring */ replacementChar: string; /** Whether to preserve word structure when censoring */ preserveStructure: boolean; /** Custom replacement words/phrases */ customReplacements: Map; /** Whether to preserve sentence structure */ preserveSentenceStructure: boolean; /** Whether to maintain original text length */ maintainLength: boolean; /** Minimum confidence threshold for filtering */ confidenceThreshold: number; /** Whether to apply gradual filtering based on severity */ gradualFiltering: boolean; /** Replacement patterns for different categories */ categoryReplacements: Map; } /** * Result of a filtering operation */ interface FilterResult { /** The filtered text */ filteredText: string; /** Number of words that were filtered */ filteredCount: number; /** Details about what was filtered */ filterDetails: FilterDetail[]; /** Whether the text structure was preserved */ structurePreserved: boolean; /** Original text length vs filtered text length */ lengthComparison: { original: number; filtered: number; difference: number; }; } /** * Details about a specific filter operation */ interface FilterDetail { /** Original word that was filtered */ originalWord: string; /** What it was replaced with */ replacement: string; /** Position in the text */ position: { start: number; end: number; }; /** Why it was filtered */ reason: string; /** Confidence of the match */ confidence: number; /** Filter method used */ method: 'censor' | 'remove' | 'replace' | 'custom'; } /** * Advanced text filtering engine */ declare class ProfanityFilter { private config; constructor(config?: Partial); /** * Legacy method for backward compatibility */ applyFilter(text: string, matches: DetectionMatch[], mode: FilterMode, replacementChar?: string, preserveStructure?: boolean): string; /** * Filter text based on detected matches */ filter(text: string, matches: DetectionMatch[] | EnhancedDetectionMatch$1[], customConfig?: Partial): FilterResult; /** * Normalize match positions - find actual word position in text if positions are wrong */ private normalizeMatch; /** * Filter a single match from text */ private filterSingleMatch; /** * Generate censoring replacement */ private generateCensorReplacement; /** * Generate removal replacement */ private generateRemovalReplacement; /** * Generate replacement word/phrase */ private generateReplaceReplacement; /** * Apply gradual filtering based on severity and confidence */ private applyGradualFiltering; /** * Partially censor a word */ private partialCensor; /** * Get custom replacement for a word */ private getCustomReplacement; /** * Select replacement based on severity level for deterministic results */ private selectReplacementBySeverity; /** * Preserve sentence structure after filtering */ private preserveSentenceStructure; /** * Create empty result for no matches */ private createEmptyResult; /** * Batch filter multiple texts */ batchFilter(texts: string[], matchesArray: DetectionMatch[][], config?: Partial): FilterResult[]; /** * Create a safe version of text with intelligent filtering */ makeSafe(text: string, matches: DetectionMatch[], safetyLevel?: 'strict' | 'moderate' | 'lenient'): FilterResult; /** * Update filter configuration */ updateConfig(config: Partial): void; /** * Get current configuration */ getConfig(): FilterConfig; /** * Add custom replacement rule */ addCustomReplacement(word: string, replacement: string): void; /** * Remove custom replacement rule */ removeCustomReplacement(word: string): boolean; /** * Add category replacement options */ addCategoryReplacements(category: string, replacements: string[]): void; /** * Get filter statistics */ getStats(): { customReplacements: number; categoryReplacements: number; currentMode: FilterMode; preserveStructure: boolean; }; /** * Merge configuration with defaults */ private mergeWithDefaults; } /** * Serialized trie node structure for import/export */ interface SerializedTrieNode { isEndOfWord: boolean; children: Record; data?: TrieNodeData; } /** * Serialized trie structure for import/export */ interface SerializedTrie { root: SerializedTrieNode; totalWords: number; version: string; } /** * Data stored at each terminal node (word end) */ interface TrieNodeData { /** Original word as stored */ word: string; /** Severity level of the word */ severity: SeverityLevel; /** Categories this word belongs to */ categories: ProfanityCategory[]; /** Language this word is from */ language: string; /** Whether this word is case-sensitive */ caseSensitive?: boolean; /** Confidence score for this match */ confidence?: number; } /** * Single node in the Trie structure with performance optimizations */ declare class TrieNode { children: Map; isEndOfWord: boolean; data: TrieNodeData | null; failureLink: TrieNode | null; outputLink: TrieNode | null; accessCount: number; lastAccessTime: number; constructor(); /** * Check if this node has any children */ hasChildren(): boolean; /** * Get child node for a character */ getChild(char: string): TrieNode | undefined; /** * Add or get child node for a character */ addChild(char: string): TrieNode; } /** * Match result from Trie search */ interface TrieMatch { /** The matched word */ word: string; /** Start position in the search text */ start: number; /** End position in the search text */ end: number; /** Data associated with this match */ data: TrieNodeData; /** Edit distance (for fuzzy matches) */ editDistance?: number; } /** * Efficient Trie implementation for fast profanity detection * Features: * - O(m) insertion and search where m is word length * - Fuzzy matching with configurable edit distance * - Memory-optimized storage * - Support for word variations and patterns * - Aho-Corasick algorithm for multi-pattern matching */ declare class ProfanityTrie { root: TrieNode; private totalWords; private compiled; constructor(); /** * Insert a word into the Trie with associated data */ insert(word: string, data: TrieNodeData): void; /** * Insert multiple words with their variations */ insertWithVariations(baseWord: string, variations: readonly string[], data: TrieNodeData): void; /** * Search for exact matches in text */ search(text: string, caseSensitive?: boolean): TrieMatch[]; /** * Search for matches starting from a specific position */ private searchFromPosition; /** * Fuzzy search with edit distance tolerance - OPTIMIZED * Uses iterative approach with early termination and pruning */ fuzzySearch(text: string, maxEditDistance?: number, caseSensitive?: boolean): TrieMatch[]; /** * Optimized fuzzy search using iterative approach with pruning */ private fuzzySearchFromPositionOptimized; /** * Specialized fuzzy search for short texts (more accurate) */ private fuzzySearchShortText; /** * Legacy fuzzy search DFS - kept for compatibility but deprecated * Use fuzzySearchFromPositionOptimized instead */ private _fuzzySearchDFS; /** * Check if position represents a word boundary */ private isWordBoundary; /** * Remove duplicate matches and sort by quality */ private deduplicateMatches; /** * Compile the Trie for optimized searching (Aho-Corasick) * This creates failure links for efficient multi-pattern matching */ compile(): void; /** * Build failure links for Aho-Corasick algorithm */ private buildFailureLinks; /** * Multi-pattern search using Aho-Corasick algorithm * More efficient than multiple single searches */ multiPatternSearch(text: string, caseSensitive?: boolean, maxMatches?: number): TrieMatch[]; /** * Get statistics about the Trie */ getStats(): { totalWords: number; totalNodes: number; averageDepth: number; maxDepth: number; memoryUsage: number; }; /** * Clear the entire Trie */ clear(): void; /** * Export Trie to a serializable format */ export(): SerializedTrie; /** * Import Trie from serialized format */ import(data: SerializedTrie): void; /** * PERFORMANCE OPTIMIZATIONS */ private searchCache; private readonly MAX_CACHE_SIZE; private cacheHits; private cacheMisses; /** * Cached search with intelligent cache management */ cachedSearch(text: string, caseSensitive?: boolean): TrieMatch[]; /** * Batch processing for multiple texts - significantly more efficient */ batchSearch(texts: string[], caseSensitive?: boolean): TrieMatch[][]; /** * Memory-efficient batch processing with streaming */ batchSearchStream(texts: Iterable, caseSensitive?: boolean): Generator; /** * Optimized traversal with early termination */ searchWithEarlyTermination(text: string, maxMatches: number, caseSensitive?: boolean): TrieMatch[]; enableLazyLoading(callback: (word: string) => TrieNodeData | null): void; /** * Smart cache eviction using LRU strategy */ private evictOldCacheEntries; /** * Get cache performance statistics */ getCacheStats(): { hits: number; misses: number; hitRate: number; size: number; }; /** * Clear search cache */ clearCache(): void; /** * Warm up cache with common patterns */ warmUpCache(commonTexts: string[]): void; /** * Memory usage optimization - compact internal structures */ compact(): void; } /** * Advanced profanity matcher with context-aware detection * Handles severity scoring, word boundaries, and false positive reduction */ /** * Configuration for the profanity matcher */ interface MatcherConfig { /** Languages to detect */ languages: LanguageCode[]; /** Minimum severity level to report */ minSeverity: SeverityLevel; /** Categories to detect */ categories: ProfanityCategory[]; /** Enable fuzzy matching */ fuzzyMatching: boolean; /** Fuzzy matching threshold (0-1) */ fuzzyThreshold: number; /** Words to whitelist */ whitelist: string[]; /** Enable context-aware filtering */ contextAware: boolean; /** Minimum word length to consider */ minWordLength: number; /** Maximum edit distance for fuzzy matches */ maxEditDistance: number; } /** * High-performance profanity matcher with advanced features */ declare class ProfanityMatcher { private tries; private symSpellIndices; private whitelist; private config; private commonWords; private contextPatterns; private matchCache; private readonly MAX_CACHE_SIZE; private cacheHits; private cacheMisses; private normalizationCache; private readonly MAX_NORMALIZATION_CACHE; constructor(config: MatcherConfig); /** * Load profanity words for a specific language */ loadLanguage(language: LanguageCode, words: ReadonlyArray<{ readonly word: string; readonly severity: SeverityLevel; readonly categories: readonly ProfanityCategory[]; readonly variations?: readonly string[]; readonly caseSensitive?: boolean; }>): Promise; /** * Add custom words to the matcher */ addCustomWords(customWords: CustomWord[]): void; /** * Find all profanity matches in text - OPTIMIZED WITH CACHING */ findMatches(text: string, detectedLanguages?: LanguageCode[], caseSensitive?: boolean): DetectionMatch[]; /** * Perform ultra-fast fuzzy search using SymSpell algorithm * 40-80x faster than traditional BFS approach */ private symSpellFuzzySearch; /** * Get Trie data for a word (helper for SymSpell integration) */ private getTrieData; /** * Convert Trie match to Detection match - OPTIMIZED */ private convertToDetectionMatch; /** * Filter matches based on configuration and common patterns */ private filterMatches; /** * Apply context-aware filtering to reduce false positives */ private applyContextFiltering; /** * Get context information for a match - OPTIMIZED */ private getMatchContext; /** * Check for negating context */ private hasNegatingContext; /** * Check for technical/medical context */ private hasTechnicalContext; /** * Check for quoted context */ private hasQuotedContext; /** * Calculate confidence based on context */ private calculateContextConfidence; /** * Check if there's surrounding profanity (quick check) */ private hasSurroundingProfanity; /** * Remove overlapping matches, keeping the highest severity */ private deduplicateMatches; /** * Adjust confidence based on various factors */ private adjustConfidence; /** * Check if word should be included based on config */ private shouldIncludeWord; /** * Check if word is whitelisted */ private isWhitelisted; /** * Check if word is a common word (potential false positive) */ private isCommonWord; /** * Check if match has proper word boundaries */ private hasProperWordBoundaries; /** * Initialize whitelist with common false positives */ private initializeWhitelist; /** * Initialize common words that might cause false positives * Note: Words that are explicitly in profanity databases should not be filtered here */ private initializeCommonWords; /** * Initialize context patterns for better detection */ private initializeContextPatterns; /** * Get matcher statistics with performance metrics */ getStats(): { totalLanguages: number; totalWords: number; trieStats: Record; cacheStats: { hits: number; misses: number; hitRate: number; size: number; }; normalizationCacheSize: number; }; /** * Update matcher configuration */ updateConfig(newConfig: Partial): void; /** * Clear all caches for memory management */ clearCaches(): void; /** * Get cached matches for a text */ private getCachedMatches; /** * Cache matches for a text */ private cacheMatches; /** * Generate cache key for text and configuration */ private getCacheKey; } /** * Default detector configuration */ declare const DEFAULT_DETECTOR_CONFIG: DetectorConfig; /** * Default analysis options */ declare const DEFAULT_ANALYSIS_OPTIONS: AnalysisOptions; /** * Performance-oriented configuration * Optimized for speed over comprehensive detection */ declare const PERFORMANCE_CONFIG: Partial; /** * Comprehensive configuration * Optimized for maximum detection accuracy */ declare const COMPREHENSIVE_CONFIG: Partial; /** * Strict configuration * High precision, low false positives */ declare const STRICT_CONFIG: Partial; /** * Lenient configuration * Lower precision, fewer false negatives */ declare const LENIENT_CONFIG: Partial; /** * Environment-specific configurations */ declare const ENVIRONMENT_CONFIGS: { development: DetectorConfig; production: DetectorConfig; testing: DetectorConfig; }; /** * Get configuration for current environment */ declare function getEnvironmentConfig(): DetectorConfig; /** * Configuration presets for common use cases */ declare const CONFIG_PRESETS: { readonly default: DetectorConfig; readonly performance: { languages: LanguageCode[]; minSeverity: SeverityLevel; categories: ProfanityCategory[]; fuzzyMatching: boolean; fuzzyThreshold: number; customWords: CustomWord[]; whitelist: string[]; detectAlternateScripts: boolean; normalizeText: boolean; replacementChar: string; preserveStructure: boolean; languageData?: Partial>; }; readonly comprehensive: { languages: LanguageCode[]; minSeverity: SeverityLevel; categories: ProfanityCategory[]; fuzzyMatching: boolean; fuzzyThreshold: number; customWords: CustomWord[]; whitelist: string[]; detectAlternateScripts: boolean; normalizeText: boolean; replacementChar: string; preserveStructure: boolean; languageData?: Partial>; }; readonly strict: { languages: LanguageCode[]; minSeverity: SeverityLevel; categories: ProfanityCategory[]; fuzzyMatching: boolean; fuzzyThreshold: number; customWords: CustomWord[]; whitelist: string[]; detectAlternateScripts: boolean; normalizeText: boolean; replacementChar: string; preserveStructure: boolean; languageData?: Partial>; }; readonly lenient: { languages: LanguageCode[]; minSeverity: SeverityLevel; categories: ProfanityCategory[]; fuzzyMatching: boolean; fuzzyThreshold: number; customWords: CustomWord[]; whitelist: string[]; detectAlternateScripts: boolean; normalizeText: boolean; replacementChar: string; preserveStructure: boolean; languageData?: Partial>; }; }; /** * Get a configuration preset by name */ declare function getConfigPreset(preset: keyof typeof CONFIG_PRESETS): DetectorConfig; /** * Language-specific optimization configs */ declare const LANGUAGE_OPTIMIZED_CONFIGS: { en: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; es: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; fr: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; de: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; ru: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; zh: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; ja: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; ar: { fuzzyThreshold: number; normalizeText: boolean; detectAlternateScripts: boolean; }; }; /** * Configuration validation and sanitization * Ensures all configuration options are valid and safe */ /** * Configuration validation result */ interface ValidationResult { isValid: boolean; errors: string[]; warnings: string[]; sanitizedConfig: DetectorConfig | undefined; } /** * Analysis options validation result */ interface AnalysisOptionsValidationResult { isValid: boolean; errors: string[]; warnings: string[]; sanitizedOptions: AnalysisOptions | undefined; } /** * Validate and sanitize detector configuration */ declare class ConfigValidator { /** * Validate a complete detector configuration */ static validate(config: Partial): ValidationResult; /** * Validate analysis options */ static validateAnalysisOptions(options: Partial): AnalysisOptionsValidationResult; /** * Validate languages array */ private static validateLanguages; /** * Validate severity level */ private static validateSeverity; /** * Validate categories array */ private static validateCategories; /** * Validate fuzzy threshold */ private static validateFuzzyThreshold; /** * Validate custom words */ private static validateCustomWords; /** * Validate whitelist */ private static validateWhitelist; /** * Validate replacement character */ private static validateReplacementChar; /** * Perform cross-validation of configuration settings */ private static performCrossValidation; /** * Quick validation for basic use cases */ static quickValidate(config: Partial): boolean; /** * Sanitize configuration without full validation */ static sanitize(config: Partial): DetectorConfig; } /** * Runtime configuration management * Handles configuration loading, validation, environment overrides, and hot-swapping */ /** * Configuration source types */ type ConfigSource = 'default' | 'file' | 'environment' | 'runtime'; /** * Configuration change event */ interface ConfigChangeEvent { source: ConfigSource; previousConfig: DetectorConfig; newConfig: DetectorConfig; timestamp: Date; changeDetails: { added: string[]; modified: string[]; removed: string[]; }; } /** * Configuration manager options */ interface ConfigManagerOptions { enableHotReload?: boolean; configFilePath?: string; validateOnLoad?: boolean; autoOptimizeForLanguages?: boolean; enableEnvironmentOverrides?: boolean; cacheValidatedConfigs?: boolean; } /** * Runtime configuration manager */ declare class ConfigManager { private currentConfig; private configHistory; private changeListeners; private fileWatcher; private configCache; private readonly maxHistorySize; private readonly options; constructor(initialConfig?: Partial, options?: ConfigManagerOptions); /** * Get current configuration */ getConfig(): DetectorConfig; /** * Update configuration with validation */ updateConfig(newConfig: Partial, source?: ConfigSource, skipHistory?: boolean, skipNotification?: boolean): Promise; /** * Load configuration from file */ loadFromFile(filePath?: string): Promise; /** * Save current configuration to file */ saveToFile(filePath?: string): Promise; /** * Apply environment variable overrides */ applyEnvironmentOverrides(): void; /** * Use a configuration preset */ usePreset(preset: keyof typeof CONFIG_PRESETS): Promise; /** * Auto-optimize configuration for detected languages */ private autoOptimizeForLanguages; /** * Enable hot reload for configuration file */ private enableHotReload; /** * Add configuration change listener */ onConfigChange(listener: (event: ConfigChangeEvent) => void): () => void; /** * Get configuration history */ getConfigHistory(): Array<{ config: DetectorConfig; timestamp: Date; source: ConfigSource; }>; /** * Revert to previous configuration */ revertToPrevious(): Promise; /** * Reset to default configuration */ resetToDefault(): Promise; /** * Validate current configuration */ validateCurrentConfig(): { isValid: boolean; errors: string[]; warnings: string[]; }; /** * Get optimized configuration for specific languages */ getOptimizedConfigForLanguages(languages: LanguageCode[]): DetectorConfig; /** * Dispose resources */ dispose(): void; /** * Detect changes between configurations */ private detectChanges; /** * Notify all change listeners */ private notifyListeners; } /** * Get or create global configuration manager */ declare function getGlobalConfigManager(initialConfig?: Partial, options?: ConfigManagerOptions): ConfigManager; /** * Reset global configuration manager */ declare function resetGlobalConfigManager(): void; /** * Dynamic language data loading system * Handles lazy loading, caching, and optimization for language-specific data */ /** * Language data structure */ interface LanguageData { metadata: { name: string; code: LanguageCode; version: string; wordCount: number; lastUpdated: string; contributors?: string[]; }; profanity: Array<{ word: string; severity: SeverityLevel; categories: ProfanityCategory[]; variations?: string[]; context?: string[]; [key: string]: unknown; }>; categories: Record; severity: Record; variations: Record; context: Record; } /** * Language loading options */ interface LanguageLoadOptions { dataPath?: string; cacheEnabled?: boolean; preloadCommonWords?: boolean; validateData?: boolean; useCompressedFormat?: boolean; languageData?: Partial>; } /** * Language load result */ interface LanguageLoadResult { success: boolean; data?: LanguageData; error?: string; loadTime: number; fromCache: boolean; } /** * Dynamic language data loader */ declare class LanguageLoader { private cache; private loadingPromises; private options; private staticLanguageData; private loadTimes; private cacheHits; private cacheMisses; constructor(options?: LanguageLoadOptions); /** * Load language data with caching and optimization */ loadLanguage(language: LanguageCode): Promise; /** * Perform actual language loading */ private performLanguageLoad; /** * Load language data from static imports (tree-shakeable) */ private loadFromStaticData; /** * Load all language files from directory */ private loadLanguageFiles; /** * Validate language data structure */ private validateLanguageData; /** * Preload common languages */ preloadCommonLanguages(languages?: LanguageCode[]): Promise; /** * Batch load multiple languages */ loadLanguages(languages: LanguageCode[]): Promise>; /** * Get available languages in data directory */ getAvailableLanguages(): Promise; /** * Get language metadata without loading full data */ getLanguageMetadata(language: LanguageCode): Promise; /** * Check if language is available */ isLanguageAvailable(language: LanguageCode): Promise; /** * Clear cache for specific language or all languages */ clearCache(language?: LanguageCode): void; /** * Get cache statistics */ getCacheStats(): { cacheSize: number; cacheHits: number; cacheMisses: number; hitRate: number; cachedLanguages: LanguageCode[]; }; /** * Get load performance statistics */ getPerformanceStats(): Map; /** * Optimize memory usage */ optimizeMemory(): void; /** * Reload specific language data */ reloadLanguage(language: LanguageCode): Promise; /** * Get language data size estimation */ getLanguageDataSize(language: LanguageCode): number; /** * Export cached data for serialization */ exportCache(): Record; /** * Import cached data from serialization */ importCache(data: Record): void; /** * Dispose resources and cleanup */ dispose(): void; } /** * Get global language loader instance */ declare function getGlobalLanguageLoader(options?: LanguageLoadOptions): LanguageLoader; /** * Reset global language loader */ declare function resetGlobalLanguageLoader(): void; /** * Multi-language detection and coordination system * Manages detection across multiple languages with intelligent optimization */ /** * Multi-language detection result */ interface MultiLanguageDetectionResult extends DetectionResult { languageResults: Map; primaryLanguage: LanguageCode; languageConfidences: Map; crossLanguageMatches: boolean; } /** * Multi-language detector options */ interface MultiLanguageDetectorOptions { languages: LanguageCode[]; autoDetectLanguages?: boolean; primaryLanguage?: LanguageCode; enableCrossLanguageMatching?: boolean; languageThreshold?: number; parallelProcessing?: boolean; cacheResults?: boolean; optimizeForPerformance?: boolean; } /** * Language detection strategy */ declare enum LanguageDetectionStrategy { AUTO = "auto",// Auto-detect based on text EXPLICIT = "explicit",// Use only specified languages HYBRID = "hybrid" } /** * Multi-language profanity detector */ declare class MultiLanguageDetector { private languageDetectors; private languageDetector; private languageLoader; private configManager; private options; private detectionStats; private resultCache; private readonly MAX_CACHE_SIZE; private cacheHits; private cacheMisses; constructor(baseConfig?: Partial, options?: Partial); /** * Initialize detectors for each configured language */ private initializeLanguageDetectors; /** * Detect profanity across multiple languages */ detect(text: string, options?: Partial): Promise; /** * Detect languages present in text */ private detectLanguagesInText; /** * Select languages for analysis based on detection and configuration */ private selectLanguagesForAnalysis; /** * Analyze text with multiple language detectors */ private analyzeWithMultipleLanguages; /** * Merge results from multiple language detectors */ private mergeLanguageResults; /** * Detect cross-language profanity matches */ private detectCrossLanguageMatches; /** * Add support for new language */ addLanguage(language: LanguageCode, config?: Partial): Promise; /** * Remove language support */ removeLanguage(language: LanguageCode): boolean; /** * Get available languages */ getAvailableLanguages(): LanguageCode[]; /** * Get language-specific detector */ getLanguageDetector(language: LanguageCode): ContentShieldDetector | undefined; /** * Update configuration for all language detectors */ updateConfiguration(newConfig: Partial): Promise; /** * Get performance statistics */ getPerformanceStats(): { languageStats: Map; cacheStats: { size: number; hitRate: number; }; }; /** * Warm up caches for common patterns */ warmUpCaches(commonTexts: string[]): Promise; /** * Optimize memory usage */ optimizeMemory(): void; /** * Generate cache key for result caching */ private generateCacheKey; /** * Cache analysis result */ private cacheResult; /** * Update performance statistics */ private updatePerformanceStats; /** * Dispose resources */ dispose(): void; } /** * Factory options for creating detectors */ interface DetectorFactoryOptions { useOptimizedConfig?: boolean; enableCaching?: boolean; preloadLanguageData?: boolean; enableAdvancedFeatures?: boolean; } /** * Create a detector optimized for specific language(s) */ declare function createDetector(languages: LanguageCode | LanguageCode[], config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create an advanced multi-language detector */ declare function createAdvancedMultiLanguageDetector(languages: LanguageCode[], config?: Partial, options?: DetectorFactoryOptions): MultiLanguageDetector; /** * Create a detector for English content */ declare function createEnglishDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for Spanish content */ declare function createSpanishDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for French content */ declare function createFrenchDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for German content */ declare function createGermanDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for Russian content */ declare function createRussianDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for Chinese content */ declare function createChineseDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for Japanese content */ declare function createJapaneseDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a detector for Arabic content */ declare function createArabicDetector(config?: Partial, options?: DetectorFactoryOptions): ContentShieldDetector; /** * Create a high-performance detector optimized for speed */ declare function createPerformanceDetector(languages?: LanguageCode | LanguageCode[], config?: Partial): ContentShieldDetector; /** * Create a comprehensive detector for maximum accuracy */ declare function createComprehensiveDetector(languages?: LanguageCode[], config?: Partial): ContentShieldDetector; /** * Create a detector based on environment (development, production, testing) */ declare function createEnvironmentDetector(languages?: LanguageCode | LanguageCode[], environment?: 'development' | 'production' | 'testing'): ContentShieldDetector; /** * Auto-detect and create appropriate detector for text */ declare function createAutoDetector(sampleText: string, config?: Partial): Promise; /** * Create detector with custom language data loader * * NOTE: This is currently a placeholder implementation. Full integration of custom loaders * would require architectural changes to pass the loader instance through the detector * initialization chain. For now, this function creates a detector with default loading behavior. * * Future enhancement: Modify ContentShieldDetector constructor to accept optional LanguageLoader * instance and use it instead of the default loading mechanism. */ declare function createDetectorWithCustomLoader(languages: LanguageCode | LanguageCode[], dataPath: string, config?: Partial): ContentShieldDetector; /** * Get language-specific factory function */ declare function getLanguageFactory(language: LanguageCode): ((config?: Partial, options?: DetectorFactoryOptions) => ContentShieldDetector) | null; /** * Create multiple language-specific detectors */ declare function createDetectorCollection(languages: LanguageCode[], config?: Partial, options?: DetectorFactoryOptions): Map; /** * Legacy compatibility - original multi-language detector */ declare function createMultiLanguageDetector(languages: LanguageCode[], config?: Partial): ContentShieldDetector; /** * Text normalization utilities for consistent profanity detection */ /** * Normalize text for profanity detection - OPTIMIZED */ declare function normalizeText(text: string): string; /** * Fuzzy matching utilities for profanity detection */ /** * Check if two strings match within a fuzzy threshold */ declare function fuzzyMatch(text: string, pattern: string, threshold?: number): boolean; /** * Find fuzzy matches in text */ declare function findFuzzyMatches(text: string, patterns: string[], threshold?: number): Array<{ pattern: string; match: string; similarity: number; start: number; end: number; }>; /** * Calculate similarity score between two strings */ declare function calculateSimilarity(a: string, b: string): number; /** * Find the best match from a list of patterns */ declare function findBestMatch(text: string, patterns: string[], minThreshold?: number): { pattern: string; similarity: number; } | null; /** * Create a default detector configuration */ declare function createDefaultConfig(): DetectorConfig; /** * Create a strict configuration for high-security environments */ declare function createStrictConfig(): DetectorConfig; /** * Create a lenient configuration for casual environments */ declare function createLenientConfig(): DetectorConfig; /** * Create a configuration for family-friendly content */ declare function createFamilyFriendlyConfig(): DetectorConfig; /** * Quick detection function using default configuration */ declare function detect(text: string): Promise; /** * Quick filter function using default configuration */ declare function filter(text: string, mode?: FilterMode): Promise; /** * Quick clean check using default configuration */ declare function isClean(text: string): Promise; /** * Configure the default detector instance with custom settings. * * This function allows you to configure the global detector used by quick-start functions. * Once configured, all subsequent calls to detect(), filter(), and isClean() will use * these settings. * * @param config - Partial detector configuration to apply * * @example * ```typescript * // Configure with static language data (tree-shakeable) * import { configure, detect } from 'content-shield' * import { EN } from 'content-shield/languages/en' * * await configure({ * languageData: { en: EN }, * languages: ['en'] * }) * * const result = await detect('some text') * ``` * * @example * ```typescript * // Configure with dynamic loading (loads from data directory) * import { configure, detect } from 'content-shield' * * await configure({ * languages: ['en', 'es'], * minSeverity: SeverityLevel.HIGH * }) * * const result = await detect('some text') * ``` * * @example * ```typescript * // Configure multiple languages with static imports * import { configure, detect } from 'content-shield' * import { EN } from 'content-shield/languages/en' * import { ES } from 'content-shield/languages/es' * * await configure({ * languageData: { * en: EN, * es: ES * }, * languages: ['en', 'es'], * fuzzyMatching: true * }) * * const result = await detect('text with multiple languages') * ``` */ declare function configure(config: Partial): Promise; /** * Reset the default detector instance */ declare function reset(): void; /** * ContentShield - A modern TypeScript library for multi-language profanity detection * and content moderation with severity levels and customizable filtering * * Features: * - Multi-language support (17 languages) * - Performance optimizations with intelligent caching * - Comprehensive configuration system * - Advanced language integration * - Worker thread support for large texts * - Memory-efficient operations * - Real-time configuration management */ interface PerformanceMonitor { startTiming(operation: string): string; endTiming(timerId: string): number; getStats(): Record; reset(): void; } declare class SimplePerformanceMonitor implements PerformanceMonitor { private timers; private stats; startTiming(operation: string): string; endTiming(timerId: string): number; getStats(): Record; reset(): void; } declare const performanceMonitor: SimplePerformanceMonitor; interface EnhancedOptions { language?: LanguageCode | LanguageCode[]; performance?: boolean; caching?: boolean; fuzzyMatching?: boolean; customConfig?: Partial; } /** * Enhanced detect function with advanced options */ declare function detectEnhanced(text: string, options?: EnhancedOptions): Promise; /** * Enhanced filter function with advanced options */ declare function filterEnhanced(text: string, options?: EnhancedOptions): Promise; /** * Batch processing function for multiple texts */ declare function batchDetect(texts: string[], options?: EnhancedOptions): Promise; /** * Stream processing function for large datasets */ declare function streamDetect(texts: Iterable, options?: EnhancedOptions): AsyncGenerator; /** * Create a pre-configured detector instance */ declare function createConfiguredDetector(preset?: 'performance' | 'comprehensive' | 'strict' | 'lenient', languages?: LanguageCode | LanguageCode[], customConfig?: Partial): Promise; /** * Auto-configure detector based on sample text */ declare function createSmartDetector(sampleTexts: string[], customConfig?: Partial): Promise; /** * Utility function to get library information */ declare function getLibraryInfo(): { version: string; supportedLanguages: LanguageCode[]; features: string[]; }; /** * Health check function */ declare function healthCheck(): Promise<{ status: 'healthy' | 'warning' | 'error'; checks: Record; details: Record; }>; declare const VERSION = "0.1.0"; export { AnalysisOptions, type AnalysisOptionsValidationResult, COMPREHENSIVE_CONFIG, CONFIG_PRESETS, type ConfigChangeEvent, ConfigManager, type ConfigManagerOptions, type ConfigSource, ConfigValidator, ContentShieldDetector, CustomWord, DEFAULT_ANALYSIS_OPTIONS, DEFAULT_DETECTOR_CONFIG, DetectionMatch, DetectionResult, DetectionResultBuilder, DetectorConfig, type DetectorFactoryOptions, ENVIRONMENT_CONFIGS, EnhancedDetectionMatch$1 as EnhancedDetectionMatch, type EnhancedOptions, type FilterConfig, type FilterDetail, FilterMode, type FilterResult, LANGUAGE_OPTIMIZED_CONFIGS, LENIENT_CONFIG, LanguageCode, type LanguageData, LanguageDetection, LanguageDetectionStrategy, LanguageDetector, type LanguageLoadOptions, type LanguageLoadResult, LanguageLoader, type MultiLanguageDetectionResult, MultiLanguageDetector, type MultiLanguageDetectorOptions, PERFORMANCE_CONFIG, type PerformanceMonitor, ProfanityCategory, ProfanityFilter, ProfanityMatcher, ProfanityTrie, STRICT_CONFIG, SeverityLevel, StaticLanguageData, VERSION, type ValidationResult, batchDetect, calculateSimilarity, configure, createAdvancedMultiLanguageDetector, createArabicDetector, createAutoDetector, createChineseDetector, createComprehensiveDetector, createConfiguredDetector, createDefaultConfig, createDetector, createDetectorCollection, createDetectorWithCustomLoader, createEnglishDetector, createEnvironmentDetector, createFamilyFriendlyConfig, createFrenchDetector, createGermanDetector, createJapaneseDetector, createLenientConfig, createMultiLanguageDetector, createPerformanceDetector, createRussianDetector, createSmartDetector, createSpanishDetector, createStrictConfig, detect, detectEnhanced, filter, filterEnhanced, findBestMatch, findFuzzyMatches, fuzzyMatch, getConfigPreset, getEnvironmentConfig, getGlobalConfigManager, getGlobalLanguageLoader, getLanguageFactory, getLibraryInfo, healthCheck, isClean, normalizeText, performanceMonitor, reset, resetGlobalConfigManager, resetGlobalLanguageLoader, streamDetect };