All Projects
FilterKata – Profanity Filter for TypeScript
FilterKata is a lightweight and customizable TypeScript class to detect and censor inappropriate or offensive words from text input. Perfect for chat systems, comment moderation, forums, and more.
Installation
Install via npm:
npm install filter-kata
Or using Yarn:
yarn add filter-kata
Usage
1. Import the class
import { FilterKata } from 'filter-kata';
2. Initialize the filter
const filter = new FilterKata();
3. Add offensive words
filter.tambah(['stupid', 'evil']);
4. Check if a text contains offensive words
const result = filter.cek('You are so stupid!');
console.log(result); // true
5. Censor the offensive words
const censored = filter.sensor('You are so stupid!');
console.log(censored); // You are so ******
You can customize the censor character:
filter.sensor('You are evil', '#'); // You are ####
6. Remove words from the filter
filter.hapus(['stupid']);
7. Get the current word list
console.log(filter.daftar()); // ['evil']
API Reference
| Method | Description |
|---|---|
tambah(kataList: string[]) | Add words to the filter |
cek(teks: string): boolean | Check if text contains offensive words |
sensor(teks: string, mask: string = '*') | Censor the offensive words in the text |
hapus(kataList: string[]) | Remove words from the filter list |
daftar(): string[] | Get the current list of filtered words |
Notes
- Case-insensitive matching (e.g. "Stupid" and "stupid" are both detected).
- Make sure to include all word variations you want to filter.
🪪 License
MIT © kikuk24
End of Project Documentation. Explore other works.