Skip to content

Commit

Permalink
Merge pull request #29 from andrewsokolov/task/ability-to-set-multipl…
Browse files Browse the repository at this point in the history
…e-properties-with-object

Ability to set multiple properties with object
  • Loading branch information
hemanth committed Dec 8, 2015
2 parents 2af34ad + 6634c79 commit 93790aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -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;
};

Expand Down
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test.js
Expand Up @@ -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');
Expand Down

0 comments on commit 93790aa

Please sign in to comment.