Skip to content

Commit

Permalink
add JSONparse alias
Browse files Browse the repository at this point in the history
don't stringify

this can be done with a sub-expression
  • Loading branch information
jonschlinkert committed Jan 25, 2017
1 parent cabbcba commit f01d96d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/number.js
Expand Up @@ -52,7 +52,8 @@ helpers.random = function(min, max) {
};

/**
* Abbreviate numbers to the given number of `precision`.
* Abbreviate numbers to the given number of `precision`. This is for
* general numbers, not size in bytes.
*
* @param {String} `number`
* @param {String} `precision`
Expand Down
18 changes: 16 additions & 2 deletions lib/object.js
Expand Up @@ -214,10 +214,17 @@ helpers.merge = function(context/*, objects, options*/) {
* @api public
*/

helpers.parseJSON = function(str, options) {
helpers.JSONparse = function(str, options) {
return options.fn(JSON.parse(str));
};

/**
* Alias for parseJSON. this will be
* deprecated in a future release
*/

helpers.parseJSON = helpers.JSONparse;

/**
* Pick properties from the context object.
*
Expand Down Expand Up @@ -256,9 +263,16 @@ helpers.pick = function(props, context, options) {
* @api public
*/

helpers.stringify = function(obj, indent) {
helpers.JSONstringify = function(obj, indent) {
if (!utils.isNumber(indent)) {
indent = 0;
}
return JSON.stringify(obj, null, indent);
};

/**
* Alias for JSONstringify. this will be
* deprecated in a future release
*/

helpers.stringify = helpers.JSONstringify;
2 changes: 1 addition & 1 deletion lib/url.js
Expand Up @@ -58,7 +58,7 @@ helpers.urlResolve = function(base, href) {
*/

helpers.urlParse = function(str) {
return JSON.stringify(url.parse(str));
return url.parse(str);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion test/url.js
Expand Up @@ -46,7 +46,7 @@ describe('url', function() {

describe('urlParse', function() {
it('should take a string, and return an object stringified to JSON.', function() {
var fn = hbs.compile('{{{urlParse "http://foo.com/bar/baz?key=value" "json"}}}');
var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value" "json")}}}');
JSON.parse(fn()).should.eql({
"protocol": "http:",
"slashes": true,
Expand Down

0 comments on commit f01d96d

Please sign in to comment.