Skip to content
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ $ npm test

## Documentation

You have a look at the documentation [here](https://joshghent.github.io/query-stringifier/).

If you ever edit the documentation and wants to generate a new version of it just run the command:

```
Expand Down
23 changes: 22 additions & 1 deletion docs/QueryString.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ <h3 class="subsection-title">Methods</h3>

<h4 class="name" id="parse">

<span class="type-signature"></span>parse<span class="signature">(queryStr)</span><span class="type-signature"></span>
<span class="type-signature"></span>parse<span class="signature">(queryStr)</span><span class="type-signature"> &rarr; {object}</span>


<div class="container-source members">
Expand Down Expand Up @@ -264,6 +264,27 @@ <h5>Parameters:</h5>



<div class="container-returns">
<h5>Returns:</h5>





<span class="param-type">object</span>





- Returns query-string as object





</div>




Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ <h2>Install</h2><pre class="prettyprint source lang-bash"><code>$ npm install qu

// Parse query strings into objects
qs.parse('?food=pizza&bar=chocolate');
// { food: pizza, bar: chocolate }</code></pre><h2>Tests</h2><pre class="prettyprint source"><code>$ npm test</code></pre><h2>Documentation</h2><p>If you ever edit the documentation and wants to generate a new version of it just run the command:</p>
// { food: pizza, bar: chocolate }</code></pre><h2>Tests</h2><pre class="prettyprint source"><code>$ npm test</code></pre><h2>Documentation</h2><p>You have a look at the documentation <a href="https://joshghent.github.io/query-stringifier/">here</a>.</p>
<p>If you ever edit the documentation and wants to generate a new version of it just run the command:</p>
<pre class="prettyprint source"><code>$ npm run docs</code></pre><p>Commit your changes and push them to master. Github pages will update the page automatically.</p>
<h2>Issues?</h2><p>Go <a href="https://github.com/joshghent/query-stringifier/issues">here</a></p>
<h2>Contributing</h2><p>Insterested to help? Just follow our <a href="https://github.com/joshghent/query-stringifier/blob/master/CONTRIBUTING.md">Contribution Guide</a>.</p></article>
Expand Down
34 changes: 31 additions & 3 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
/**
* Add the query stringify method
* @param {string | any} queryStr - The query string to parse into an object. If any type other than string, just returns it
* @returs {object} Returns query-string as object
* @returns {object} Returns query-string as object
*/
QueryString.prototype.parse = function (queryStr) {
let obj = Object.create(null);
Expand All @@ -111,13 +111,41 @@ <h1><a href="index.html" class="link">QueryString</a></h1>

queryStr.split('&amp;').forEach((param) => {
const components = param.split('=');

obj[decodeURIComponent(components[0])] = decodeURIComponent(components[1]);
const value = decodeURIComponent(components[1]);
var key = decodeURIComponent(components[0]);

//Is the query param an array?
if (key.search(/\[([0-9]*)\]/) !== -1) {
const indexOfArray = key.slice(-2) !== '[]' ? key.charAt(key.length - 2) : undefined;
key = key.slice(0, key.indexOf('['));

//Does the array already exist in the object
if (obj[key]) {
if (indexOfArray) {
obj[key][indexOfArray] = value;
} else {
obj[key].push(value);
}
} else {
if (indexOfArray) {
obj[key] = [];
obj[key][indexOfArray] = value;
} else {
obj[key] = [value];
}
}
} else {
obj[key] = value;
}
});

return obj;
}

QueryString.prototype.extract = function (url) {
return url.substring(url.indexOf('?') + 1);
}

// Export the module
module.exports = new QueryString();</code></pre>
</article>
Expand Down
Loading