@rikatech/text-profanity
v1.1.3
Published
A fast, lightweight, and highly advanced profanity filter with comprehensive **Anti-Bypass** capabilities. Protects your text inputs across multiple languages (**English**, **Vietnamese**, and **Japanese**).
Readme
@rikatech/text-profanity
A fast, lightweight, and highly advanced profanity filter with comprehensive Anti-Bypass capabilities. Protects your text inputs across multiple languages (English, Vietnamese, and Japanese).
Installation
npm install @rikatech/text-profanityAnti-Bypass Features
This package doesn't just match words; it automatically untangles complex attempts by users to evade filters:
- Noise & Punctuation Ignored: Dots, spaces, symbols are skipped over (e.g.,
f.u.c.k-> caught). - Leetspeak (Teencode) Conversion: Numbers & symbols are reverted to letters (e.g.,
@->a,3->e,0->o,!->i). - Repeating Characters: Extended vowels and characters are collapsed (e.g.,
shiiiiiiitttt->shit). - Unaccented/Extended Latin Support: Strips extended Unicode and intelligently matches unaccented variations to native dictionary items (e.g.,
d mcatchesđ m). - Advanced Japanese Script Armor: Automatically folds Katakana to Hiragana (e.g.
シネ->しね), normalizes half-width characters, merges detached Dakuon (バカ->バカ->ばか), and bypasses long vowelsー.
Usage
import { WordFilter } from "@rikatech/text-profanity";
// Initialize with target languages (built-in options: 'en', 'vi', 'ja')
const filter = new WordFilter({
languages: ["en", "vi", "ja"],
placeholder: "*" // Default mask string
});
// 1. Check if text contains bad words
console.log(filter.hasBadWord("shiiiiiiit")); // Returns: true
console.log(filter.hasBadWord("hello world")); // Returns: false
// 2. Intelligent Masking (preserves text formatting & lengths)
console.log(filter.mask("you are a b.i.t.c.h"));
// Output: "you are a *********"
// 3. Add custom bad words programmatically
filter.addBadWords(["scam", "spam"]);
console.log(filter.mask("This is a scam website!"));
// Output: "This is a **** website!"Contributing and Tests
Written safely with TypeScript and rigorously tested with Jest parsing complex filter evasion scenarios.
npm run test