Skip to content

Instantly share code, notes, and snippets.

@jamiehodge
Created May 24, 2013 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiehodge/5642713 to your computer and use it in GitHub Desktop.
Save jamiehodge/5642713 to your computer and use it in GitHub Desktop.
parse url query string
params = (url) ->
plus = /\+/g
search = /([^&=]+)=?([^&]*)/g
decode = (s) -> decodeURIComponent s.replace(plus, ' ')
index = url.indexOf '?'
if index isnt -1 then hash = url.substr index + 1 else hash = ''
result = {}
while match = search.exec(hash)
key = decode match[1]
value = decode match[2]
result[key] = value
result
console.log params 'http://tus.io?offset=1023'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment