-
Notifications
You must be signed in to change notification settings - Fork 3
/
profanityFilter.js
41 lines (31 loc) · 1.31 KB
/
profanityFilter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Thanks to Kano Computing for profanity list. https://github.com/KanoComputing/nodejs-profanity-util/
var profanity = {
badWords: [],
clean: function(string, escapeAsterisks = false) {
while (profanity.badWords == []) {}
var input = string.split(" ");
var returns = "";
for (var i = 0; i < input.length; i++) {
if ($.inArray(input[i].toLowerCase().replace(/[.,\/\\|¦¬@#!£$€%\^&\*;:{}+=\-_'"`~()\[\]\<\>]/g,""), profanity.badWords) > -1) {
returns += Array(input[i].length + 1).join(escapeAsterisks ? "\\*" : "*") + " ";
} else {
returns += input[i] + " ";
}
}
return returns.substring(0, returns.length - 1);
},
isRude: function(string) {
while (profanity.badWords == []) {}
var input = string.split(" ");
var returns = false;
for (var i = 0; i < input.length; i++) {
if ($.inArray(input[i].toLowerCase().replace(/[.,\/\\|¦¬@#!£$€%\^&\*;:{}+=\-_'"`~()\[\]\<\>]/g,""), profanity.badWords) > -1) {
returns = true;
}
}
return returns;
}
}
$.getJSON("https://raw.githubusercontent.com/KanoComputing/nodejs-profanity-util/master/lib/swearwords.json", function(data) {
profanity.badWords = data;
});