Created
April 24, 2012 07:56
-
-
Save yocontra/2477664 to your computer and use it in GitHub Desktop.
Tiny cookie getter/setter javascript/coffee-script
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
cookie = (name, value) -> | |
if name and value | |
document.cookie = "#{name}=#{value};" | |
return value | |
else | |
out = {} | |
for cookie in document.cookie.split ";" | |
pair = cookie.split "=" | |
out[pair[0]] = pair[1] | |
return (if name? then out[name] else out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment