ucc-utils
Version:
1 lines • 3.43 kB
JavaScript
function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(e){if(Array.isArray(e))return e}function r(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}function n(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var o=true;var a=false;var i,s;try{for(r=r.call(e);!(o=(i=r.next()).done);o=true){n.push(i.value);if(t&&n.length===t)break}}catch(e){a=true;s=e}finally{try{if(!o&&r["return"]!=null)r["return"]()}finally{if(a)throw s}}return n}function o(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(e,r){return t(e)||n(e,r)||i(e,r)||o()}function i(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor)n=t.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}import{a as s}from"../chunk-JZXLCA2E.mjs";var u={};s(u,{getAllCookies:function(){return m},getCookie:function(){return c},isCookieValid:function(){return g},removeCookie:function(){return f},setCookie:function(){return l}});var c=function(e){var t;var r="; ".concat(document.cookie).split("; ".concat(e,"="));return r.length===2?(t=r.pop())===null||t===void 0?void 0:t.split(";").shift():""},l=function(e,t,r){var n="".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(t));if(r.expires=r.expires||7,r.expires){var o=new Date;o.setTime(o.getTime()+r.expires*24*60*60*1e3),n+="; expires=".concat(o.toUTCString())}r.path&&(n+="; path=".concat(r.path)),r.domain&&(n+="; domain=".concat(r.domain)),r.secure&&(n+="; secure"),r.sameSite&&(n+="; samesite=".concat(r.sameSite)),document.cookie=n},f=function(e,t,r){l(e,"",{expires:-1,path:t,domain:r})},m=function(){var e={};return document.cookie.split(";").forEach(function(t){var r=a(t.split("="),2),n=r[0],o=r[1];e[n.trim()]=decodeURIComponent(o)}),e},g=function(e){return!!c(e)};var v={};s(v,{getLocalStorage:function(){return S},removeLocalStorage:function(){return d},setLocalStorage:function(){return p}});var S=function(e){var t=localStorage.getItem(e);if(!t)return null;var r=JSON.parse(t),n=r.expires,o=r.value;return new Date().getTime()>new Date(n).getTime()?(localStorage.removeItem(e),null):o},p=function(e,t,r){var n=r.expires,o=n===void 0?7:n;var a=new Date().getTime()+o*24*60*60*1e3,i=new Date(a).toUTCString(),s={value:t,expires:i};localStorage.setItem(e,JSON.stringify(s))},d=function(e){localStorage.removeItem(e)};var y={};s(y,{getSessionStorage:function(){return h},removeSessionStorage:function(){return k},setSessionStorage:function(){return C}});var h=function(e){var t=sessionStorage.getItem(e);return t?JSON.parse(t):null},C=function(e,t){sessionStorage.setItem(e,JSON.stringify(t))},k=function(e){sessionStorage.removeItem(e)};var I={};s(I,{IndexDB:function(){return x}});var x=function e(){"use strict";r(this,e)};var w={cookie:u,localStorage:v,sessionStorage:y,indexDB:I};export{x as IndexDB,w as default,m as getAllCookies,c as getCookie,S as getLocalStorage,h as getSessionStorage,g as isCookieValid,f as removeCookie,d as removeLocalStorage,k as removeSessionStorage,l as setCookie,p as setLocalStorage,C as setSessionStorage};