Skip to content

Commit 41b2b25

Browse files
authored
Merge pull request #16 from marcelorl/master
fix: extract documentation and result fixed
2 parents 0627f5c + 823e491 commit 41b2b25

File tree

6 files changed

+202
-9
lines changed

6 files changed

+202
-9
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ const options = { prefix: '?' };
2626
qs.stringify(params, options);
2727
// '?food=pizza&bar=chocolate'
2828

29-
3029
// Parse query strings into objects
3130
qs.parse('?food=pizza&bar=chocolate');
3231
// { food: pizza, bar: chocolate }
32+
33+
// Extract query string from url
34+
qs.extract('http://test.com?food=pizza&bar=chocolate');
35+
// food=pizza&bar=chocolate
3336
```
3437

3538
## Tests

docs/QueryString.html

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
3232
<ul></ul>
3333
</div>
3434

35-
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
35+
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#extract">extract</a></li><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
3636
</nav>
3737
<div id="resizer"></div>
3838

@@ -167,6 +167,166 @@ <h3 class="subsection-title">Methods</h3>
167167
<dl>
168168

169169

170+
<dt>
171+
172+
<h4 class="name" id="extract">
173+
174+
<span class="type-signature"></span>extract<span class="signature">(url)</span><span class="type-signature"> &rarr; {string}</span>
175+
176+
177+
<div class="container-source members">
178+
<code><a href="index.js.html">index.js</a></code>,
179+
<code><a href="index.js.html#line102">line 102</a></code>
180+
</div>
181+
182+
</h4>
183+
184+
185+
186+
</dt>
187+
<dd>
188+
189+
190+
<div class="description">
191+
Extract the query string sentence from any url. If there is no query string, empty string should be returned.
192+
</div>
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+
<div class="container-params">
203+
<h5>Parameters:</h5>
204+
205+
<table class="params">
206+
<thead>
207+
<tr>
208+
209+
<th>Name</th>
210+
211+
212+
<th>Type</th>
213+
214+
215+
216+
217+
218+
<th class="last">Description</th>
219+
</tr>
220+
</thead>
221+
222+
<tbody>
223+
224+
225+
<tr>
226+
227+
<td class="name"><code>url</code></td>
228+
229+
230+
<td class="type">
231+
232+
233+
<span class="param-type">string</span>
234+
235+
236+
237+
</td>
238+
239+
240+
241+
242+
243+
<td class="description last">url which contains</td>
244+
</tr>
245+
246+
247+
</tbody>
248+
</table>
249+
250+
</div>
251+
252+
253+
254+
255+
256+
257+
258+
259+
260+
261+
262+
263+
264+
<div class="container-returns">
265+
<h5>Returns:</h5>
266+
267+
268+
269+
270+
271+
<span class="param-type">string</span>
272+
273+
274+
275+
276+
277+
- Extracted query string from url
278+
279+
280+
281+
282+
283+
</div>
284+
285+
286+
287+
288+
289+
<dl class="details">
290+
291+
292+
293+
294+
295+
296+
297+
298+
299+
300+
301+
302+
303+
304+
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+
317+
318+
319+
320+
</dl>
321+
322+
323+
324+
325+
</dd>
326+
327+
328+
329+
170330
<dt>
171331

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

docs/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
3232
<ul></ul>
3333
</div>
3434

35-
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
35+
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#extract">extract</a></li><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
3636
</nav>
3737
<div id="resizer"></div>
3838

@@ -74,10 +74,13 @@ <h2>Install</h2><pre class="prettyprint source lang-bash"><code>$ npm install qu
7474
qs.stringify(params, options);
7575
// '?food=pizza&bar=chocolate'
7676

77-
7877
// Parse query strings into objects
7978
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>You have a look at the documentation <a href="https://joshghent.github.io/query-stringifier/">here</a>.</p>
79+
// { food: pizza, bar: chocolate }
80+
81+
// Extract query string from url
82+
qs.extract('http://test.com?food=pizza&bar=chocolate');
83+
// 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>
8184
<p>If you ever edit the documentation and wants to generate a new version of it just run the command:</p>
8285
<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>
8386
<h2>Issues?</h2><p>Go <a href="https://github.com/joshghent/query-stringifier/issues">here</a></p>

docs/index.js.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
3434
<ul></ul>
3535
</div>
3636

37-
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
37+
<div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="QueryString.html">QueryString</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="QueryString_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="QueryString.html#extract">extract</a></li><li><a href="QueryString.html#parse">parse</a></li><li><a href="QueryString.html#stringify">stringify</a></li></ul></div></li></ul></div>
3838
</nav>
3939
<div id="resizer"></div>
4040

@@ -142,8 +142,18 @@ <h1><a href="index.html" class="link">QueryString</a></h1>
142142
return obj;
143143
}
144144

145+
/**
146+
* Extract the query string sentence from any url. If there is no query string, empty string should be returned.
147+
* @param {string} url - url which contains
148+
* @returns {string} Extracted query string from url
149+
*/
145150
QueryString.prototype.extract = function (url) {
146-
return url.substring(url.indexOf('?') + 1);
151+
const queryStringPosition = url.indexOf('?')
152+
const isThereQueryString = queryStringPosition > -1
153+
154+
if (!isThereQueryString) return ''
155+
156+
return url.substring(queryStringPosition + 1);
147157
}
148158

149159
// Export the module

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,18 @@ QueryString.prototype.parse = function (queryStr) {
9494
return obj;
9595
}
9696

97+
/**
98+
* Extract the query string sentence from any url. If there is no query string, empty string should be returned.
99+
* @param {string} url - url which contains
100+
* @returns {string} Extracted query string from url
101+
*/
97102
QueryString.prototype.extract = function (url) {
98-
return url.substring(url.indexOf('?') + 1);
103+
const queryStringPosition = url.indexOf('?')
104+
const isThereQueryString = queryStringPosition > -1
105+
106+
if (!isThereQueryString) return ''
107+
108+
return url.substring(queryStringPosition + 1);
99109
}
100110

101111
// Export the module

test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ describe('query-stringifier', function () {
6262
});
6363

6464
describe('#extract', function () {
65-
it('exract the query string of the url', function() {
65+
it('extract the query string of the url', function() {
6666
var url = 'www.dummyurl.com?firstqueryparam=first&secondqueryparam=second';
6767
var result = qs.extract(url);
6868

6969
expect(result).to.equal('firstqueryparam=first&secondqueryparam=second');
7070
});
71+
72+
it('should return empty if there is no query string', function() {
73+
var url = 'www.dummyurl.com';
74+
var result = qs.extract(url);
75+
76+
expect(result).to.equal('');
77+
});
7178
});
7279

7380
describe('#extract/#parse', function() {

0 commit comments

Comments
 (0)