Skip to content

Commit 235121d

Browse files
committed
fix(*): update removeWords functionality to be case-insensitive
#50
1 parent b398740 commit 235121d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/badwords.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Filter {
3131
return this.list
3232
.filter((word) => {
3333
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi');
34-
return !this.exclude.includes(word) && wordExp.test(string);
34+
return !this.exclude.includes(word.toLowerCase()) && wordExp.test(string);
3535
})
3636
.length > 0 || false;
3737
}
@@ -65,19 +65,21 @@ class Filter {
6565

6666
this.list.push(...words);
6767

68-
words.forEach((word) => {
69-
if (this.exclude.includes(word)) {
70-
this.exclude.splice(this.exclude.indexOf(word), 1);
71-
}
72-
});
68+
words
69+
.map(word => word.toLowerCase())
70+
.forEach((word) => {
71+
if (this.exclude.includes(word)) {
72+
this.exclude.splice(this.exclude.indexOf(word), 1);
73+
}
74+
});
7375
}
7476

7577
/**
7678
* Add words to whitelist filter
7779
* @param {...string} word - Word(s) to add to whitelist.
7880
*/
7981
removeWords() {
80-
this.exclude.push(...Array.from(arguments));
82+
this.exclude.push(...Array.from(arguments).map(word => word.toLowerCase()));
8183
}
8284
}
8385

0 commit comments

Comments
 (0)