Skip to content

Commit

Permalink
transformer can now return an undefined key (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe authored and mhamann committed Nov 4, 2017
1 parent 81ce0be commit b9321b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nconf/common.js
Expand Up @@ -154,7 +154,7 @@ common.transform = function(map, fn) {

if (!result) {
return null;
} else if (result.key && typeof result.value !== 'undefined') {
} else if (result.key) {
return result;
}

Expand Down
28 changes: 28 additions & 0 deletions test/complete-test.js
Expand Up @@ -242,6 +242,34 @@ vows.describe('nconf/multiple-stores').addBatch({
teardown: function () {
nconf.remove('env');
}
}).addBatch({
// Threw this in it's own batch to make sure it's run separately from the
// sync check
"When using env with a transform:fn that return an undefined value": {
topic: function () {

function testTransform(obj) {
if (obj.key === 'FOO') {
return {key: 'FOO', value: undefined};
}

return obj;
}

var that = this;
helpers.cp(complete, completeTest, function () {
nconf.env({ transform: testTransform });
that.callback();
});
}, "env vars": {
"port key/value properly transformed": function() {
assert.equal(typeof nconf.get('FOO'), 'undefined');
}
}
},
teardown: function () {
nconf.remove('env');
}
}).addBatch({
// Threw this in it's own batch to make sure it's run separately from the
// sync check
Expand Down

0 comments on commit b9321b2

Please sign in to comment.