Comparing version 1.0.2 to 1.1.0
21
index.js
@@ -17,6 +17,2 @@ /** | ||
* Replaces bad words with asterisks | ||
* | ||
* @param {string} words - String of words to filter | ||
* | ||
* @returns {string} String of words (censored). | ||
**/ | ||
@@ -35,3 +31,20 @@ filter: (words, callback) => { | ||
}); | ||
}, | ||
/** | ||
* True if swearword is found, false if not | ||
**/ | ||
hasSwears: (words, callback) => { | ||
fs.readFile(path.join(__dirname,'swearwords.txt'), 'utf8', (err, data) => { | ||
if (err) throw err | ||
var b = false | ||
// Trim down file input to remove weird encoding/returns | ||
var lines = data.replace(new RegExp('\r','g'),'').split('\n') | ||
for (var i = 0; i < lines.length; i++) { | ||
if(words.indexOf(lines[i]) > -1) { | ||
b = true | ||
} | ||
} | ||
callback(b) | ||
}); | ||
} | ||
} |
{ | ||
"name": "no-swears", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Filter swearwords out of your strings automagically", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
no-swears | ||
no-swears | ||
=== | ||
@@ -6,2 +6,4 @@ | ||
[](https://badge.fury.io/js/no-swears) | ||
Very simple package for censoring swear words from JavaScript strings, | ||
@@ -27,6 +29,17 @@ replacing offending words with "\*\*\*\*". | ||
noswears.filter(badString, goodString => { | ||
console.log(goodString) | ||
console.log(goodString) // "this is a ****ing string" | ||
}) | ||
``` | ||
More options coming soon :) | ||
### hasSwears() | ||
This just returns true or false to callback depending on whether the passed string | ||
contains a swear word | ||
```javascript | ||
let badString = "this is a bitching string" | ||
noswears.hasSwears(badString, swearBool => { | ||
console.log(swearBool) // true | ||
}) | ||
``` |
11
test.js
@@ -8,3 +8,3 @@ 'use strict' | ||
noswears.filter(badString, goodString => { | ||
console.log("Want string \"**** brain**** is weird\", got", goodString) | ||
console.log("Testing filter\nWant string \"**** brain**** is weird\", got", goodString) | ||
if (goodString == "**** brain**** is weird") { | ||
@@ -15,2 +15,11 @@ console.log("✔ Success!") | ||
} | ||
}) | ||
noswears.hasSwears(badString, swearBool => { | ||
console.log("\nTesting hasSwears\nWant true, got", swearBool) | ||
if (swearBool == true) { | ||
console.log("✔ Success!") | ||
} else { | ||
console.log("✖ Failed!") | ||
} | ||
}) |
5625
86
43