Skip to content

Instantly share code, notes, and snippets.

@ErBlack
Last active August 29, 2015 14:21
Show Gist options
  • Save ErBlack/5171184be992fda6d716 to your computer and use it in GitHub Desktop.
Save ErBlack/5171184be992fda6d716 to your computer and use it in GitHub Desktop.
query parser
function query() {
location.search
.substr(1)
.split('&')
.reduce(function (query, component) {
component = component.length && component.split('=');
if (component.length) {
try {
var key = decodeURIComponent(component[0]),
value = component[1];
if (query[key]) {
query[key] = [].concat(query[key]);
query[key].push(decodeURIComponent(value))
} else {
query[key] = value && decodeURIComponent(value);
}
} catch (exception) {
}
}
return query;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment