UNPKG

@ghoran/text

Version:

Quran text

64 lines (61 loc) 1.78 kB
const textMetaData = [ { name: "hafs" }, { name: "hafs-v13" }, { name: "imla" }, { name: "tanzil-simple-clean" }, { name: "tanzil-simple-min" } ]; function importText(type) { switch (type) { case "tanzil-simple-clean": return import('./chunks/quran-text-tanzil-simple-clean.mjs').then(function (n) { return n.q; }); case "tanzil-simple-min": return import('./chunks/quran-text-tanzil-simple-min.mjs').then(function (n) { return n.q; }); case "imla": return import('./chunks/quran-text-imla.mjs').then(function (n) { return n.q; }); case "hafs": return import('./chunks/quran-text-hafs.mjs').then(function (n) { return n.q; }); case "hafs-v13": return import('./chunks/quran-text-hafs-v13.mjs').then(function (n) { return n.q; }); case "qpc-v1": return import('./chunks/quran-text-qpc-v1.mjs').then(function (n) { return n.q; }); case "qpc-v2": return import('./chunks/quran-text-qpc-v2.mjs').then(function (n) { return n.q; }); } } async function loadText(type, { cacheName = "@ghoran", cachePrefix = "@ghoran" } = {}) { const cacheKey = `/${cachePrefix}/quran-text/${type}?v=0.2`; try { const cache = await caches.open(cacheName); const response = await cache.match(cacheKey); if (response) { const text2 = await response.json(); return text2; } } catch (err) { } const result = await importText(type); const text = result.default; try { const cache = await caches.open(cacheName); await cache.put( cacheKey, new Response(JSON.stringify(text), { headers: { "content-type": "application/json" } }) ); } finally { return text; } } export { importText, loadText, textMetaData };