UNPKG

697 BJavaScriptView Raw
1var bundleURL = null;
2function getBundleURLCached() {
3 if (!bundleURL) {
4 bundleURL = getBundleURL();
5 }
6
7 return bundleURL;
8}
9
10function getBundleURL() {
11 // Attempt to find the URL of the current script and use that as the base URL
12 try {
13 throw new Error;
14 } catch (err) {
15 var matches = ('' + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);
16 if (matches) {
17 return getBaseURL(matches[0]);
18 }
19 }
20
21 return '/';
22}
23
24function getBaseURL(url) {
25 return ('' + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)\/[^/]+$/, '$1') + '/';
26}
27
28exports.getBundleURL = getBundleURLCached;
29exports.getBaseURL = getBaseURL;