Regex as env separator (#288)
* use regexp as env separator (support shorthand specification) * add test to cover the env separator
This commit is contained in:
parent
e5db2ef6d7
commit
467ab753c8
2 changed files with 27 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
Loading…
Reference in a new issue