Skip to content

Instantly share code, notes, and snippets.

@andrienko
Created October 26, 2015 22:09
Show Gist options
  • Save andrienko/44af2c35b0c9fc3fa534 to your computer and use it in GitHub Desktop.
Save andrienko/44af2c35b0c9fc3fa534 to your computer and use it in GitHub Desktop.
var e = encodeURIComponent;
var d = decodeURIComponent;
var paramsToURI = function(params){
var uri_components = [];
for(var i in params){
if(params.hasOwnProperty(i)) {
uri_components.push(e(i) + '=' + e(params[i]));
}
}
return uri_components.join('&');
};
var URIToParams = function(uri){
uri = uri.replace(/^.*\?/,'');
var uri_components = uri.split('&');
var params = {};
uri_components.forEach(function(a){
a = a.split('=');
params[d(a[0])] = d(a[1]);
});
return params;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment