add day 13, SSRgit checkout maingit checkout mainsudo pacman -S virt-manager qemu vde2 ebtables dnsmasq bridge-utils openbsd-netcat
checkout
This commit is contained in:
41
day13/src/lib/cookieManager.js
Normal file
41
day13/src/lib/cookieManager.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export function setCookie(name, value, expires, path, domain) {
|
||||
if (import.meta.env.SSR) return
|
||||
var cookie = name.trimEnd() + "=" + escape(value) + ";";
|
||||
|
||||
if (expires) {
|
||||
// If it's a date
|
||||
if(expires instanceof Date) {
|
||||
// If it isn't a valid date
|
||||
if (isNaN(expires.getTime()))
|
||||
expires = new Date();
|
||||
}
|
||||
else
|
||||
expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24);
|
||||
|
||||
cookie += "expires=" + expires.toGMTString() + ";";
|
||||
}
|
||||
|
||||
if (path)
|
||||
cookie += "path=" + path + ";";
|
||||
if (domain)
|
||||
cookie += "domain=" + domain + ";";
|
||||
|
||||
document.cookie = cookie;
|
||||
}
|
||||
|
||||
export function getCookie(name) {
|
||||
if (import.meta.env.SSR) return
|
||||
let cname = name + "=";
|
||||
let decodedCookie = decodeURIComponent(document.cookie);
|
||||
let ca = decodedCookie.split(';');
|
||||
for(let i = 0; i <ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(cname) == 0) {
|
||||
return c.substring(cname.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user