Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.

Commit 173d0ff

Browse files
author
Aleksey Smolenchuk
committed
allow for array-type keys in .set()
1 parent 35d430c commit 173d0ff

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function fetchConfigSync(dirname, opts) {
186186
}
187187

188188
function setKey(keyPath, value) {
189-
if (typeof keyPath !== 'string') {
189+
if (typeof keyPath !== 'string' && !Array.isArray(keyPath)) {
190190
throw InvalidKeyPath({
191191
keyPath: keyPath
192192
});

test/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,15 @@ test('config.set()', function (assert) {
248248
config.set('key', 'value');
249249
config.set('nested.key', 'value2');
250250
config.set('nested.key3', 'value3');
251-
252-
assert.equal(config.get('key'), 'value');
253-
assert.equal(config.get('nested.key'), 'value2');
254-
assert.equal(config.get('nested.key3'), 'value3');
251+
config.set(['nested', 'key4'], 'value4');
252+
config.set(['nested', 'key.with.dots5'], 'value5');
253+
254+
assert.equal(config.get('key'), 'value', 'flat key');
255+
assert.equal(config.get('nested.key'), 'value2', 'nested key');
256+
assert.equal(config.get('nested.key3'), 'value3', 'child nested key');
257+
assert.equal(config.get('nested.key4'), 'value4', 'array key');
258+
assert.equal(config.get(['nested', 'key.with.dots5']),
259+
'value5', 'array key with dots');
255260

256261
assert.end();
257262
});

0 commit comments

Comments
 (0)