From 01f25fa423f68319d4e0a47ee1349579c84b14b0 Mon Sep 17 00:00:00 2001 From: Adrien Becchis Date: Sun, 5 Nov 2017 02:30:56 +0100 Subject: [PATCH] Regex as env separator (#288) * use regexp as env separator (support shorthand specification) * add test to cover the env separator --- lib/nconf/stores/env.js | 2 +- test/complete-test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/nconf/stores/env.js b/lib/nconf/stores/env.js index d500c3e..12dd3b4 100644 --- a/lib/nconf/stores/env.js +++ b/lib/nconf/stores/env.js @@ -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; } }; diff --git a/test/complete-test.js b/test/complete-test.js index d1f9462..3125388 100644 --- a/test/complete-test.js +++ b/test/complete-test.js @@ -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); \ No newline at end of file