UNPKG

1.26 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).skypin={})}(this,(function(t){"use strict";let e=(n=new Map,{get:t=>n.get(t),set:(t,e)=>(n.set(t,e),e)});var n;let i="https://cdn.skypack.dev",s={pin:!0,min:!0};async function o(t){try{const e=await fetch(`${i}/${t}`),n=await e.text();let s=(/Normal:\s([\S]+)/g.exec(n)||["",""])[1],r=(/Minified:\s([\S]+)/g.exec(n)||["",""])[1];if("Not"===r||"Not"===s){let e=i+(/export\s\*\sfrom\s'([^\s;']+)/g.exec(n)||["",""])[1];return await fetch(e),o(t)}if(!(s&&r&&s.length&&r.length))throw"Invalid URL found";return{normal:s,minified:r}}catch(t){return console.log("Error fetching module from skypack. Returning empty strings"),console.log(t),{normal:"",minified:""}}}t.skypin=async function(t,n={}){if(n={...s,...n},t.startsWith(".")||t.startsWith("https://")||t.startsWith("http://"))return t;let[r,a="latest"]=t.split("@").filter((t=>t.length));r="@"===t.charAt(0)?`@${r}`:r;let f=`${r}@${a}`;return n.pin?await async function(t,n=!0){return e.get(t)||e.set(t,(await o(t))[n?"minified":"normal"])}(f,n.min):`${i}/${f}`},Object.defineProperty(t,"__esModule",{value:!0})}));