-
Notifications
You must be signed in to change notification settings - Fork 0
/
tarnationFixer.js
62 lines (48 loc) · 1.74 KB
/
tarnationFixer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const fs = require('fs');
module.exports.Fixer = class Fixer {
constructor(censoredPhrases) {
this.specialCharExp = /[\.\^\$\*\+\?\(\)\[\{\\\|\-]/;
this.globalSpecialCharExp = new RegExp(this.specialCharExp, 'g');
this.censoredPhrases = censoredPhrases;
this.verifyPhrases();
}
verifyPhrases()
{
for (const phraseKey in this.censoredPhrases)
{
//console.log(`Key: ${key}, Value: ${this.censoredPhrases[key]}`)
if (this.specialCharExp.test(phraseKey))
{
//console.log('found special chars!')
let newPhraseKey = phraseKey.replace(this.globalSpecialCharExp, "")
this.censoredPhrases[newPhraseKey] = this.censoredPhrases[phraseKey]
//console.log(`Deleted old key. New key: ${newPhraseKey}`)
delete this.censoredPhrases[phraseKey];
}
}
console.log('Verified phrases.')
/*
console.log('final results:')
for (const phraseKey in this.censoredPhrases)
{
console.log(`Key: ${phraseKey}, Value: ${this.censoredPhrases[phraseKey]}`)
}
*/
}
checkForBadPhrases(string) {
let result = string.toLowerCase();
for (let i = 0; i < Object.keys(this.censoredPhrases).length; i++)
{
if (result.includes(Object.keys(this.censoredPhrases)[i])) return true
}
return false;
}
replaceBadPhrases(string) {
let result = string;
for (const phraseKey in this.censoredPhrases)
{
result = result.replace(new RegExp(phraseKey, 'gi',), this.censoredPhrases[phraseKey]);
}
return result;
}
}