Skip to content

Commit 01f0e0e

Browse files
authored
Merge pull request #13 from marcelorl/master
hook to add generated docs files to commit
2 parents 18055a6 + 3698b47 commit 01f0e0e

File tree

6 files changed

+565
-83
lines changed

6 files changed

+565
-83
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ $ npm test
4040

4141
## Documentation
4242

43+
You have a look at the documentation [here](https://joshghent.github.io/query-stringifier/).
44+
4345
If you ever edit the documentation and wants to generate a new version of it just run the command:
4446

4547
```

docs/QueryString.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ <h3 class="subsection-title">Methods</h3>
171171

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

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

176176

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

265265

266266

267+
<div class="container-returns">
268+
<h5>Returns:</h5>
269+
270+
271+
272+
273+
274+
<span class="param-type">object</span>
275+
276+
277+
278+
279+
280+
- Returns query-string as object
281+
282+
283+
284+
285+
286+
</div>
287+
267288

268289

269290

docs/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ <h2>Install</h2><pre class="prettyprint source lang-bash"><code>$ npm install qu
7777

7878
// Parse query strings into objects
7979
qs.parse('?food=pizza&bar=chocolate');
80-
// { 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>
80+
// { 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>
81+
<p>If you ever edit the documentation and wants to generate a new version of it just run the command:</p>
8182
<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>
8283
<h2>Issues?</h2><p>Go <a href="https://github.com/joshghent/query-stringifier/issues">here</a></p>
8384
<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>

docs/index.js.html

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
9898
/**
9999
* Add the query stringify method
100100
* @param {string | any} queryStr - The query string to parse into an object. If any type other than string, just returns it
101-
* @returs {object} Returns query-string as object
101+
* @returns {object} Returns query-string as object
102102
*/
103103
QueryString.prototype.parse = function (queryStr) {
104104
let obj = Object.create(null);
@@ -111,13 +111,41 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
111111

112112
queryStr.split('&amp;').forEach((param) => {
113113
const components = param.split('=');
114-
115-
obj[decodeURIComponent(components[0])] = decodeURIComponent(components[1]);
114+
const value = decodeURIComponent(components[1]);
115+
var key = decodeURIComponent(components[0]);
116+
117+
//Is the query param an array?
118+
if (key.search(/\[([0-9]*)\]/) !== -1) {
119+
const indexOfArray = key.slice(-2) !== '[]' ? key.charAt(key.length - 2) : undefined;
120+
key = key.slice(0, key.indexOf('['));
121+
122+
//Does the array already exist in the object
123+
if (obj[key]) {
124+
if (indexOfArray) {
125+
obj[key][indexOfArray] = value;
126+
} else {
127+
obj[key].push(value);
128+
}
129+
} else {
130+
if (indexOfArray) {
131+
obj[key] = [];
132+
obj[key][indexOfArray] = value;
133+
} else {
134+
obj[key] = [value];
135+
}
136+
}
137+
} else {
138+
obj[key] = value;
139+
}
116140
});
117141

118142
return obj;
119143
}
120144

145+
QueryString.prototype.extract = function (url) {
146+
return url.substring(url.indexOf('?') + 1);
147+
}
148+
121149
// Export the module
122150
module.exports = new QueryString();</code></pre>
123151
</article>

0 commit comments

Comments
 (0)