Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add env() plugin

  • Loading branch information...
commit 64c0b8eaaac7bf8f4fb41c0b08733b5d428142dd 1 parent 248f8e2
@tj authored
View
1  lib/eson.js
@@ -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
9 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;
+};
View
2  test/bools.js
@@ -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
13 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');
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.