Last active
August 29, 2015 14:21
-
-
Save ErBlack/5171184be992fda6d716 to your computer and use it in GitHub Desktop.
query parser
This file contains 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 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