Created
September 17, 2013 21:12
-
-
Save owldesign/6600712 to your computer and use it in GitHub Desktop.
Coffee Script Cookies
This file contains 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
####################################################### | |
# Chocolate Chip Cookies setter+getter | |
####################################################### | |
createCookie = (name, value, expires, path, domain) -> | |
cookie = name + "=" + escape(value) + ";" | |
if expires | |
if expires instanceof Date | |
expires = new Date() if isNaN(expires.getTime()) | |
else | |
expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24) | |
cookie += "expires=" + expires.toGMTString() + ";" | |
cookie += "path=" + path + ";" if path | |
cookie += "domain=" + domain + ";" if domain | |
document.cookie = cookie | |
getCookie = (name) -> | |
regexp = new RegExp("(?:^" + name + "|;s*" + name + ")=(.*?)(?:;|$)", "g") | |
result = regexp.exec(document.cookie) | |
(if (result is null) then null else result[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment