UNPKG

rich-component

Version:

library providing means to work conveniently with HTML based Web Components

1 lines 479 B
export{e as fetchTemplate};const t={};async function e(e,n=!1){if(!e||"string"!=typeof e)throw new Error(`invalid template URL: ${e}`);let r=t[e]||null;return r&&!n||(r=new Promise((t,n)=>{fetch(e).then(t=>{if(t.ok)return t.text();throw new Error(`failed to fetch template from '${e}', status ${t.status}`)}).then(n=>{if(!n)throw new Error(`failed to fetch template from '${e}', no content`);{const e=document.createElement("template");e.innerHTML=n,t(e)}}).catch(n)}),t[e]=r),r}