Skip to content

Instantly share code, notes, and snippets.

@rosenfeld
Created August 7, 2012 19:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosenfeld/3288442 to your computer and use it in GitHub Desktop.
Save rosenfeld/3288442 to your computer and use it in GitHub Desktop.
Parse query params in CoffeeScript
# 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