UNPKG

cjs-bad-word-filter-ko

Version:

bad-word-filter-ko npm을 cjs버전으로 리메이크 한 것 입니다.

22 lines (18 loc) 592 B
const Filter = function() { this.list = require('./list.js').words; // words 배열을 직접 가져옵니다 }; Filter.prototype.clean = function(string) { const words = this.list; for (const word of words) { const regex = new RegExp(word, 'gi'); string = string.replace(regex, '*'.repeat(word.length)); } return string; }; Filter.prototype.addWords = function(...words) { this.list.push(...words); }; Filter.prototype.removeWords = function(...words) { this.list = this.list.filter(item => !words.includes(item)); }; module.exports = Filter;