1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var siteBasePath = '';
|
13 | var siteOrigin = void 0;
|
14 |
|
15 |
|
16 | function isAbsoluteUrl(url) {
|
17 | return (/^https?:/.test(url)
|
18 | );
|
19 | }
|
20 |
|
21 | function prefixUrl(url) {
|
22 | if (isAbsoluteUrl(url)) {
|
23 | return url;
|
24 | }
|
25 | if (siteBasePath && url.indexOf(siteBasePath) === 0) {
|
26 | return url;
|
27 | }
|
28 | if (!/^\//.test(url)) url = '/' + url;
|
29 | return siteBasePath + url;
|
30 | }
|
31 |
|
32 | function prefixUrlAbsolute(url) {
|
33 | if (isAbsoluteUrl(url)) {
|
34 | return url;
|
35 | }
|
36 | if (!siteOrigin) {
|
37 | if (process.env.NODE_ENV !== 'production') {
|
38 | throw new Error('The siteOrigin property is not specified in your Batfish configuration. Unable to prefix with absolute path.');
|
39 | }
|
40 | return url;
|
41 | }
|
42 | if (!/^\//.test(url)) url = '/' + url;
|
43 | return siteOrigin + siteBasePath + url;
|
44 | }
|
45 |
|
46 | function isUrlPrefixed(url) {
|
47 | return url.indexOf(siteBasePath) === 0;
|
48 | }
|
49 |
|
50 | prefixUrl._configure = function (a, b) {
|
51 | siteBasePath = a || '';
|
52 | siteOrigin = b;
|
53 | };
|
54 |
|
55 | exports.prefixUrl = prefixUrl;
|
56 | exports.prefixUrlAbsolute = prefixUrlAbsolute;
|
57 | exports.isUrlPrefixed = isUrlPrefixed; |
\ | No newline at end of file |