1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = extractPathFromURL;
|
7 |
|
8 | var _escapeStringRegexp = _interopRequireDefault(require("escape-string-regexp"));
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function extractPathFromURL(prefixes, url) {
|
13 | for (const prefix of prefixes) {
|
14 | var _prefix$match$, _prefix$match;
|
15 |
|
16 | const protocol = (_prefix$match$ = (_prefix$match = prefix.match(/^[^:]+:/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[0]) !== null && _prefix$match$ !== void 0 ? _prefix$match$ : '';
|
17 | const host = prefix.replace(new RegExp(`^${(0, _escapeStringRegexp.default)(protocol)}`), '').replace(/\/+/g, '/')
|
18 | .replace(/^\//, '');
|
19 |
|
20 | const prefixRegex = new RegExp(`^${(0, _escapeStringRegexp.default)(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : (0, _escapeStringRegexp.default)(it)).join('\\.')}`);
|
21 | const normalizedURL = url.replace(/\/+/g, '/');
|
22 |
|
23 | if (prefixRegex.test(normalizedURL)) {
|
24 | return normalizedURL.replace(prefixRegex, '');
|
25 | }
|
26 | }
|
27 |
|
28 | return undefined;
|
29 | }
|
30 |
|
\ | No newline at end of file |