Getting Started with Glin-Profanity
Installation
Install Glin-Profanity into your project:
npm install glin-profanity
yarn add glin-profanity
Basic Usage
Quickly scan text in real-time using the useProfanityChecker
hook:
import React, { useState } from 'react';
import { useProfanityChecker } from 'glin-profanity';
const MyComponent = () => {
const [text, setText] = useState('');
const { result, checkText } = useProfanityChecker();
const handleCheck = () => checkText(text);
return (
<div className="space-y-4">
<input
type="text"
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Type something..."
className="w-full border rounded px-3 py-2"
/>
<button
onClick={handleCheck}
className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded"
>
Check Profanity
</button>
{result && (
<div className="mt-2">
<p>Contains Profanity: <strong>{result.containsProfanity ? 'Yes' : 'No'}</strong></p>
{result.containsProfanity && (
<>
<p>Flagged Words: <code>{result.profaneWords.join(', ')}</code></p>
{result.severityMap && (
<ul className="list-disc list-inside text-sm text-gray-600 dark:text-gray-300">
{result.profaneWords.map((word, i) => (
<li key={i}>
<strong>{word}</strong> – Severity: <em>{result.severityMap?.[word] ?? 'N/A'}</em>
</li>
))}
</ul>
)}
</>
)}
</div>
)}
</div>
);
};
Displays results, flagged terms, and severity levels for enhanced moderation control.
Configuration
Control detection behavior with config options:
const { result, checkText } = useProfanityChecker({
allLanguages: true,
caseSensitive: false,
wordBoundaries: true,
allowObfuscatedMatch: true,
fuzzyToleranceLevel: 0.8,
severityLevels: true,
customWords: ['slur1', 'slur2']
});
New in v2.0.0: Detect obfuscated profanity like f@ck
, enable typo-matching, and return severity ratings. Use checkTextAsync()
for async environments.
Filter Class
Constructor
new Filter({
languages?: Language[],
allLanguages?: boolean,
caseSensitive?: boolean,
wordBoundaries?: boolean,
allowObfuscatedMatch?: boolean,
fuzzyToleranceLevel?: number,
customWords?: string[],
replaceWith?: string,
severityLevels?: boolean,
ignoreWords?: string[],
logProfanity?: boolean
});
Use the Filter
class to programmatically scan content (server-side or client-side).
- languages: Specific languages (e.g.,
['en']
). - allLanguages: Scan in 20+ supported languages.
- caseSensitive: Respect letter casing.
- wordBoundaries: Avoid partial matches (e.g.,
class
vs.ass
). - allowObfuscatedMatch: Catch disguised slurs like
a$$
,f@ck
. - fuzzyToleranceLevel: 0.5–1 range to detect typos and near matches.
- customWords: Add your own flagged terms.
- replaceWith: Replace matches with
***
or similar. - severityLevels: Return severity map per term.
- ignoreWords: Safelist terms to exclude.
- logProfanity: Log results to console for debugging.
Recommended for advanced use-cases where React hooks aren’t ideal.
useProfanityChecker Hook
A custom React hook for real-time text moderation in components.
Config Options
- languages: Array like
['en', 'fr']
. - allLanguages: Enable detection in all supported languages.
- caseSensitive: Match case exactly.
- wordBoundaries: Avoid substring matches.
- allowObfuscatedMatch: Detect leetspeak & disguised terms.
- fuzzyToleranceLevel: Typo sensitivity (e.g., 0.8).
- customWords: Add platform-specific slurs.
- replaceWith: Mask words in output.
- severityLevels: Enable severity-based moderation logic.
- ignoreWords: Whitelist words to exclude from detection.
- logProfanity: Output matches to console (dev mode).
- customActions: Run custom logic when a match is found.
Returns
result
: Scan result objectcheckText()
: Run a sync scancheckTextAsync()
: Run an async scan (e.g., server)reset()
: Clear last result
const {
result,
checkText,
checkTextAsync,
reset
} = useProfanityChecker({
allLanguages: true,
allowObfuscatedMatch: true,
fuzzyToleranceLevel: 0.85,
customWords: ['slur1', 'slur2'],
severityLevels: true
});
Integration
Getting started with Glin-Profanity takes just a few lines of code. Here's how to integrate it into your workflow:
- Install the package with
npm
oryarn
. - Import
useProfanityChecker
orFilter
. - Customize detection options: fuzzy matching, obfuscation, etc.
- Use
checkText()
orcheckTextAsync()
in forms, APIs, or streams.
Perfect for content forms, live chats, UGC pipelines, and AI agent moderation.
Benefits
Glin-Profanity gives your product superpowers in user protection and quality moderation:
- 🧠 AI-level Detection: Flags typos, leetspeak, and evasion attempts.
- 🧩 Custom Filters: Add your own terms, exceptions, or replace rules.
- 🌐 Global Support: Works in 20+ languages—out of the box.
- ⚡ Fast & Flexible: React hook or standalone class—lightweight and async-ready.
- 🔒 Clean UX: Eliminate offensive input at the source.