threads
Version:
Web workers & worker threads as simple as a function call
30 lines (29 loc) • 996 B
JavaScript
// Source: <https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js>
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBundleURL = exports.getBaseURL = void 0;
let bundleURL;
function getBundleURLCached() {
if (!bundleURL) {
bundleURL = getBundleURL();
}
return bundleURL;
}
exports.getBundleURL = getBundleURLCached;
function getBundleURL() {
// Attempt to find the URL of the current script and use that as the base URL
try {
throw new Error;
}
catch (err) {
const matches = ("" + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);
if (matches) {
return getBaseURL(matches[0]);
}
}
return "/";
}
function getBaseURL(url) {
return ("" + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/, '$1') + '/';
}
exports.getBaseURL = getBaseURL;
;