1 | import escapeStringRegexp from 'escape-string-regexp';
|
2 | export default function extractPathFromURL(prefixes, url) {
|
3 | for (const prefix of prefixes) {
|
4 | var _prefix$match$, _prefix$match;
|
5 |
|
6 | 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$ : '';
|
7 | const host = prefix.replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '').replace(/\/+/g, '/')
|
8 | .replace(/^\//, '');
|
9 |
|
10 | const prefixRegex = new RegExp(`^${escapeStringRegexp(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : escapeStringRegexp(it)).join('\\.')}`);
|
11 | const normalizedURL = url.replace(/\/+/g, '/');
|
12 |
|
13 | if (prefixRegex.test(normalizedURL)) {
|
14 | return normalizedURL.replace(prefixRegex, '');
|
15 | }
|
16 | }
|
17 |
|
18 | return undefined;
|
19 | }
|
20 |
|
\ | No newline at end of file |