Skip to content

Instantly share code, notes, and snippets.

@richtier
Last active December 30, 2015 21:29
Show Gist options
  • Save richtier/7888232 to your computer and use it in GitHub Desktop.
Save richtier/7888232 to your computer and use it in GitHub Desktop.
querrystring to object
/**
* converts querystring to object. Allows multiple values per key
* @param {String} querystring - optional querystring. default address bar
* @return {object}
*/
self.querystringToObject = function(querystring){
var params = {};
(querystring || window.location.search)
.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) {
if (params[$1]){
if (!$.isArray(params[$1])){
params[$1] = [params[$1]];
}
params[$1].push($3);
}else{
params[$1] = $3;
}
});
return params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment