From 226965663c54e9476a5c23c1188f836fa6b6553a Mon Sep 17 00:00:00 2001 From: webmech Date: Tue, 23 Oct 2018 14:05:39 -0400 Subject: [PATCH] refactor(*): simplify methods for adding and removing words https://github.com/web-mech/badwords/pull/45 https://github.com/web-mech/badwords/pull/45 --- lib/badwords.js | 8 ++++---- test/removeWords.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/badwords.js b/lib/badwords.js index b0b84a0..f93953e 100644 --- a/lib/badwords.js +++ b/lib/badwords.js @@ -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) { @@ -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); }; diff --git a/test/removeWords.js b/test/removeWords.js index d8ac2ff..067bc84 100644 --- a/test/removeWords.js +++ b/test/removeWords.js @@ -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');