diff --git a/.travis.yml b/.travis.yml index efd82de1..ee8bff0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,5 @@ node_js: - '5' - '4' - '0.12' -before_script: - - npm install -g gulp-cli -script: gulp +allowed_failures: + node_js: '0.12' diff --git a/README.md b/README.md index 7c708747..1108d851 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ var math = helpers.math({ ## Categories -Currently **189 helpers** in **20 categories**: +Currently **190 helpers** in **20 categories**: * **[array](#array)** ([code](lib/array.js) | [unit tests](test/array.js)) * **[code](#code)** ([code](lib/code.js) | [unit tests](test/code.js)) @@ -392,9 +392,10 @@ Visit the: [code](lib/url.js) | [unit tests](test/url.js) | [issues](https://git * **[url_encode](#url_encode)** ([code](lib/url.js#L59) | [no tests]) * **[url_decode](#url_decode)** ([code](lib/url.js#L68) | [no tests]) * **[urlResolve](#urlResolve)** ([code](lib/url.js#L82) | [tests](test/url.js#L11)) -* **[urlParse](#urlParse)** ([code](lib/url.js#L94) | [tests](test/url.js#L45)) -* **[stripQuerystring](#stripQuerystring)** ([code](lib/url.js#L106) | [tests](test/url.js#L24)) -* **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L126) | [no tests]) +* **[urlParse](#urlParse)** ([code](lib/url.js#L97) | [tests](test/url.js#L45)) +* **[parseQueryString](#parseQueryString)** ([code](lib/url.js#L109) | [tests](test/url.js#L57)) +* **[stripQuerystring](#stripQuerystring)** ([code](lib/url.js#L121) | [tests](test/url.js#L24)) +* **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L141) | [no tests]) *** @@ -3007,16 +3008,28 @@ browser would for an anchor tag. * `href` **{String}** * `returns` **{String}** -### [{{urlParse}}](lib/url.js#L94) +### [{{urlParse}}](lib/url.js#L97) Parses a `url` string into an object. +If parseQueryString options is true it will parse the query string +of given `url`. **Params** * `str` **{String}**: URL string -* `returns` **{String}**: Returns stringified JSON +* `options` **{Options}**: Handlebars provided options object +* `returns` **{Object}**: Returns a parsed object -### [{{stripQuerystring}}](lib/url.js#L106) +### [{{parseQueryString}}](lib/url.js#L109) + +Parses a `queryString` string into an object. + +**Params** + +* `queryString` **{String}**: queryString +* `returns` **{Object}**: a parsed object + +### [{{stripQuerystring}}](lib/url.js#L121) Strip the query string from the given `url`. @@ -3025,7 +3038,7 @@ Strip the query string from the given `url`. * `url` **{String}** * `returns` **{String}**: the url without the queryString -### [{{stripProtocol}}](lib/url.js#L126) +### [{{stripProtocol}}](lib/url.js#L141) Strip protocol from a `url`. Useful for displaying media that may have an 'http' protocol on secure connections. @@ -3339,10 +3352,10 @@ $ npm install && npm test ### License -Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). +Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). When this project was created some helpers were sourced from [Swag, by Elving Rodriguez](http://elving.github.com/swag/). Released under the [MIT License](LICENSE). *** -_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 17, 2017._ \ No newline at end of file +_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 23, 2018._ \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index ebbad0a7..e0321d2a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,13 @@ environment: matrix: # node.js + - nodejs_version: "9.0" - nodejs_version: "8.0" - nodejs_version: "7.0" - nodejs_version: "6.0" - nodejs_version: "5.0" + - nodejs_version: "4.0" + - nodejs_version: "0.12" # Install scripts. (runs after repo cloning) install: @@ -13,15 +16,12 @@ install: - ps: Install-Product node $env:nodejs_version # install modules - npm install - - npm install -g gulp-cli # Post-install test scripts. test_script: # Output useful info for debugging. - node --version - npm --version - # run tests - - gulp # Don't actually build. build: off diff --git a/lib/url.js b/lib/url.js index 110a8165..6836dbae 100644 --- a/lib/url.js +++ b/lib/url.js @@ -85,14 +85,29 @@ helpers.urlResolve = function(base, href) { /** * Parses a `url` string into an object. + * If parseQueryString options is true it will parse the query string + * of given `url`. * * @param {String} `str` URL string - * @return {String} Returns stringified JSON + * @param {Options} `options` Handlebars provided options object + * @return {Object} Returns a parsed object * @api public */ -helpers.urlParse = function(str) { - return url.parse(str); +helpers.urlParse = function(str, options) { + return url.parse(str, options.hash.parseQueryString); +}; + +/** + * Parses a `queryString` string into an object. + * + * @param {String} `queryString` queryString + * @return {Object} a parsed object + * @api public + */ + +helpers.parseQueryString = function(str) { + return querystring.parse(str); }; /** diff --git a/test/url.js b/test/url.js index 460caadc..a60ad6f4 100644 --- a/test/url.js +++ b/test/url.js @@ -44,10 +44,21 @@ describe('url', function() { describe('urlParse', function() { it('should take a string, and return an object stringified to JSON.', function() { - var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value" "json")}}}'); - + var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value")}}}'); assert.deepEqual(fn(), '{"protocol":"http:","slashes":true,"auth":null,"host":"foo.com","port":null,"hostname":"foo.com","hash":null,"search":"?key=value","query":"key=value","pathname":"/bar/baz","path":"/bar/baz?key=value","href":"http://foo.com/bar/baz?key=value"}'); }); + + it('should take a string, and return an object stringified to JSON. The query string should be parsed as well.', function() { + var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value" parseQueryString=true)}}}'); + assert.deepEqual(fn(), '{"protocol":"http:","slashes":true,"auth":null,"host":"foo.com","port":null,"hostname":"foo.com","hash":null,"search":"?key=value","query":{"key":"value"},"pathname":"/bar/baz","path":"/bar/baz?key=value","href":"http://foo.com/bar/baz?key=value"}'); + }); + }); + + describe('parseQueryString', function() { + it('should take a string, and return an object stringified to JSON.', function() { + var fn = hbs.compile('{{{JSONstringify (parseQueryString "key=value")}}}'); + assert.deepEqual(fn(), '{"key":"value"}'); + }); }); describe('strip protocol', function() {