Permalink
Browse files

The parser should also accept objects instead of strings only. Fixes #6

  • Loading branch information...
1 parent dabe970 commit 8db75ed1cca8f17ba3c4363dd154543d3922980f @3rd-Eden committed Jul 17, 2012
Showing with 11 additions and 2 deletions.
  1. +3 −1 lib/Parser.js
  2. +8 −1 test/parser.js
View
4 lib/Parser.js
@@ -75,6 +75,8 @@ Parser.prototype.parse = function(str){
var self = this
, plugins = this.plugins;
+ if (typeof str !== 'string') str = JSON.stringify(str);
+
return JSON.parse(str, function(key, val){
var plugin, ret;
if ('' === key) return val;
@@ -85,4 +87,4 @@ Parser.prototype.parse = function(str){
}
return val;
});
-};
+};
View
9 test/parser.js
@@ -70,5 +70,12 @@ describe('Parser', function(){
parser.parse('{ "foo": "bar" }')
.should.eql({ foo: 'hey' });
})
+
+ it('should also parse objects', function(){
+ var parser = new Parser
+ , data = { foo: 'bar' };
+
+ parser.parse(data).should.eql(data);
+ })
})
-})
+})

0 comments on commit 8db75ed

Please sign in to comment.