UNPKG

cache-kit

Version:

A simple caching layer for fetch requests — supports memory, browser (localStorage), and Node.js (filesystem) adapters with smart strategies.

2 lines (1 loc) 1.25 kB
function e(e,o,n,r){return new(n||(n=Promise))((function(t,d){function a(e){try{c(r.next(e))}catch(e){d(e)}}function i(e){try{c(r.throw(e))}catch(e){d(e)}}function c(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,i)}c((r=r.apply(e,o||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o=(o,n,r)=>e(void 0,void 0,void 0,(function*(){var e;const t=null===(e=null==n?void 0:n.method)||void 0===e?void 0:e.toLowerCase();let d;const a=new URL(o).href;try{if(t&&"get"!==t||(null==n?void 0:n.body))d=yield fetch(o,n);else switch(r.adapter){case"memory":{const{default:e}=yield import("./memory-DRkXbpxz.js");d=yield e(a,n,r);break}case"browser":{if("undefined"==typeof window)throw new Error("Browser adapter cannot be used in a Node.js environment.");const{default:e}=yield import("./browser-DmV3PaYm.js");d=yield e(a,n,r);break}case"node":{if("undefined"!=typeof window)throw new Error("Node adapter cannot be used in the browser.");const{default:e}=yield import("./node-DBR-DQyW.js");d=yield e(a,n,r);break}default:throw new Error(`Unknown adapter: ${r.adapter}`)}}catch(e){console.warn("⚠️ cachedFetch fallback due to error:",e),d=yield fetch(o,n)}return d}));export{e as _,o as c};