Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the PR is created in order to close #336 #337

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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])

***

Expand Down Expand Up @@ -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`.

Expand All @@ -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.

Expand Down Expand Up @@ -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._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 23, 2018._
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
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:
# Get the latest stable version of Node.js or io.js
- 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
21 changes: 18 additions & 3 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
15 changes: 13 additions & 2 deletions test/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down