Regex as env separator (#288)

* use regexp as env separator (support shorthand specification)

* add test to cover the env separator
Adrien Becchis 2017-11-05 02:30:56 +01:00 committed by Matt Hamann
parent 16667be6f3
commit 01f25fa423
2 changed files with 27 additions and 1 deletions

View File

@ -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;
}
};

View File

@ -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": {
@ -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);