Skip to content

Commit

Permalink
refactor(*): simplify methods for adding and removing words
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mech committed Oct 23, 2018
1 parent 1ab43a8 commit 2269656
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/badwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var Filter = (function () {
* Add words to blacklist filter / remove words from whitelist filter
* @param {(string|string[])}
*/
Filter.prototype.addWords = function addWords(words) {
words = (words instanceof Array) ? words : [words];
Filter.prototype.addWords = function addWords() {
let words = Array.from(arguments);
this.list = this.list.concat(words);

words.forEach(function (word) {
Expand All @@ -90,10 +90,10 @@ var Filter = (function () {

/**
* Add words to whitelist filter
* @param {...string} word - Word to add to whitelist.
* @param {(string|string[])} word - Word to add to whitelist.
*/
Filter.prototype.removeWords = function removeWords() {
var words = Array.prototype.slice.call(arguments);
let words = Array.from(arguments);
this.exclude.push.apply(this.exclude, words);
};

Expand Down
3 changes: 2 additions & 1 deletion test/removeWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var Filter = require('../lib/badwords.js'),
describe('filter', function(){
describe('removeWords',function(){
it("Should allow you to remove words from the filter blacklist and no longer filter them",function(){
filter.removeWords('hells');
let removingWords = ['hells', 'yea'];
filter.removeWords(...removingWords);
assert(filter.clean('This is a hells good test') === 'This is a hells good test');
filter.addWords('hells');
assert(filter.clean('This is a hells good test') === 'This is a ***** good test');
Expand Down

0 comments on commit 2269656

Please sign in to comment.