From 20a2fa1bcbf7817a7814904247319972c2fcd44b Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Mon, 8 Jan 2018 20:20:00 -0500 Subject: [PATCH 1/5] fix configs --- .travis.yml | 5 ++--- appveyor.yml | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) 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/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 From e0115af061040722af60ee06aa206cb10596d3f4 Mon Sep 17 00:00:00 2001 From: Kirill Shatskiy Date: Thu, 22 Nov 2018 13:33:35 +0300 Subject: [PATCH 2/5] remove "json" option from the tests because it's not supported by urlParse --- test/url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/url.js b/test/url.js index 460caadc..43a6d1b0 100644 --- a/test/url.js +++ b/test/url.js @@ -44,7 +44,7 @@ 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"}'); }); From ea649f9c2df7a5cd9172c0cee7e17c0a6f83c69f Mon Sep 17 00:00:00 2001 From: Kirill Shatskiy Date: Thu, 22 Nov 2018 18:05:47 +0300 Subject: [PATCH 3/5] implement tests for parseQuery string and url.parse --- test/url.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/url.js b/test/url.js index 43a6d1b0..a60ad6f4 100644 --- a/test/url.js +++ b/test/url.js @@ -45,9 +45,20 @@ 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")}}}'); - 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() { From b2fc9f8427db6232962d580cdedfd29a778b07d1 Mon Sep 17 00:00:00 2001 From: Kirill Shatskiy Date: Thu, 22 Nov 2018 18:06:10 +0300 Subject: [PATCH 4/5] implement parseQueryString and the options for urlParse --- lib/url.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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); }; /** From 7ba16ac2d0a232f05537cf0d2efc252b30f66260 Mon Sep 17 00:00:00 2001 From: Kirill Shatskiy Date: Fri, 23 Nov 2018 10:54:47 +0300 Subject: [PATCH 5/5] update readme --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) 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