Comparing version 1.6.5 to 2.0.0
@@ -5,2 +5,22 @@ # Change Log | ||
<a name="2.0.0"></a> | ||
# [2.0.0](https://github.com/web-mech/badwords/compare/v1.6.5...v2.0.0) (2018-10-23) | ||
### Documentation | ||
* update documentation. add requirements for using lib moving forward ([9b2831d](https://github.com/web-mech/badwords/commit/9b2831d)) | ||
### Features | ||
* **profane:** support profane phrases and well as words ([995ea1e](https://github.com/web-mech/badwords/commit/995ea1e)) | ||
### BREAKING CHANGES | ||
* moving into es2016+ language features | ||
<a name="1.6.5"></a> | ||
@@ -7,0 +27,0 @@ ## [1.6.5](https://github.com/web-mech/badwords/compare/v1.6.4...v1.6.5) (2018-10-23) |
var localList = require('./lang.json').words; | ||
var baseList = require('badwords-list').array; | ||
var Filter = (function() { | ||
var Filter = (function () { | ||
/** | ||
@@ -28,8 +28,7 @@ * Filter constructor. | ||
Filter.prototype.isProfane = function isProfane(string) { | ||
return string | ||
.split(/\b/) | ||
.map(function(w) { | ||
return w.toLowerCase().replace(this.regex, ''); | ||
return this.list | ||
.filter(function (word) { | ||
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi'); | ||
return !this.exclude.includes(word) && wordExp.test(string); | ||
}, this) | ||
.filter(this.isProfaneLike, this) | ||
.shift() || false; | ||
@@ -52,6 +51,6 @@ }; | ||
return this.list | ||
.map(function(w) { | ||
.map(function (w) { | ||
return new RegExp('^' + w.replace(/(\W)/g, '\\$1') + '$', 'gi'); | ||
}, this) | ||
.reduce(function(outcome, wordExp) { | ||
.reduce(function (outcome, wordExp) { | ||
return outcome || wordExp.test(word); | ||
@@ -74,3 +73,3 @@ }, false); | ||
Filter.prototype.clean = function clean(string) { | ||
return string.split(/\b/).map(function(word) { | ||
return string.split(/\b/).map(function (word) { | ||
return this.isProfane(word) ? this.replaceWord(word) : word; | ||
@@ -83,3 +82,3 @@ }.bind(this)).join(''); | ||
* @param {(string|string[])} | ||
*/ | ||
*/ | ||
Filter.prototype.addWords = function addWords(words) { | ||
@@ -89,4 +88,4 @@ words = (words instanceof Array) ? words : [words]; | ||
words.forEach(function(word) { | ||
if(!!~this.exclude.indexOf(word)) { | ||
words.forEach(function (word) { | ||
if (!!~this.exclude.indexOf(word)) { | ||
this.exclude.splice(this.exclude.indexOf(word), 1); | ||
@@ -100,3 +99,3 @@ } | ||
* @param {...string} word - Word to add to whitelist. | ||
*/ | ||
*/ | ||
Filter.prototype.removeWords = function removeWords() { | ||
@@ -103,0 +102,0 @@ var words = Array.prototype.slice.call(arguments); |
{ | ||
"name": "bad-words", | ||
"version": "1.6.5", | ||
"version": "2.0.0", | ||
"description": "A javascript filter for bad words", | ||
@@ -5,0 +5,0 @@ "main": "./lib/badwords", |
@@ -9,2 +9,6 @@ # bad-words | ||
## Requirements | ||
As of version 2, requires you either have an environment that understands ES2016 and beyond or a transpiler like Babel. | ||
## Installation | ||
@@ -11,0 +15,0 @@ |
@@ -37,4 +37,9 @@ require('assert'); | ||
assert(filter.isProfane("that person is an\nasshole")); | ||
}) | ||
}); | ||
it('Should detect bad word phrases', function () { | ||
filter.addWords('oh no'); | ||
assert(filter.isProfane("oh no! this is profane!")); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28260
763
182