3 lines
2.3 KiB
JavaScript
3 lines
2.3 KiB
JavaScript
/*! js-cookie v3.0.1 | MIT */
|
|
function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var t=function t(n,r){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=e({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+c}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],r={},o=0;o<t.length;o++){var i=t[o].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(r[u]=n.read(c,u),e===u)break}catch(e){}}return e?r[e]:r}},remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),n={get:function(e){return t.get(e)},set:function(e,n,r){t.set(e,n,r)},remove:function(e,n){t.remove(e,n)},clear:function(e){var n=t.get();Object.keys(n).forEach((function(n){t.remove(n,e)}))},check:function(e){var t=n.get(e);return""!==t&&null!=t}},r={get:function(e){try{return JSON.parse(window.localStorage.getItem(e))}catch(t){return window.localStorage.getItem(e)}},set:function(e,t){window.localStorage.setItem(e,JSON.stringify(t))},remove:function(e){window.localStorage.removeItem(e)},clear:function(){window.localStorage.clear()},check:function(e){return null!==r.get(e)}},o={get:function(e){try{return JSON.parse(window.sessionStorage.getItem(e))}catch(t){return window.sessionStorage.getItem(e)}},set:function(e,t){window.sessionStorage.setItem(e,JSON.stringify(t))},remove:function(e){window.sessionStorage.removeItem(e)},clear:function(){window.sessionStorage.clear()},check:function(e){return null!==o.get(e)}};export{n as cookie,r as localStorage,o as sessionStorage};
|