diff --git a/README.md b/README.md
index 6bd7449..e5a058f 100644
--- a/README.md
+++ b/README.md
@@ -26,10 +26,13 @@ const options = { prefix: '?' };
qs.stringify(params, options);
// '?food=pizza&bar=chocolate'
-
// Parse query strings into objects
qs.parse('?food=pizza&bar=chocolate');
// { food: pizza, bar: chocolate }
+
+// Extract query string from url
+qs.extract('http://test.com?food=pizza&bar=chocolate');
+// food=pizza&bar=chocolate
```
## Tests
diff --git a/docs/QueryString.html b/docs/QueryString.html
index 21d3422..1a52406 100644
--- a/docs/QueryString.html
+++ b/docs/QueryString.html
@@ -32,7 +32,7 @@
-
+
@@ -167,6 +167,166 @@ Methods
+-
+
+
+
+
+
+
+-
+
+
+
+ Extract the query string sentence from any url. If there is no query string, empty string should be returned.
+
+
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+ | Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ url |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+ url which contains |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+string
+
+
+
+
+
+- Extracted query string from url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/docs/index.html b/docs/index.html
index fb9e46f..f955577 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -32,7 +32,7 @@
-
+
@@ -74,10 +74,13 @@ Install
$ npm install qu
qs.stringify(params, options);
// '?food=pizza&bar=chocolate'
-
// Parse query strings into objects
qs.parse('?food=pizza&bar=chocolate');
-// { food: pizza, bar: chocolate }
Tests
$ npm test
Documentation
You have a look at the documentation here.
+// { food: pizza, bar: chocolate }
+
+// Extract query string from url
+qs.extract('http://test.com?food=pizza&bar=chocolate');
+// food=pizza&bar=chocolateTests
$ npm test
Documentation
You have a look at the documentation here.
If you ever edit the documentation and wants to generate a new version of it just run the command:
$ npm run docs
Commit your changes and push them to master. Github pages will update the page automatically.
Issues?
Go here
diff --git a/docs/index.js.html b/docs/index.js.html
index 31296dc..e2ff457 100644
--- a/docs/index.js.html
+++ b/docs/index.js.html
@@ -34,7 +34,7 @@
-
+
@@ -142,8 +142,18 @@
return obj;
}
+/**
+ * Extract the query string sentence from any url. If there is no query string, empty string should be returned.
+ * @param {string} url - url which contains
+ * @returns {string} Extracted query string from url
+ */
QueryString.prototype.extract = function (url) {
- return url.substring(url.indexOf('?') + 1);
+ const queryStringPosition = url.indexOf('?')
+ const isThereQueryString = queryStringPosition > -1
+
+ if (!isThereQueryString) return ''
+
+ return url.substring(queryStringPosition + 1);
}
// Export the module
diff --git a/index.js b/index.js
index 71e951b..a92c630 100644
--- a/index.js
+++ b/index.js
@@ -94,8 +94,18 @@ QueryString.prototype.parse = function (queryStr) {
return obj;
}
+/**
+ * Extract the query string sentence from any url. If there is no query string, empty string should be returned.
+ * @param {string} url - url which contains
+ * @returns {string} Extracted query string from url
+ */
QueryString.prototype.extract = function (url) {
- return url.substring(url.indexOf('?') + 1);
+ const queryStringPosition = url.indexOf('?')
+ const isThereQueryString = queryStringPosition > -1
+
+ if (!isThereQueryString) return ''
+
+ return url.substring(queryStringPosition + 1);
}
// Export the module
diff --git a/test.js b/test.js
index 998c918..fe6390d 100644
--- a/test.js
+++ b/test.js
@@ -62,12 +62,19 @@ describe('query-stringifier', function () {
});
describe('#extract', function () {
- it('exract the query string of the url', function() {
+ it('extract the query string of the url', function() {
var url = 'www.dummyurl.com?firstqueryparam=first&secondqueryparam=second';
var result = qs.extract(url);
expect(result).to.equal('firstqueryparam=first&secondqueryparam=second');
});
+
+ it('should return empty if there is no query string', function() {
+ var url = 'www.dummyurl.com';
+ var result = qs.extract(url);
+
+ expect(result).to.equal('');
+ });
});
describe('#extract/#parse', function() {