Last active
January 4, 2019 18:48
-
-
Save robsonsobral/73b41a4ced0ab4e44ac85ccc6f8b542b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getQueryString() { | |
var url = arguments.length > 0 && arguments[0] !== undefined ? | |
arguments[0] : | |
window.location.search; | |
var queryString = url.indexOf('?') !== -1 ? | |
url.split('?')[1] : | |
url; | |
var queries = queryString.indexOf('&') !== -1 ? | |
queryString.split('&') : | |
[queryString]; | |
var params = {}; | |
for (let i = 0; i < queries.length; i += 1) { | |
var element = queries[i].indexOf('=') !== -1 ? | |
queries[i].split('=') : | |
[queries[i], null]; | |
params[decodeURIComponent(element[0])] = decodeURIComponent(element[1] || ''); | |
} | |
return params; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setQueryString(params) { | |
return '?' + Object | |
.keys(params) | |
.map(function (key) { | |
return key + '=' + encodeURIComponent(params[key]) | |
}) | |
.join('&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment