UNPKG

filter-kata

Version:

**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.

31 lines (30 loc) 805 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FilterKata = void 0; class FilterKata { constructor() { this.jorok = []; } tambah(kataList) { this.jorok.push(...kataList); } cek(teks) { const lower = teks.toLowerCase(); return this.jorok.some(kata => lower.includes(kata)); } sensor(teks, mask = '*') { let hasil = teks; this.jorok.forEach(kata => { const regex = new RegExp(kata, 'gi'); hasil = hasil.replace(regex, mask.repeat(kata.length)); }); return hasil; } daftar() { return [...this.jorok]; } hapus(kataList) { this.jorok = this.jorok.filter(k => !kataList.includes(k)); } } exports.FilterKata = FilterKata;