Skip to content

Commit

Permalink
Regex as env separator (#288)
Browse files Browse the repository at this point in the history
* use regexp as env separator (support shorthand specification)

* add test to cover the env separator
  • Loading branch information
AdrieanKhisbe authored and Matt Hamann committed Dec 18, 2017
1 parent 16667be commit 01f25fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nconf/stores/env.js
Expand Up @@ -35,7 +35,7 @@ var Env = exports.Env = function (options) {
if (options instanceof Array) {
this.whitelist = options;
}
if (typeof(options) === 'string') {
if (typeof(options) === 'string' || options instanceof RegExp) {
this.separator = options;
}
};
Expand Down
26 changes: 26 additions & 0 deletions test/complete-test.js
Expand Up @@ -23,6 +23,8 @@ process.env.NODE_ENV = 'debug';
process.env.FOOBAR = 'should not load';
process.env.json_array = JSON.stringify(['foo', 'bar', 'baz']);
process.env.json_obj = JSON.stringify({foo: 'bar', baz: 'foo'});
process.env.NESTED__VALUE = 'nested';
process.env.NESTED___VALUE_EXTRA_LODASH = '_nested_';

vows.describe('nconf/multiple-stores').addBatch({
"When using the nconf with multiple providers": {
Expand Down Expand Up @@ -297,4 +299,28 @@ 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 bad transform:fn": {
topic: function () {

var that = this;
helpers.cp(complete, completeTest, function () {
try {
nconf.env({ separator: /__+/ });
that.callback();
} catch (err) {
that.callback(null, err);
}
});
}, "env vars": {
"can access to nested values": function(err) {
assert.deepEqual(nconf.get('NESTED'), {VALUE:'nested', VALUE_EXTRA_LODASH: '_nested_'});
}
}
},
teardown: function () {
nconf.remove('env');
}
}).export(module);

0 comments on commit 01f25fa

Please sign in to comment.