Skip to content

Commit 0899624

Browse files
authored
Merge pull request #9 from PhilippeChab/Extract_URL_Query
Extract url query from url
2 parents ecaa36d + e6ab96d commit 0899624

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,9 @@ QueryString.prototype.parse = function (queryStr) {
6161
return obj;
6262
}
6363

64+
QueryString.prototype.extract = function (url) {
65+
return url.substring(url.indexOf('?') + 1);
66+
}
67+
6468
// Export the module
6569
module.exports = new QueryString();

test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,25 @@ describe('query-stringifier', function () {
4646
expect(parsed).to.have.property('thing', 'thung');
4747
});
4848
});
49+
50+
describe('#extract', function () {
51+
it('exract the query string of the url', function() {
52+
var url = 'www.dummyurl.com?firstqueryparam=first&secondqueryparam=second';
53+
var result = qs.extract(url);
54+
55+
expect(result).to.equal('firstqueryparam=first&secondqueryparam=second');
56+
});
57+
});
58+
59+
describe('#extract/#parse', function() {
60+
it('extract the query string of the url and parses it', function () {
61+
var url = 'www.dummyurl.com?firstqueryparam=first&secondqueryparam=second';
62+
var result = qs.parse(qs.extract(url));
63+
64+
expect(result).to.be.an('object');
65+
expect(result).to.have.property('firstqueryparam', 'first');
66+
expect(result).to.have.property('secondqueryparam', 'second');
67+
});
68+
});
69+
4970
});

0 commit comments

Comments
 (0)