From 6634c792520cef2afc482f2b7c26617f6e75c8b8 Mon Sep 17 00:00:00 2001 From: andrewsokolov Date: Fri, 20 Nov 2015 10:30:27 +0200 Subject: [PATCH] Ability to set multiple properties with object --- index.js | 8 +++++++- readme.md | 4 ++++ test.js | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a0541b1..70c4580 100644 --- a/index.js +++ b/index.js @@ -83,7 +83,13 @@ Configstore.prototype.get = function (key) { Configstore.prototype.set = function (key, val) { var config = this.all; - config[key] = val; + if (arguments.length === 1) { + Object.keys(key).forEach(function (k) { + config[k] = key[k]; + }); + } else { + config[key] = val; + } this.all = config; }; diff --git a/readme.md b/readme.md index 3a4d4c9..3235730 100644 --- a/readme.md +++ b/readme.md @@ -64,6 +64,10 @@ Store the config at `$CONFIG/package-name/config.json` instead of the default `$ Set an item. +### config.set(object) + +Set multiple items at once. + ### config.get(key) Get an item. diff --git a/test.js b/test.js index 7e4731d..500c289 100644 --- a/test.js +++ b/test.js @@ -16,6 +16,15 @@ it('.set() and .get()', function () { assert.equal(this.conf.get('foo'), 'bar'); }); +it('.set() with object and .get()', function () { + this.conf.set({ + foo1: 'bar1', + foo2: 'bar2' + }); + assert.equal(this.conf.get('foo1'), 'bar1'); + assert.equal(this.conf.get('foo2'), 'bar2'); +}); + it('.del()', function () { this.conf.set('foo', 'bar'); this.conf.del('foo');