🛡️ profanity-nsfw-violence-checker
A robust and customizable TypeScript/JavaScript library for detecting and censoring profanity, sexual content, violence, and hate speech in plain text and HTML.
✨ Features
- 🚨 Detects profanity, sexual content, violence, and hate speech
- 🧠 Supports leetspeak & misspellings (e.g.,
s3x, f@ck)
- 🧪 Customizable severity levels (low/medium/high)
- 🛡️ Safe HTML censoring without breaking markup
- 📦 Built-in TypeScript types and full support
- 🧰 Add/remove words, enable whitelist, toggle
strictMode
📦 Installation
npm install profanity-nsfw-violence-checker
yarn add profanity-nsfw-violence-checker
🚀 Quick Start
import { ProfanityChecker } from 'profanity-nsfw-violence-checker';
const checker = new ProfanityChecker();
const result = checker.check("That fucking movie was damn violent!");
console.log(result);
/* Output:
{
originalText: 'That fucking movie was a damn disgrace. It was so violent!',
isFlagged: true,
isProfane: true,
isSexual: false,
isViolent: true,
isHateSpeech: false,
severity: 'high',
matches: {
profanity: [ { word: 'fucking', position: 5, severity: 'medium', ... }, { word: 'damn', position: 28, severity: 'medium', ... } ],
sexual: [],
violence: [ { word: 'violent', position: 51, severity: 'high', ... } ],
hateSpeech: []
}
}
*/
const censored = checker.censor("That fucking movie was damn violent!");
console.log(censored); // Output: That ******* movie was **** violent!
🖼️ HTML Censoring
const html = '<p>This is <strong>damn</strong> violent.</p>';
const cleanHtml = checker.censorHtml(html);
console.log(cleanHtml);
// <p>This is <strong>****</strong> violent.</p>
⚙️ Configuration
const customChecker = new ProfanityChecker({
censorCharacter: '#',
strictMode: true,
allowWhitelist: true,
customWords: {
profanity: ['frick', 'dang'],
hateSpeech: ['subhuman']
}
});
📚 API Methods
checker.check(text: string): CheckResult → Analyze text and get details
checker.censor(text: string): string → Censor words in plain text
checker.censorHtml(html: string): string → Censor inside HTML safely
checker.addWords(category, words, severity?) → Add words to a category
checker.removeWords(category, words) → Remove words from category
checker.addToWhitelist(words) → Exclude words from detection
checker.getStats() → Dictionary stats (count per category)
🧠 Supported Categories
- profanity: e.g., f***, s***, etc.
- sexual: e.g., p***, blowjob, etc.
- violence: e.g., kill, stab, etc.
- hateSpeech: e.g., racial slurs, subhuman, etc.
🧪 TypeScript Support
type Severity = 'low' | 'medium' | 'high';
interface Match {
word: string;
position: number;
severity: Severity;
context: string;
}
interface CheckResult {
originalText: string;
isFlagged: boolean;
isProfane: boolean;
isSexual: boolean;
isViolent: boolean;
isHateSpeech: boolean;
severity: Severity;
matches: {
profanity: Match[];
sexual: Match[];
violence: Match[];
hateSpeech: Match[];
};
}
📈 Example Output
{
isFlagged: true,
isProfane: true,
isSexual: false,
isViolent: true,
isHateSpeech: false,
severity: 'high',
matches: {
profanity: [{ word: 'fucking', position: 5, severity: 'high' }],
sexual: [],
violence: [{ word: 'violent', position: 42, severity: 'high' }],
hateSpeech: []
}
}
🙌 Contributions
PRs and issues are welcome. Help improve detection accuracy, word lists, or features!
📄 License
MIT License – Victor Olayemi