Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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