Skip to content

Commit

Permalink
Merge branch 'feature/env-uppercase' of https://github.com/nw/rc
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Mar 29, 2017
2 parents 13bca12 + c4d83bf commit 874c2e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ var env = exports.env = function (prefix, env) {
env = env || process.env
var obj = {}
var l = prefix.length
var regex = new RegExp("^"+prefix, "i");
for(var k in env) {
if((k.indexOf(prefix)) === 0) {
if(regex.test(k)) {

var keypath = k.substring(l).split('__')

Expand Down
8 changes: 7 additions & 1 deletion test/nested-env-vars.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

var n = 'rc'+Math.random()
var seed = Math.random();
var n = 'rc'+ seed;
var N = 'RC'+ seed;
var assert = require('assert')


Expand All @@ -18,6 +20,9 @@ process.env[n+'_someOpt__w__w__'] = 18629
// Leading '__' should ignore everything up to 'z'
process.env[n+'___z__i__'] = 9999

// should ignore case for config name section.
process.env[N+'_test_upperCase'] = 187

var config = require('../')(n, {
option: true
})
Expand All @@ -37,4 +42,5 @@ assert.equal(config.someOpt.z/*.x*/, 186577)
assert.equal(config.someOpt.w.w, 18629)
assert.equal(config.z.i, 9999)

assert.equal(config.test_upperCase, 187)

0 comments on commit 874c2e3

Please sign in to comment.