@2toad/profanity
Version:
A JavaScript profanity filter
25 lines • 756 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Lookup {
constructor(wholeWord) {
this.wholeWord = wholeWord;
}
exists(text) {
this.regex.lastIndex = 0;
return this.regex.test(text);
}
removeWords(words) {
this.words = this.words.filter(x => !words.includes(x));
this.buildRegex();
}
addWords(words) {
this.words = this.words.concat(words);
this.buildRegex();
}
buildRegex() {
const pattern = `${this.wholeWord ? '\\b' : ''}(${this.words.join('|')})${this.wholeWord ? '\\b' : ''}`;
this.regex = new RegExp(pattern, 'ig');
}
}
exports.Lookup = Lookup;
//# sourceMappingURL=lookup.js.map