Skip to content

Commit

Permalink
feat(dictionary): add removeDictionary method to support dictional re…
Browse files Browse the repository at this point in the history
…moval
  • Loading branch information
jojoee committed Nov 7, 2022
1 parent 525f854 commit 1f69a81
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,22 @@ var LeoProfanity = {

return this;
},

/**
* Remove dictionary
*
* @example
* // remove dictionary
* filter.removeDictionary('th')
*
* @public
* @param {string} name dictionary name
*/
removeDictionary: function (name) {
delete this.wordDictionary[name]

return this;
},
};

if (typeof module !== 'undefined' && module.exports != null) {
Expand Down
24 changes: 24 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,27 @@ describe('addDictionary', function () {
expect(filter.list().length).to.equal(words.length);
});
});

describe('removeDictionary', function () {
it('should remove existing dictionary', function () {
var name = 'fr';
filter.loadDictionary(name);
expect(filter.list().length).to.not.equal(0);

filter.removeDictionary(name);

expect(name in filter.wordDictionary).to.be.false;
});

it('should remove new dictionary', function () {
filter.loadDictionary()
var name = 'th'
var words = ['หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า']
filter.addDictionary(name, words);
expect(filter.list().length).to.equal(words.length);

filter.removeDictionary(name);

expect(name in filter.wordDictionary).to.be.false;
});
});

0 comments on commit 1f69a81

Please sign in to comment.