mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-19 06:44:59 +09:00
Hello world
First open source release of Campfire 🎉
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export function getCookie(name) {
|
||||
const cookies = document.cookie ? document.cookie.split("; ") : []
|
||||
const prefix = `${encodeURIComponent(name)}=`
|
||||
const cookie = cookies.find(cookie => cookie.startsWith(prefix))
|
||||
|
||||
if (cookie) {
|
||||
const value = cookie.split("=").slice(1).join("=")
|
||||
return value ? decodeURIComponent(value) : undefined
|
||||
}
|
||||
}
|
||||
|
||||
const twentyYears = 20 * 365 * 24 * 60 * 60 * 1000
|
||||
|
||||
export function setCookie(name, value) {
|
||||
const body = [ name, value ].map(encodeURIComponent).join("=")
|
||||
const expires = new Date(Date.now() + twentyYears).toUTCString()
|
||||
const cookie = `${body}; path=/; expires=${expires}`
|
||||
document.cookie = cookie
|
||||
}
|
||||
Reference in New Issue
Block a user