diff --git a/index.js b/index.js index 4c66afa..d6a6529 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,9 @@ function format(fmt) { */ exports.string = function(val){ + if (typeof val === 'object') { + return JSON.stringify(val) + } return null == val ? '' : String(val); }; diff --git a/test/index.js b/test/index.js index 10baaa8..6aef295 100644 --- a/test/index.js +++ b/test/index.js @@ -52,6 +52,7 @@ describe('escape.string(val)', function(){ escape.string().should.equal(''); escape.string(0).should.equal('0'); escape.string(15).should.equal('15'); + escape.string({"hello":"bye"}).should.equal('{"hello":"bye"}') escape.string('something').should.equal('something'); }) })