profanity-nsfw-violence-checker
Version:
A powerful TypeScript library to detect and censor profanity, sexual content, violence, and hate speech in both plain text and HTML.
182 lines (145 loc) โข 5.1 kB
Markdown
<h1>๐ก๏ธ profanity-nsfw-violence-checker</h1>
<p>
A robust and customizable TypeScript/JavaScript library for detecting and censoring profanity, sexual content, violence, and hate speech in plain text and HTML.
</p>
<p>
<a href="https://www.npmjs.com/package/profanity-nsfw-violence-checker">
<img src="https://img.shields.io/npm/v/profanity-nsfw-violence-checker.svg" alt="npm version" />
</a>
<a href="https://www.npmjs.com/package/profanity-nsfw-violence-checker">
<img src="https://img.shields.io/npm/dm/profanity-nsfw-violence-checker.svg" alt="npm downloads" />
</a>
<a href="https://github.com/victorolayemi/profanity-nsfw-violence-checker/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/profanity-nsfw-violence-checker.svg" alt="license" />
</a>
</p>
<hr />
<h2>โจ Features</h2>
<ul>
<li>๐จ Detects <strong>profanity, sexual content, violence, and hate speech</strong></li>
<li>๐ง Supports <strong>leetspeak & misspellings</strong> (e.g., <code>s3x</code>, <code>f@ck</code>)</li>
<li>๐งช Customizable <strong>severity levels</strong> (low/medium/high)</li>
<li>๐ก๏ธ Safe <strong>HTML censoring</strong> without breaking markup</li>
<li>๐ฆ Built-in <strong>TypeScript types</strong> and full support</li>
<li>๐งฐ Add/remove words, enable <strong>whitelist</strong>, toggle <code>strictMode</code></li>
</ul>
<hr />
<h2>๐ฆ Installation</h2>
<pre><code>npm install profanity-nsfw-violence-checker</code></pre>
<pre><code>yarn add profanity-nsfw-violence-checker</code></pre>
<hr />
<h2>๐ Quick Start</h2>
<pre><code>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!
</code></pre>
<hr />
<h2>๐ผ๏ธ HTML Censoring</h2>
<pre><code>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>
</code></pre>
<hr />
<h2>โ๏ธ Configuration</h2>
<pre><code>const customChecker = new ProfanityChecker({
censorCharacter: '#',
strictMode: true,
allowWhitelist: true,
customWords: {
profanity: ['frick', 'dang'],
hateSpeech: ['subhuman']
}
});
</code></pre>
<hr />
<h2>๐ API Methods</h2>
<ul>
<li><code>checker.check(text: string): CheckResult</code> โ Analyze text and get details</li>
<li><code>checker.censor(text: string): string</code> โ Censor words in plain text</li>
<li><code>checker.censorHtml(html: string): string</code> โ Censor inside HTML safely</li>
<li><code>checker.addWords(category, words, severity?)</code> โ Add words to a category</li>
<li><code>checker.removeWords(category, words)</code> โ Remove words from category</li>
<li><code>checker.addToWhitelist(words)</code> โ Exclude words from detection</li>
<li><code>checker.getStats()</code> โ Dictionary stats (count per category)</li>
</ul>
<hr />
<h2>๐ง Supported Categories</h2>
<ul>
<li><strong>profanity</strong>: e.g., f***, s***, etc.</li>
<li><strong>sexual</strong>: e.g., p***, blowjob, etc.</li>
<li><strong>violence</strong>: e.g., kill, stab, etc.</li>
<li><strong>hateSpeech</strong>: e.g., racial slurs, subhuman, etc.</li>
</ul>
<hr />
<h2>๐งช TypeScript Support</h2>
<pre><code>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[];
};
}
</code></pre>
<hr />
<h2>๐ Example Output</h2>
<pre><code>{
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: []
}
}
</code></pre>
<hr />
<h2>๐ Contributions</h2>
<p>
PRs and issues are welcome. Help improve detection accuracy, word lists, or features!
</p>
<hr />
<h2>๐ License</h2>
<p>
MIT License โ Victor Olayemi
</p>