@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
1 lines • 5.54 kB
JavaScript
;function d(){return typeof window!="undefined"&&(window==null?void 0:window.document)!==void 0&&typeof document!="undefined"&&typeof navigator!="undefined"}var c=()=>{var e;try{if(typeof process!="undefined"&&(process!=null&&process.versions)&&((e=process==null?void 0:process.versions)!=null&&e.node)||typeof global=="object"&&(global==null?void 0:global.toString.call(global))==="[object global]")return !0}catch(t){}return false},S=()=>{var e,t;return !!(typeof window!="undefined"&&window&&typeof(window==null?void 0:window.process)=="object"&&((e=window==null?void 0:window.process)==null?void 0:e.type)==="renderer"||typeof process!="undefined"&&typeof(process==null?void 0:process.versions)=="object"&&((t=process.versions)!=null&&t.electron)||typeof navigator=="object"&&navigator&&typeof navigator.userAgent=="string"&&String(navigator==null?void 0:navigator.userAgent).toLowerCase().indexOf("electron")>=0)},h=()=>{if(typeof document!="undefined"&&document)try{return document.createEvent("TouchEvent"),!0}catch(e){try{return "ontouchstart"in window||"onmsgesturechange"in window}catch(t){}}return false},v=()=>typeof window=="undefined"&&typeof process!="undefined",y=()=>typeof window!="undefined"&&typeof window=="object",A=()=>{if(!d()||typeof navigator!="object"||!navigator||typeof navigator.userAgent!="string")return false;let e=navigator.userAgent.toLowerCase();return /android|webos|iphone|blackberry|iemobile|opera mini/i.test(e)},N=()=>{if(!d()||typeof navigator!="object"||!navigator||typeof navigator.userAgent!="string")return false;let e=navigator.userAgent.toLowerCase();return /android/i.test(e)},I=()=>{var e;return !y()||!(window!=null&&window.ReactNativeWebView)?false:typeof((e=window==null?void 0:window.ReactNativeWebView)==null?void 0:e.postMessage)=="function"},D=()=>c()&&process.platform==="darwin",P=()=>c()&&process.platform==="win32",x=()=>c()&&process.platform==="linux",p={isWeb:d,isLinux:x,isDarwin:D,isWin32:P,isNode:c,isElectron:S,isTouchDevice:h,isServerSide:v,isClientSide:y,isMobileBrowser:A,isAndroidMobileBrowser:N,isReactNativeWebview:I};var a=class e{static decycle(t,r=[]){if(typeof t=="function")return;if(!t||typeof t!="object")return t;if(r.includes(t))return null;let n=r.concat([t]);return Array.isArray(t)?t.map(o=>e.decycle(o,n)):Object.fromEntries(Object.entries(t).map(([o,g])=>[o,e.decycle(g,n)]))}static stringify(t,r=false){return typeof t=="string"?t:JSON.stringify(r!==false?e.decycle(t):t)}static isJSON(t){if(typeof t!="string")return false;let r=t.trim();if(r.length===0)return false;let n=r[0];if(n!=="{"&&n!=="[")return false;try{let o=JSON.parse(r);return o!==null&&typeof o=="object"}catch(o){return false}}static parse(t,r){if(typeof t=="string")try{t=JSON.parse(t,r);}catch(n){return t}if(t&&typeof t=="object")for(let n in t){let o=t[n];e.isJSON(o)&&(t[n]=e.parse(o,r));}return t}};function f(e){return !!(e&&typeof e=="string")}function C(e){return typeof e=="boolean"||!e||typeof e=="number"||typeof e=="string"||typeof e=="symbol"?false:Object(e).constructor===Promise||e.constructor&&(e.constructor.name==="Promise"||e.constructor.name==="AsyncFunction")||e instanceof Promise||typeof(e==null?void 0:e.then)=="function"&&typeof(e==null?void 0:e.catch)=="function"&&typeof(e==null?void 0:e.finally)=="function"?true:e&&typeof e.constructor=="function"&&Function.prototype.toString.call(e.constructor).replace(/\(.*\)/,"()")===Function.prototype.toString.call(Function).replace("Function","Promise").replace(/\(.*\)/,"()")}function m(e){return e&&Object.prototype.toString.call(e)==="[object Promise]"?true:C(e)}var s=class s{static get storage(){var r;let t=Reflect.getMetadata(s.sessionStorageMetaData,s);if(l(t)&&(this._storage=t),this._storage)return this._storage;if(p.isClientSide()&&typeof window!="undefined"&&window.localStorage&&((r=window.localStorage)!=null&&r.getItem))this._storage={get:n=>window.localStorage.getItem(n),set:(n,o)=>window.localStorage.setItem(n,o),remove:n=>window.localStorage.removeItem(n),removeAll:()=>window.localStorage.clear()};else {let n={};this._storage={get:o=>n[o],set:(o,g)=>n[o]=g,remove:o=>delete n[o],removeAll:()=>n={}};}return this._storage}static set storage(t){l(t)&&Reflect.defineMetadata(s.sessionStorageMetaData,t,s);}static get keyNamespace(){return f(this._keyNamespace)?this._keyNamespace:""}static set keyNamespace(t){f(t)&&(this._keyNamespace=t.trim().replace(/\s+/g,"-"));}static sanitizeKey(t){if(!t||!f(t))return "";t=t.trim().replace(/\s+/g,"-");let r=this.keyNamespace;return r?`${r}-${t}`:t}};s.sessionStorageMetaData=Symbol("sessionStorage"),s._keyNamespace=void 0;var i=s;function u(e){return i.sanitizeKey(e)}var b=(e,t)=>(e=e&&a.stringify(e,t),e==null&&(e=""),e),w=e=>{if(m(e))return new Promise((t,r)=>{e.then(n=>{t(a.parse(n));}).catch(n=>{r(n);});});if(e!=null)return a.parse(e)},O=e=>{if(e=u(e),i.storage&&e&&typeof e=="string"){let t=i.storage.get(e);return w(t)}},W=e=>{if(e=u(e),i.storage&&e&&typeof e=="string")return i.storage.remove(e)},M=()=>{if(i.storage)return i.storage.removeAll()},l=e=>{if(!e)return false;try{return ["get","set","remove","removeAll"].every(t=>typeof e[t]=="function")}catch(t){return false}},K={get:O,set:(e,t,r=true)=>(e=u(e),i.storage.set(e,b(t,r))),remove:W,handleGetValue:w,sanitizeKey:u,handleSetValue:b,isValidStorage:l,Manager:i,removeAll:M};function B(){return function(e){try{let t=new e;if(!l(t))return;i.storage=t;}catch(t){console.error(t," registering session storage");}}}exports.AttachSessionStorage=B;exports.Session=K;