Last active
December 1, 2015 21:42
-
-
Save evanleck/30ee2c043453ee0adc2c to your computer and use it in GitHub Desktop.
Super simple parser of query string parameters.
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
/* | |
* Params.js | |
* | |
* Super simple parser of query string parameters. | |
* Creates a variable 'params' on the 'window' object. | |
* | |
*/ | |
(function() { | |
var params = {}, | |
capture = void 0, | |
query = window.location.search.substring(1), | |
whitespace = /\+/g, | |
regex = /([^&=]+)=?([^&]*)/g, | |
decode = function(s) { | |
return decodeURIComponent(s.replace(whitespace, " ")); | |
}; | |
while (capture = regex.exec(query)) { | |
var key = decode(capture[1]), | |
value = decode(capture[2]); | |
if (value !== '') { | |
params[key] = value; | |
} | |
} | |
this.params = params; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment