Skip to content

Instantly share code, notes, and snippets.

@yocontra
Created April 24, 2012 07:56
Show Gist options
  • Save yocontra/2477664 to your computer and use it in GitHub Desktop.
Save yocontra/2477664 to your computer and use it in GitHub Desktop.
Tiny cookie getter/setter javascript/coffee-script
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