Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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