Created
May 24, 2013 10:56
-
-
Save jamiehodge/5642713 to your computer and use it in GitHub Desktop.
parse url query string
This file contains hidden or 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 = (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