Created
August 7, 2012 19:06
-
-
Save rosenfeld/3288442 to your computer and use it in GitHub Desktop.
Parse query params in CoffeeScript
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
# for simple use case - doesn't take into account multiple occurrences | |
parseParams = (search = window.location.search)-> | |
d = (str)-> decodeURIComponent str.replace /\+/g, ' ' | |
query = search.substring 1 | |
regex = /(.*?)=([^\&]*)&?/g | |
params = {} | |
params[d(m[1])] = d(m[2]) while m = regex.exec query | |
params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment