JavaScript ↔ Python Cross-Reference
Complete API parity reference between JavaScript and Python implementations
Complete cross-platform API reference showing exact method correspondence between JavaScript and Python implementations. All methods provide identical functionality with language-appropriate naming conventions.
✅ 100% Feature Parity
Every JavaScript method has an equivalent Python implementation with identical functionality, parameters, and return values.
Core Functions API
Primary Detection Methods
| JavaScript Method | Python Method | Description | Documentation Links |
|---|---|---|---|
checkProfanity() | check_profanity() | Main profanity detection with full configuration support | JS Docs | Python Docs |
isWordProfane() | is_word_profane() | Quick boolean check for single words | JS Docs | Python Docs |
checkProfanityAsync() | check_profanity_async() | Promise-based async profanity detection | JS Docs | Python Docs |
validateText() | validate_text() | Comprehensive text validation with suggestions | JS Docs | Python Docs |
getLanguageInfo() | get_language_info() | Get supported language capabilities and information | JS Docs | Python Docs |
Filter Class API
Object-Oriented Interface
| JavaScript Method | Python Method | Description | Documentation Links |
|---|---|---|---|
new Filter(config) | Filter(config) | Filter class constructor with persistent configuration | JS Docs | Python Docs |
filter.check(text) | filter.check(text) | Check profanity using instance configuration | JS Docs | Python Docs |
filter.checkWithMinSeverity() | filter.check_with_min_severity() | Filter by severity threshold (MILD/MODERATE/SEVERE) | JS Docs | Python Docs |
filter.isProfane(word) | filter.is_profane(word) | Quick word check using instance configuration | JS Docs | Python Docs |
filter.updateConfig() | filter.update_config() | Update instance configuration dynamically | JS Docs | Python Docs |
filter.getConfig() | filter.get_config() | Get current instance configuration | JS Docs | Python Docs |
filter.resetConfig() | filter.reset_config() | Reset configuration to defaults | JS Docs | Python Docs |
filter.clearCache() | filter.clear_cache() | Clear internal result cache | JS Docs | Python Docs |
filter.getCacheStats() | filter.get_cache_stats() | Get cache performance statistics | JS Docs | Python Docs |
Batch Processing API
Multiple Text Processing
| JavaScript Method | Python Method | Description | Documentation Links |
|---|---|---|---|
checkMultiple() | check_multiple() | Process multiple texts efficiently with shared configuration | JS Docs | Python Docs |
validateMultiple() | validate_multiple() | Validate multiple texts with comprehensive results | JS Docs | Python Docs |
processBatch() | process_batch() | High-performance batch processing with streaming support | JS Docs | Python Docs |
React Integration API
React Hook (JavaScript Only)
| JavaScript Method | Python Equivalent | Description | Documentation Links |
|---|---|---|---|
useProfanityChecker() | N/A - JavaScript Only | React hook for profanity checking with state management | React Hook Docs |
hook.checkText() | Use Flask/Django patterns | Check text and update hook state | React Hook Docs |
hook.checkTextAsync() | Use async Flask routes | Async text checking with loading states | React Hook Docs |
hook.reset() | Manage state manually | Reset hook state to initial values | React Hook Docs |
React Integration: Python doesn't have React hooks, but equivalent functionality can be achieved using Flask/Django with async routes and proper state management on the frontend.
Configuration Options
Complete Configuration Parity
| JavaScript Config | Python Config | Description | Default Values |
|---|---|---|---|
languages: string[] | languages: List[str] | Specific languages to check for profanity | ['english'] |
allLanguages: boolean | all_languages: bool | Check all 23 supported languages | false / False |
enableContextAware: boolean | enable_context_aware: bool | Enable NLP-based context analysis | false / False |
confidenceThreshold: number | confidence_threshold: float | Context confidence threshold (0.0-1.0) | 0.7 |
contextWindow: number | context_window: int | Number of words to analyze for context | 3 |
caseSensitive: boolean | case_sensitive: bool | Enable case-sensitive matching | false / False |
wordBoundaries: boolean | word_boundaries: bool | Enforce word boundaries for exact matching | true / True |
allowObfuscatedMatch: boolean | allow_obfuscated_match: bool | Detect disguised profanity (sh1t, f*ck) | false / False |
fuzzyMatching: boolean | fuzzy_matching: bool | Enable fuzzy matching for similar words | true / True |
fuzzyTolerance: number | fuzzy_tolerance: float | Character similarity threshold (0.0-1.0) | 0.8 |
autoReplace: boolean | auto_replace: bool | Automatically return text with profanity replaced | false / False |
replaceChar: string | replace_char: str | Character to use for replacement | '●' |
preserveLength: boolean | preserve_length: bool | Preserve original word length in replacements | true / True |
severityFilter: string | severity_filter: str | Minimum severity to flag (MILD/MODERATE/SEVERE) | 'MODERATE' |
enableCaching: boolean | enable_caching: bool | Enable result caching for performance | false / False |
cacheSize: number | cache_size: int | Maximum number of cached results | 1000 |
Return Value Structures
Cross-Platform Return Types
interface ProfanityCheckResult {
containsProfanity: boolean;
profaneWords: string[];
processedText?: string;
filteredWords: string[];
autoReplaced?: string;
severityMap?: Record<string, SeverityLevel>;
matches?: Match[];
contextScore?: number;
}
interface ValidationResult {
isValid: boolean;
errors: string[];
suggestions: string[];
confidence: number;
alternatives: Record<string, string[]>;
}
interface CacheStats {
hits: number;
misses: number;
hitRate: number;
size: number;
maxSize: number;
}class ProfanityCheckResult:
contains_profanity: bool
profane_words: List[str]
processed_text: Optional[str]
filtered_words: List[str]
auto_replaced: Optional[str]
severity_map: Optional[Dict[str, SeverityLevel]]
matches: Optional[List[Match]]
context_score: Optional[float]
class ValidationResult:
is_valid: bool
errors: List[str]
suggestions: List[str]
confidence: float
alternatives: Dict[str, List[str]]
class CacheStats:
hits: int
misses: int
hit_rate: float
size: int
max_size: intUsage Examples Comparison
Side-by-Side Implementation Examples
import { checkProfanity, Filter } from 'glin-profanity';
// Basic usage
const result = checkProfanity("This is damn good!", {
languages: ['english'],
enableContextAware: true,
confidenceThreshold: 0.7
});
// Filter class usage
const filter = new Filter({
languages: ['english', 'spanish'],
enableContextAware: true,
autoReplace: true,
replaceChar: '●'
});
const processedResult = filter.check("Text to analyze");
// Batch processing
const batchResults = filter.checkMultiple([
"First text to check",
"Second text to analyze",
"Third piece of content"
]);
// Configuration updates
filter.updateConfig({
confidenceThreshold: 0.8,
severityFilter: 'MODERATE'
});
// Cache management
const stats = filter.getCacheStats();
filter.clearCache();from glin_profanity import check_profanity, Filter
# Basic usage
result = check_profanity("This is damn good!", {
'languages': ['english'],
'enable_context_aware': True,
'confidence_threshold': 0.7
})
# Filter class usage
filter_instance = Filter({
'languages': ['english', 'spanish'],
'enable_context_aware': True,
'auto_replace': True,
'replace_char': '●'
})
processed_result = filter_instance.check("Text to analyze")
# Batch processing
batch_results = filter_instance.check_multiple([
"First text to check",
"Second text to analyze",
"Third piece of content"
])
# Configuration updates
filter_instance.update_config({
'confidence_threshold': 0.8,
'severity_filter': 'MODERATE'
})
# Cache management
stats = filter_instance.get_cache_stats()
filter_instance.clear_cache()Framework Integration Patterns
Web Framework Equivalents
| JavaScript Framework | Python Framework | Description | Documentation Links |
|---|---|---|---|
| Express.js Middleware | Flask Decorator Pattern | Node.js web framework integration | Express Guide | Flask Guide |
| Next.js API Routes | Django Model Validation | React framework server-side integration | Next.js Guide | Django Guide |
| React Hook Forms | WTForms Integration | Client-side form validation | React Forms | WTForms Example |
| Browser Web Workers | Celery Background Tasks | Background processing in browsers | Web Workers | Celery Tasks |
Error Handling Comparison
Exception and Error Patterns
import { checkProfanity, ProfanityError } from 'glin-profanity';
try {
const result = checkProfanity(text, config);
if (result.containsProfanity) {
console.log('Profanity detected:', result.profaneWords);
}
} catch (error) {
if (error instanceof ProfanityError) {
console.error('Profanity check failed:', error.message);
console.error('Error code:', error.code);
} else {
console.error('Unexpected error:', error);
}
}
// Async error handling
try {
const result = await checkProfanityAsync(text, config);
} catch (error) {
console.error('Async check failed:', error);
}from glin_profanity import check_profanity, ProfanityError
try:
result = check_profanity(text, config)
if result['contains_profanity']:
print('Profanity detected:', result['profane_words'])
except ProfanityError as e:
print(f'Profanity check failed: {e.message}')
print(f'Error code: {e.code}')
except Exception as e:
print(f'Unexpected error: {e}')
# Async error handling
try:
result = await check_profanity_async(text, config)
except Exception as e:
print(f'Async check failed: {e}')Performance Considerations
Cross-Platform Performance Notes
- Memory Usage: Both implementations have similar memory footprints (~2-5MB)
- Processing Speed: JavaScript typically 10-15% faster due to V8 optimizations
- Bundle Size: JavaScript bundle ~2.1MB, Python package ~1.8MB
- Cold Start: Python has slightly faster cold start due to simpler initialization
- Caching: Both implementations support identical caching strategies
- Concurrent Processing: JavaScript uses Web Workers, Python uses multiprocessing
What's Next?
🔧 Core Functions
Complete JavaScript API reference
🐍 Python API
Complete Python API reference
⚛️ React Integration
React hook usage and examples
🏗️ Filter Class
Object-oriented API for both languages
Perfect Parity: Both JavaScript and Python implementations provide identical functionality. Choose the language that best fits your project requirements - the profanity detection capabilities are exactly the same.