Skip to content

Commit

Permalink
The parser should also accept objects instead of strings only. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jul 17, 2012
1 parent dabe970 commit 8db75ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -85,4 +87,4 @@ Parser.prototype.parse = function(str){
}
return val;
});
};
};
9 changes: 8 additions & 1 deletion test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.