Skip to content

Instantly share code, notes, and snippets.

@gbuesing
Created October 25, 2015 20:02
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 gbuesing/783d23441af7421af67b to your computer and use it in GitHub Desktop.
Save gbuesing/783d23441af7421af67b to your computer and use it in GitHub Desktop.
addParams = (path, params) ->
query = objToQuery(params)
joinChar = if /\?/.test(path) then '&' else '?'
"#{path}#{joinChar}#{query}"
objToQuery = (obj) ->
pairs = []
for own key, val of obj
if val? and val != ''
val = encodeURIComponent(val)
pairs.push("#{encodeURIComponent(key)}=#{val}")
pairs.join('&')
# returns querystring as an object
parseParams = ->
query = window.location.search.substr(1)
out = {}
return out unless query != ''
for keyval in query.split('&')
pair = keyval.split('=')
key = decodeURIComponent(pair[0])
val = pair[1]
if val? && val != ''
out[key] = decodeURIComponent(val)
else
out[key] = null
out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment