1 | "use strict";
|
2 |
|
3 |
|
4 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
5 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
6 | };
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | exports.URLExt = void 0;
|
9 | const path_1 = require("path");
|
10 | const url_parse_1 = __importDefault(require("url-parse"));
|
11 |
|
12 |
|
13 |
|
14 | var URLExt;
|
15 | (function (URLExt) {
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function parse(url) {
|
24 | if (typeof document !== 'undefined' && document) {
|
25 | const a = document.createElement('a');
|
26 | a.href = url;
|
27 | return a;
|
28 | }
|
29 | return url_parse_1.default(url);
|
30 | }
|
31 | URLExt.parse = parse;
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function getHostName(url) {
|
40 | return url_parse_1.default(url).hostname;
|
41 | }
|
42 | URLExt.getHostName = getHostName;
|
43 | function normalize(url) {
|
44 | return url && parse(url).toString();
|
45 | }
|
46 | URLExt.normalize = normalize;
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function join(...parts) {
|
55 | const u = url_parse_1.default(parts[0], {});
|
56 | const prefix = `${u.protocol}${u.slashes ? '//' : ''}${u.auth}${u.auth ? '@' : ''}${u.host}`;
|
57 |
|
58 | const path = path_1.posix.join(`${!!prefix && u.pathname[0] !== '/' ? '/' : ''}${u.pathname}`, ...parts.slice(1));
|
59 | return `${prefix}${path === '.' ? '' : path}`;
|
60 | }
|
61 | URLExt.join = join;
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | function encodeParts(url) {
|
74 | return join(...url.split('/').map(encodeURIComponent));
|
75 | }
|
76 | URLExt.encodeParts = encodeParts;
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function objectToQueryString(value) {
|
88 | const keys = Object.keys(value).filter(key => key.length > 0);
|
89 | if (!keys.length) {
|
90 | return '';
|
91 | }
|
92 | return ('?' +
|
93 | keys
|
94 | .map(key => {
|
95 | const content = encodeURIComponent(String(value[key]));
|
96 | return key + (content ? '=' + content : '');
|
97 | })
|
98 | .join('&'));
|
99 | }
|
100 | URLExt.objectToQueryString = objectToQueryString;
|
101 | |
102 |
|
103 |
|
104 | function queryStringToObject(value) {
|
105 | return value
|
106 | .replace(/^\?/, '')
|
107 | .split('&')
|
108 | .reduce((acc, val) => {
|
109 | const [key, value] = val.split('=');
|
110 | if (key.length > 0) {
|
111 | acc[key] = decodeURIComponent(value || '');
|
112 | }
|
113 | return acc;
|
114 | }, {});
|
115 | }
|
116 | URLExt.queryStringToObject = queryStringToObject;
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | function isLocal(url) {
|
125 | const { protocol } = parse(url);
|
126 | return ((!protocol || url.toLowerCase().indexOf(protocol) !== 0) &&
|
127 | url.indexOf('/') !== 0);
|
128 | }
|
129 | URLExt.isLocal = isLocal;
|
130 | })(URLExt = exports.URLExt || (exports.URLExt = {}));
|
131 |
|
\ | No newline at end of file |