Permalink
Browse files

add bools()

  • Loading branch information...
1 parent e3aa025 commit 1fd1cdc2bbe81e1542cdd6695121bb53d527e829 @tj committed Jun 28, 2012
Showing with 36 additions and 0 deletions.
  1. +4 −0 Readme.md
  2. +1 −0 lib/eson.js
  3. +17 −0 lib/plugins/bools.js
  4. +14 −0 test/bools.js
View
4 Readme.md
@@ -105,6 +105,10 @@ yields:
{ prod: { whatever: 'is', within: 'config/production.json' }}
```
+### eson.bools
+
+ Convert "yes", "no", "enabled", "disabled" into booleans.
+
### eson.replace(str, val)
The replace plugin allows you to replace arbitrary substrings, useful
View
1 lib/eson.js
@@ -23,6 +23,7 @@ exports.version = '0.0.1';
exports.ms = require('./plugins/ms');
exports.glob = require('./plugins/glob');
+exports.bools = require('./plugins/bools');
exports.replace = require('./plugins/replace');
exports.include = require('./plugins/include');
exports.dimensions = require('./plugins/dimensions');
View
17 lib/plugins/bools.js
@@ -0,0 +1,17 @@
+
+/**
+ * Convert "yes", "no", "enabled", "disabled" to booleans.
+ */
+
+module.exports = function(key, val){
+ switch (val) {
+ case 'yes':
+ case 'enabled':
+ return true;
+ case 'no':
+ case 'disabled':
+ return false;
+ default:
+ return val;
+ }
+};
View
14 test/bools.js
@@ -0,0 +1,14 @@
+
+var Parser = require('../')
+ , bools = Parser.bools;
+
+describe('ms', function(){
+ it('should parse string bool representations', function(){
+ bools('', 'yes').should.be.true;
+ bools('', 'enabled').should.be.true;
+ bools('', 'no').should.be.false;
+ bools('', 'disabled').should.be.false;
+ bools('', true).should.be.true;
+ bools('', 'other').should.be.equal('other');
+ })
+})

0 comments on commit 1fd1cdc

Please sign in to comment.