Comparing version 1.1.1 to 1.1.2
70
index.js
@@ -1,3 +0,3 @@ | ||
/** | ||
* no-swears - Filer our swear words from your strings | ||
/** | ||
* no-swears - Filter out or detect swear words in your strings | ||
* | ||
@@ -9,43 +9,43 @@ * @author Gabriel Simmer <https://github.com/gmemstr> | ||
'use strict' | ||
"use strict"; | ||
const fs = require('fs') | ||
const path = require('path') | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
module.exports = { | ||
/** | ||
/** | ||
* Replaces bad words with asterisks | ||
**/ | ||
filter: (words, callback) => { | ||
var finalString = words | ||
swearList(lines => { | ||
for (var i = 0; i < lines.length; i++) { | ||
var bw = new RegExp(lines[i], 'gi') | ||
finalString = finalString.replace(bw, '****') | ||
} | ||
callback(finalString) | ||
}); | ||
}, | ||
/** | ||
filter: (words, callback) => { | ||
var finalString = words; | ||
swearList(lines => { | ||
for (var i = 0; i < lines.length; i++) { | ||
var bw = new RegExp(lines[i], "gi"); | ||
finalString = finalString.replace(bw, "*".repeat(lines[i].length)); | ||
} | ||
callback(finalString); | ||
}); | ||
}, | ||
/** | ||
* True if swearword is found, false if not | ||
**/ | ||
hasSwears: (words, callback) => { | ||
swearList(lines =>{ | ||
var b = false | ||
for (var i = 0; i < lines.length; i++) { | ||
if(words.indexOf(lines[i]) > -1) { | ||
b = true | ||
} | ||
} | ||
callback(b) | ||
}); | ||
} | ||
} | ||
hasSwears: (words, callback) => { | ||
swearList(lines => { | ||
var b = false; | ||
for (var i = 0; i < lines.length; i++) { | ||
if (words.indexOf(lines[i]) > -1) { | ||
b = true; | ||
} | ||
} | ||
callback(b); | ||
}); | ||
} | ||
}; | ||
var swearList = callback => { | ||
fs.readFile(path.join(__dirname,'swearwords.txt'), 'utf8', (err, data) => { | ||
if (err) throw err | ||
data = data.replace(new RegExp('\r','g'),'').split('\n') | ||
callback(data) | ||
}); | ||
} | ||
fs.readFile(path.join(__dirname, "swearwords.txt"), "utf8", (err, data) => { | ||
if (err) throw err; | ||
data = data.replace(new RegExp("\r", "g"), "").split("\n"); | ||
callback(data); | ||
}); | ||
}; |
{ | ||
"name": "no-swears", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Filter swearwords out of your strings automagically", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,2 +13,6 @@ no-swears | ||
```bash | ||
npm install --save no-swears | ||
``` | ||
```javascript | ||
@@ -15,0 +19,0 @@ 'use strict' |
39
test.js
@@ -1,23 +0,28 @@ | ||
'use strict' | ||
"use strict"; | ||
const noswears = require('./index') | ||
const noswears = require("./index"); | ||
let badString = "hell brainfuck is weird" | ||
let badString = "hell brainfuck is a weird bitch"; | ||
noswears.filter(badString, goodString => { | ||
console.log("Testing filter\nWant string \"**** brain**** is weird\", got", goodString) | ||
if (goodString == "**** brain**** is weird") { | ||
console.log("✔ Success!") | ||
} else { | ||
console.log("✖ Failed!") | ||
} | ||
}) | ||
var expected = "**** brain**** is a weird *****"; | ||
console.log( | ||
'Testing filter\nWant string "' + expected + '", got', | ||
goodString | ||
); | ||
if (goodString == expected) { | ||
console.log("✔ Success!"); | ||
} else { | ||
console.log("✖ Failed!"); | ||
} | ||
}); | ||
noswears.hasSwears(badString, swearBool => { | ||
console.log("\nTesting hasSwears\nWant true, got", swearBool) | ||
if (swearBool == true) { | ||
console.log("✔ Success!") | ||
} else { | ||
console.log("✖ Failed!") | ||
} | ||
}) | ||
console.log("\nTesting hasSwears\nWant true, got", swearBool); | ||
if (swearBool == true) { | ||
console.log("✔ Success!"); | ||
} else { | ||
console.log("✖ Failed!"); | ||
} | ||
}); | ||
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5782
8
98
47