Permalink
Browse files

add env() plugin

  • Loading branch information...
1 parent 248f8e2 commit 64c0b8eaaac7bf8f4fb41c0b08733b5d428142dd @tj committed Jun 28, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −0 lib/eson.js
  2. +9 −0 lib/plugins/env.js
  3. +1 −1 test/bools.js
  4. +13 −0 test/env.js
View
@@ -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');
View
@@ -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;
+};
View
@@ -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;
View
@@ -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.