Created
March 27, 2014 16:52
-
-
Save gberger/9812277 to your computer and use it in GitHub Desktop.
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
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