Skip to content

Commit

Permalink
add env() plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 28, 2012
1 parent 248f8e2 commit 64c0b8e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/eson.js
Expand Up @@ -22,6 +22,7 @@ exports.version = '0.0.1';
*/

exports.ms = require('./plugins/ms');
exports.env = require('./plugins/env');
exports.glob = require('./plugins/glob');
exports.bools = require('./plugins/bools');
exports.replace = require('./plugins/replace');
Expand Down
9 changes: 9 additions & 0 deletions lib/plugins/env.js
@@ -0,0 +1,9 @@

/**
* Allow environment variables to take precedence over `val`.
*/

module.exports = function(key, val){
var name = key.toUpperCase().split(' ').join('_');
return process.env[name] || val;
};
2 changes: 1 addition & 1 deletion test/bools.js
Expand Up @@ -2,7 +2,7 @@
var Parser = require('../')
, bools = Parser.bools;

describe('ms', function(){
describe('bools', function(){
it('should parse string bool representations', function(){
bools('', 'yes').should.be.true;
bools('', 'enabled').should.be.true;
Expand Down
13 changes: 13 additions & 0 deletions test/env.js
@@ -0,0 +1,13 @@

var Parser = require('../')
, env = Parser.env;

describe('env', function(){
it('should allow setting environment variables', function(){
env('foo', 'bar').should.equal('bar');
process.env.FOO = 'baz';
env('foo', 'bar').should.equal('baz');
process.env.DEV_UI = 'yes';
env('dev ui', 'no').should.equal('yes');
})
})

0 comments on commit 64c0b8e

Please sign in to comment.