super-profanity
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -162,15 +162,2 @@ (function (scope) { | ||
/* | ||
* Prevent white listed words of being detected. | ||
*/ | ||
function whiteListIndexes(replacedWord) { | ||
let indexes = []; | ||
if (replacedWord !== null) { | ||
for (let i = 0; i < replacedWord[0].length; i++) { | ||
indexes.push(replacedWord.index + i); | ||
} | ||
} | ||
return indexes; | ||
} | ||
class NoSwearing { | ||
@@ -263,3 +250,2 @@ constructor(swearList) { | ||
var detected = []; | ||
var whiteIndexes = []; // Whitelisted indexes | ||
@@ -271,8 +257,6 @@ for (var i = 0; i < text.length; i++) { | ||
if (watch.info === 0) { | ||
// Prevent white listed words | ||
let replacedWord = | ||
input.match(watch.wordOriginal) || | ||
input.replace(/[^a-zA-Z]/g, "").match(watch.wordOriginal); | ||
whiteIndexes.push(...whiteListIndexes(replacedWord)); | ||
// Remove white listed words. | ||
input = | ||
input.replace(/\W/g, "").replaceAll(watch.wordOriginal.replace(/\s/g, ""), "") || | ||
input; | ||
} | ||
@@ -304,4 +288,3 @@ | ||
(combinedHSounds.hasOwnProperty(text[i]) == false || text[i + 1] != "h") && | ||
(watch.info === 1 || watch.info === 2) && | ||
(!whiteIndexes.includes(index)) | ||
(watch.info === 1 || watch.info === 2) | ||
) { | ||
@@ -390,3 +373,2 @@ detected.push({ | ||
&& (watch.info === 1 || watch.info === 2) | ||
&& !whiteIndexes.includes(index) | ||
) { | ||
@@ -591,7 +573,5 @@ detected.push({ | ||
input.match(word.wordOriginal) || | ||
input.replace(/[^a-zA-Z]/g, "").match(word.wordOriginal); | ||
input.replace(/\W/g, "").match(word.wordOriginal.replace(/\s/g, "")); | ||
if (replacedWord !== null) { | ||
if (whiteIndexes.includes(replacedWord.index)) return; | ||
out.push({ | ||
@@ -598,0 +578,0 @@ deviations: deviations, |
@@ -176,2 +176,3 @@ { | ||
"en": { | ||
"but it": 0, | ||
"grass": 0, | ||
@@ -178,0 +179,0 @@ "homosexual": 0, |
{ | ||
"name": "super-profanity", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A profanity filter that lives up to its name.", | ||
@@ -35,2 +35,5 @@ "main": "profanity.js", | ||
}, | ||
"engines": { | ||
"node": ">=15.0.0" | ||
}, | ||
"exports": { | ||
@@ -37,0 +40,0 @@ ".": "./dist/profanity.js" |
179363
5174