diff --git a/src/index.js b/src/index.js index cf38ddc..9743a8f 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { diff --git a/test/index.spec.js b/test/index.spec.js index 914eccd..81defcc 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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; + }); +});