Permalink
Browse files

add .json extname to paths that omit it. Closes #10

  • Loading branch information...
tj committed Oct 14, 2012
1 parent 5d0325b commit 2d02cb73038bc8a1c7d99d39693e32015521956c
Showing with 8 additions and 0 deletions.
  1. +1 −0 lib/Parser.js
  2. +7 −0 test/parser.js
View
@@ -60,6 +60,7 @@ Parser.prototype.clone = function(){
Parser.prototype.read = function(path){
this.path = path;
+ if (!~path.indexOf('.json')) path += '.json';
return this.parse(fs.readFileSync(path, 'utf8'));
};
View
@@ -29,6 +29,13 @@ describe('Parser', function(){
var obj = parser.read('test/fixtures/config.json');
obj.should.eql({ foo: 'BAR', bar: 'BAZ' });
})
+
+ it('should append .json when missing', function(){
+ var parser = new Parser;
+ parser.use(function(key, val){ return val.toUpperCase(); });
+ var obj = parser.read('test/fixtures/config');
+ obj.should.eql({ foo: 'BAR', bar: 'BAZ' });
+ })
})
describe('.parse(str)', function(){

3 comments on commit 2d02cb7

@rauchg

This comment has been minimized.

Show comment Hide comment
@rauchg

rauchg Oct 14, 2012

hawt

hawt

@tj

This comment has been minimized.

Show comment Hide comment
@tj

tj Oct 14, 2012

Owner

i love when you can copy/paste a test and change one thing haha

Owner

tj replied Oct 14, 2012

i love when you can copy/paste a test and change one thing haha

@rauchg

This comment has been minimized.

Show comment Hide comment
@rauchg

rauchg Oct 14, 2012

dat feel

dat feel

Please sign in to comment.