From 9539517098fe9c448b66661d09f1ce4442cfdcec Mon Sep 17 00:00:00 2001 From: Siddharth Kannan Date: Tue, 9 Jun 2015 11:56:21 +0200 Subject: [PATCH] Close #22 PR: Add clear function. --- index.js | 4 ++++ readme.md | 4 ++++ test.js | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/index.js b/index.js index 35992e5..19fbe8c 100644 --- a/index.js +++ b/index.js @@ -86,4 +86,8 @@ Configstore.prototype.del = function (key) { this.all = config; }; +Configstore.prototype.clear = function () { + this.all = {}; +} + module.exports = Configstore; diff --git a/readme.md b/readme.md index 395fc2e..e9e074b 100644 --- a/readme.md +++ b/readme.md @@ -38,6 +38,10 @@ Get an item. Delete an item. +### .clear() + +Delete all items. + ### .all Get all items as an object or replace the current config with an object: diff --git a/test.js b/test.js index bd4213f..b117f09 100644 --- a/test.js +++ b/test.js @@ -21,6 +21,13 @@ it('.del()', function () { assert.notEqual(this.conf.get('foo'), 'bar'); }); +it('.clear()', function(){ + this.conf.set('foo', 'bar'); + this.conf.set('foo1', 'bar1'); + this.conf.clear(); + assert.equal(this.conf.size, 0); +}); + it('.all', function () { this.conf.set('foo', 'bar'); assert.equal(this.conf.all.foo, 'bar');