UNPKG

996 BJavaScriptView Raw
1"use strict";
2// Source: <https://github.com/parcel-bundler/parcel/blob/master/packages/core/parcel-bundler/src/builtins/bundle-url.js>
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.getBundleURL = exports.getBaseURL = void 0;
5let bundleURL;
6function getBundleURLCached() {
7 if (!bundleURL) {
8 bundleURL = getBundleURL();
9 }
10 return bundleURL;
11}
12exports.getBundleURL = getBundleURLCached;
13function getBundleURL() {
14 // Attempt to find the URL of the current script and use that as the base URL
15 try {
16 throw new Error;
17 }
18 catch (err) {
19 const matches = ("" + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);
20 if (matches) {
21 return getBaseURL(matches[0]);
22 }
23 }
24 return "/";
25}
26function getBaseURL(url) {
27 return ("" + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/, '$1') + '/';
28}
29exports.getBaseURL = getBaseURL;