Skip to content

Instantly share code, notes, and snippets.

@gberger
Created March 27, 2014 16:52
Show Gist options
  • Save gberger/9812277 to your computer and use it in GitHub Desktop.
Save gberger/9812277 to your computer and use it in GitHub Desktop.
mapize = (str, pairSeparator, keyValueSeparator, fnKey, fnValue) ->
map = {}
for pair in str.split(pairSeparator)
[key, value...] = pair.split(keyValueSeparator)
map[fnKey(key)] = fnValue(value.join('='))
return map
urlParams = ->
mapize(window.location.search.substring(1), '&', '=', decodeURIComponent, decodeURIComponent)
urlParam = (name) ->
urlParams()[name]
readCookies = ->
trim = (str) -> str.replace(/^\s+|\s+$/g, '');
mapize(document.cookie, ';', '=', trim, unescape)
readCookie = (name) ->
readCookies()[name]
readSubcookie = (name, cookie) ->
mapize(cookie, '&', '=', ((s)->s), unescape)[name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment