1 | var bundleURL = null;
|
2 | function getBundleURLCached() {
|
3 | if (!bundleURL) {
|
4 | bundleURL = getBundleURL();
|
5 | }
|
6 |
|
7 | return bundleURL;
|
8 | }
|
9 |
|
10 | function getBundleURL() {
|
11 |
|
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 |
|
24 | function getBaseURL(url) {
|
25 | return ('' + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)\/[^/]+$/, '$1') + '/';
|
26 | }
|
27 |
|
28 | exports.getBundleURL = getBundleURLCached;
|
29 | exports.getBaseURL = getBaseURL;
|