Urara-Blog/node_modules/.pnpm-store/v3/files/0d/719151bcbd7e91c5e771fd7991108782ebbd427001d6b7f50a6e4d1865d64668eb892a966086da02a5af6bfd0022e08912611a98861f80c9441f5e83d67b48
2022-08-14 01:14:53 +08:00

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};