UNPKG

@wordpress/interactivity-router

Version:

Package that exposes state and actions from the `core/router` store, part of the Interactivity API.

28 lines (27 loc) 824 B
// packages/interactivity-router/src/assets/dynamic-importmap/fetch.ts var fetching = (url, parent) => { return ` fetching ${url}${parent ? ` from ${parent}` : ""}`; }; var jsContentType = /^(text|application)\/(x-)?javascript(;|$)/; async function fetchModule(url, fetchOpts, parent) { let res; try { res = await fetch(url, fetchOpts); } catch { throw Error(`Network error${fetching(url, parent)}.`); } if (!res.ok) { throw Error(`Error ${res.status}${fetching(url, parent)}.`); } const contentType = res.headers.get("content-type"); if (!jsContentType.test(contentType)) { throw Error( `Bad Content-Type "${contentType}"${fetching(url, parent)}.` ); } return { responseUrl: res.url, source: await res.text() }; } export { fetchModule }; //# sourceMappingURL=fetch.mjs.map