UNPKG

@analytics/storage-utils

Version:
3 lines (2 loc) 2.4 kB
import{get as t,GLOBAL as o,set as e,remove as r}from"@analytics/global-storage-utils";export{GLOBAL,globalContext}from"@analytics/global-storage-utils";import{hasCookies as s,getCookie as a,COOKIE as n,setCookie as i,removeCookie as l}from"@analytics/cookie-utils";export{COOKIE,getCookie,hasCookies,removeCookie,setCookie}from"@analytics/cookie-utils";import{hasLocalStorage as c,LOCAL_STORAGE as u}from"@analytics/localstorage-utils";export{LOCAL_STORAGE,hasLocalStorage}from"@analytics/localstorage-utils";import{hasSessionStorage as g,SESSION_STORAGE as f}from"@analytics/session-storage-utils";export{SESSION_STORAGE,hasSessionStorage}from"@analytics/session-storage-utils";import{isObject as m,isUndefined as S,ANY as p,isString as y,ALL as I}from"@analytics/type-utils";export{ALL,ANY}from"@analytics/type-utils";function k(t){let o=t;try{if(o=JSON.parse(t),"true"===o)return!0;if("false"===o)return!1;if(m(o))return o;parseFloat(o)===o&&(o=parseFloat(o))}catch(t){}if(null!==o&&""!==o)return o}const v=c(),O=g(),x=s();function C(o,e){if(!o)return;const r=A(e),s=!N(r),n=d(r)?k(localStorage.getItem(o)):void 0;if(s&&!S(n))return n;const i=h(r)?k(a(o)):void 0;if(s&&i)return i;const l=E(r)?k(sessionStorage.getItem(o)):void 0;if(s&&l)return l;const c=t(o);return s?c:{localStorage:n,sessionStorage:l,cookie:i,global:c}}function L(r,s,l){if(!r||S(s))return;const c={},g=A(l),m=JSON.stringify(s),p=!N(g);return d(g)&&(c[u]=F(u,s,k(localStorage.getItem(r))),localStorage.setItem(r,m),p)?c[u]:h(g)&&(c[n]=F(n,s,k(a(r))),i(r,m),p)?c[n]:E(g)&&(c[f]=F(f,s,k(sessionStorage.getItem(r))),sessionStorage.setItem(r,m),p)?c[f]:(c[o]=F(o,s,t(r)),e(r,s),p?c[o]:c)}function b(t,e){if(!t)return;const s=A(e),a=C(t,I),i={};return!S(a.localStorage)&&d(s)&&(localStorage.removeItem(t),i[u]=a.localStorage),!S(a.cookie)&&h(s)&&(l(t),i[n]=a.cookie),!S(a.sessionStorage)&&E(s)&&(sessionStorage.removeItem(t),i[f]=a.sessionStorage),!S(a.global)&&G(s,o)&&(r(t),i[o]=a.global),i}function A(t){return t?y(t)?t:t.storage:p}function d(t){return v&&G(t,u)}function h(t){return x&&G(t,n)}function E(t){return O&&G(t,f)}function N(t){return t===I||"all"===t}function G(t,o){return t===p||t===o||N(t)}function F(t,o,e){return{location:t,current:o,previous:e}}var J={setItem:L,getItem:C,removeItem:b};export{J as default,C as getItem,b as removeItem,L as setItem}; //# sourceMappingURL=analytics-util-storage.modern.js.map