Changed to as it's more accurate
This commit is contained in:
parent
e15f787940
commit
3c08fad1c9
3 changed files with 7 additions and 7 deletions
|
@ -165,14 +165,14 @@ Responsible for loading the values parsed from `process.env` into the configurat
|
||||||
//
|
//
|
||||||
nconf.env('__');
|
nconf.env('__');
|
||||||
// Get the value of the env variable 'database__host'
|
// Get the value of the env variable 'database__host'
|
||||||
var dbHost = nconf.get('database:host');
|
var dbHost = nconf.get('database:host');
|
||||||
|
|
||||||
//
|
//
|
||||||
// Or use both options
|
// Or use both options
|
||||||
//
|
//
|
||||||
nconf.env({
|
nconf.env({
|
||||||
separator: '__',
|
separator: '__',
|
||||||
filter: ['database__host', 'only', 'load', 'these', 'values']
|
whitelist: ['database__host', 'only', 'load', 'these', 'values']
|
||||||
});
|
});
|
||||||
var dbHost = nconf.get('database:host');
|
var dbHost = nconf.get('database:host');
|
||||||
```
|
```
|
||||||
|
|
|
@ -21,10 +21,10 @@ var Env = exports.Env = function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.type = 'env';
|
this.type = 'env';
|
||||||
this.readOnly = true;
|
this.readOnly = true;
|
||||||
this.filter = options.filter || [];
|
this.whitelist = options.whitelist || [];
|
||||||
this.separator = options.separator || '';
|
this.separator = options.separator || '';
|
||||||
if (options instanceof Array) {
|
if (options instanceof Array) {
|
||||||
this.filter = options;
|
this.whitelist = options;
|
||||||
}
|
}
|
||||||
if (typeof(options) === 'string') {
|
if (typeof(options) === 'string') {
|
||||||
this.separator = options;
|
this.separator = options;
|
||||||
|
@ -52,7 +52,7 @@ Env.prototype.loadEnv = function () {
|
||||||
|
|
||||||
this.readOnly = false;
|
this.readOnly = false;
|
||||||
Object.keys(process.env).filter(function (key) {
|
Object.keys(process.env).filter(function (key) {
|
||||||
return !self.filter.length || self.filter.indexOf(key) !== -1;
|
return !self.whitelist.length || self.whitelist.indexOf(key) !== -1;
|
||||||
}).forEach(function (key) {
|
}).forEach(function (key) {
|
||||||
if (self.separator) {
|
if (self.separator) {
|
||||||
self.set(common.key.apply(common, key.split(self.separator)), process.env[key]);
|
self.set(common.key.apply(common, key.split(self.separator)), process.env[key]);
|
||||||
|
|
|
@ -16,8 +16,8 @@ vows.describe('nconf/stores/env').addBatch({
|
||||||
"should have the correct methods defined": function (env) {
|
"should have the correct methods defined": function (env) {
|
||||||
assert.isFunction(env.loadSync);
|
assert.isFunction(env.loadSync);
|
||||||
assert.isFunction(env.loadEnv);
|
assert.isFunction(env.loadEnv);
|
||||||
assert.isArray(env.filter);
|
assert.isArray(env.whitelist);
|
||||||
assert.lengthOf(env.filter, 0);
|
assert.lengthOf(env.whitelist, 0);
|
||||||
assert.equal(env.separator, '');
|
assert.equal(env.separator, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue