mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 04:29:29 +08:00
1 line
No EOL
929 B
Text
1 line
No EOL
929 B
Text
var e=new Set(["domain","path","max-age","expires","samesite","secure","httponly"]);function t(t){let a,n,s,i,r={},o=0,m=t.split(/;\s*/g);for(;o<m.length;o++)if(n=m[o],a=n.indexOf("="),~a){if(s=n.substring(0,a++).trim(),i=n.substring(a).trim(),'"'===i[0]&&(i=i.substring(1,i.length-1)),~i.indexOf("%"))try{i=decodeURIComponent(i)}catch{}e.has(n=s.toLowerCase())?"expires"===n?r.expires=new Date(i):"max-age"===n?r.maxage=+i:r[n]=i:r[s]=i}else(s=n.trim().toLowerCase())&&("httponly"===s||"secure"===s)&&(r[s]=!0);return r}function a(e,t,a={}){let n=e+"="+encodeURIComponent(t);return a.expires&&(n+="; Expires="+new Date(a.expires).toUTCString()),null!=a.maxage&&a.maxage>=0&&(n+="; Max-Age="+(0|a.maxage)),a.domain&&(n+="; Domain="+a.domain),a.path&&(n+="; Path="+a.path),a.samesite&&(n+="; SameSite="+a.samesite),(a.secure||"None"===a.samesite)&&(n+="; Secure"),a.httponly&&(n+="; HttpOnly"),n}export{t as parse,a as stringify}; |