Last active
August 13, 2022 18:13
-
-
Save jgoslow/c6d91c96eed0360e46414be18ccf6ab8 to your computer and use it in GitHub Desktop.
URL javascript functions
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 formatParamsObjectToURL( params ){ | |
return "?" + Object | |
.keys(params) | |
.map(function(key){ | |
return key+"="+encodeURIComponent(params[key]) | |
}) | |
.join("&") | |
} |
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
/** | |
* Returns object of URL params | |
*/ | |
function getQueryParams(qs) { | |
qs = qs.split('+').join(' '); | |
var params = {}, | |
tokens, | |
re = /[?&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) { | |
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); | |
} | |
return params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment