@zthun/webigail-url 5.0.3 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +669 -715
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.js +645 -711
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,726 +1,679 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let lodash_es = require("lodash-es");
|
|
25
|
+
let url_parse = require("url-parse");
|
|
26
|
+
url_parse = __toESM(url_parse);
|
|
27
|
+
//#region src/mime/mime-type-application.mts
|
|
28
|
+
/**
|
|
29
|
+
* Application mime types.
|
|
30
|
+
*/ var ZMimeTypeApplication = /* @__PURE__ */ function(ZMimeTypeApplication) {
|
|
31
|
+
/**
|
|
32
|
+
* JSON data.
|
|
33
|
+
*/ ZMimeTypeApplication["JSON"] = "application/json";
|
|
34
|
+
/**
|
|
35
|
+
* The unknown type.
|
|
36
|
+
*
|
|
37
|
+
* Used for raw byte data.
|
|
38
|
+
*/ ZMimeTypeApplication["OctetStream"] = "application/octet-stream";
|
|
39
|
+
/**
|
|
40
|
+
* Compressed zip stream.
|
|
41
|
+
*/ ZMimeTypeApplication["Zip"] = "application/zip";
|
|
42
|
+
return ZMimeTypeApplication;
|
|
23
43
|
}({});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/mime/mime-type-image.mts
|
|
46
|
+
/**
|
|
47
|
+
* Mime types for images.
|
|
48
|
+
*/ var ZMimeTypeImage = /* @__PURE__ */ function(ZMimeTypeImage) {
|
|
49
|
+
/**
|
|
50
|
+
* Good choice for lossless animation sequences (GIF is less performant). AVIF and
|
|
51
|
+
* WebP have better performance but less broad browser support.
|
|
52
|
+
*/ ZMimeTypeImage["APNG"] = "image/apng";
|
|
53
|
+
/**
|
|
54
|
+
* Good choice for both images and animated images due to high performance and
|
|
55
|
+
* royalty free image format. It offers much better compression than PNG or JPEG
|
|
56
|
+
* with support for higher color depths, animated frames, transparency etc.
|
|
57
|
+
*
|
|
58
|
+
* Note that when using AVIF, you should include fallbacks to formats with
|
|
59
|
+
* better browser support (i.e. using the <picture> element).
|
|
60
|
+
*/ ZMimeTypeImage["AVIF"] = "image/avif";
|
|
61
|
+
/**
|
|
62
|
+
* Good choice for simple images and animations. Prefer PNG for lossless and
|
|
63
|
+
* indexed still images, and consider WebP, AVIF or APNG for animation sequences.
|
|
64
|
+
*/ ZMimeTypeImage["GIF"] = "image/gif";
|
|
65
|
+
/**
|
|
66
|
+
* Good choice for lossy compression of still images (currently the most popular). Prefer
|
|
67
|
+
* PNG when more precise reproduction of the image is required, or WebP/AVIF if both better
|
|
68
|
+
* reproduction and higher compression are required.
|
|
69
|
+
*/ ZMimeTypeImage["JPEG"] = "image/jpeg";
|
|
70
|
+
/**
|
|
71
|
+
* PNG is preferred over JPEG for more precise reproduction of source images, or when
|
|
72
|
+
* transparency is needed. WebP/AVIF provide even better compression and reproduction,
|
|
73
|
+
* but browser support is more limited.
|
|
74
|
+
*/ ZMimeTypeImage["PNG"] = "image/png";
|
|
75
|
+
/**
|
|
76
|
+
* Vector image format; ideal for user interface elements, icons, diagrams, etc., that
|
|
77
|
+
* must be drawn accurately at different sizes.
|
|
78
|
+
*/ ZMimeTypeImage["SVG"] = "image/svg+xml";
|
|
79
|
+
/**
|
|
80
|
+
* Excellent choice for both images and animated images. WebP offers much better compression
|
|
81
|
+
* than PNG or JPEG with support for higher color depths, animated frames, transparency etc.
|
|
82
|
+
* AVIF offers slightly better compression, but is not quite as well-supported in browsers
|
|
83
|
+
* and does not support progressive rendering.
|
|
84
|
+
*/ ZMimeTypeImage["WebP"] = "image/webp";
|
|
85
|
+
return ZMimeTypeImage;
|
|
65
86
|
}({});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/mime/mime-type-text.mts
|
|
89
|
+
/**
|
|
90
|
+
* Mime types for text based data.
|
|
91
|
+
*/ var ZMimeTypeText = /* @__PURE__ */ function(ZMimeTypeText) {
|
|
92
|
+
/**
|
|
93
|
+
* Style files used in html documents must be sent as
|
|
94
|
+
* css.
|
|
95
|
+
*/ ZMimeTypeText["CSS"] = "text/css";
|
|
96
|
+
/**
|
|
97
|
+
* Comma separated values.
|
|
98
|
+
*/ ZMimeTypeText["CSV"] = "text/csv";
|
|
99
|
+
/**
|
|
100
|
+
* JavaScript.
|
|
101
|
+
*/ ZMimeTypeText["EcmaScript"] = "text/ecmascript";
|
|
102
|
+
/**
|
|
103
|
+
* Hyper Text Markup Language. Markup language for
|
|
104
|
+
* web pages.
|
|
105
|
+
*/ ZMimeTypeText["HTML"] = "text/html";
|
|
106
|
+
/**
|
|
107
|
+
* JavaScript.
|
|
108
|
+
*/ ZMimeTypeText["JavaScript"] = "text/javascript";
|
|
109
|
+
/**
|
|
110
|
+
* Plain (basic) text.
|
|
111
|
+
*/ ZMimeTypeText["Plain"] = "text/plain";
|
|
112
|
+
/**
|
|
113
|
+
* Xtreme Markup Language.
|
|
114
|
+
*
|
|
115
|
+
* Superset of HTML. Bulky, but can
|
|
116
|
+
* represent anything.
|
|
117
|
+
*/ ZMimeTypeText["XML"] = "text/xml";
|
|
118
|
+
return ZMimeTypeText;
|
|
97
119
|
}({});
|
|
98
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/mime/mime-type.mts
|
|
99
122
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
...lodashEs.keyBy(Object.values(ZMimeTypeText)),
|
|
107
|
-
...lodashEs.keyBy(Object.values(ZMimeTypeImage))
|
|
123
|
+
* A mapping of supported mime types.
|
|
124
|
+
*/ var ZSupportedMimeTypes = Object.freeze({
|
|
125
|
+
"": "text/plain;charset=ASCII",
|
|
126
|
+
...(0, lodash_es.keyBy)(Object.values(ZMimeTypeApplication)),
|
|
127
|
+
...(0, lodash_es.keyBy)(Object.values(ZMimeTypeText)),
|
|
128
|
+
...(0, lodash_es.keyBy)(Object.values(ZMimeTypeImage))
|
|
108
129
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (key in obj) {
|
|
112
|
-
Object.defineProperty(obj, key, {
|
|
113
|
-
value: value,
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
writable: true
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
obj[key] = value;
|
|
120
|
-
}
|
|
121
|
-
return obj;
|
|
122
|
-
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/data/data-url.mts
|
|
123
132
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*/ info() {
|
|
245
|
-
const other = {
|
|
246
|
-
...this._data
|
|
247
|
-
};
|
|
248
|
-
other.buffer = this._data.buffer.slice();
|
|
249
|
-
return other;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Initializes a new instance of this object.
|
|
253
|
-
*/ constructor(){
|
|
254
|
-
/**
|
|
255
|
-
* The representation of the data url object.
|
|
256
|
-
*/ _define_property$1(this, "_data", void 0);
|
|
257
|
-
this._data = {
|
|
258
|
-
mimeType: "",
|
|
259
|
-
encoding: "utf8",
|
|
260
|
-
buffer: new Uint8Array([])
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function _define_property(obj, key, value) {
|
|
266
|
-
if (key in obj) {
|
|
267
|
-
Object.defineProperty(obj, key, {
|
|
268
|
-
value: value,
|
|
269
|
-
enumerable: true,
|
|
270
|
-
configurable: true,
|
|
271
|
-
writable: true
|
|
272
|
-
});
|
|
273
|
-
} else {
|
|
274
|
-
obj[key] = value;
|
|
275
|
-
}
|
|
276
|
-
return obj;
|
|
277
|
-
}
|
|
133
|
+
* Represents an object that is helpful in building a data url with support
|
|
134
|
+
* for data encoding.
|
|
135
|
+
*/ var ZDataUrlBuilder = class {
|
|
136
|
+
/**
|
|
137
|
+
* The representation of the data url object.
|
|
138
|
+
*/ _data;
|
|
139
|
+
/**
|
|
140
|
+
* Initializes a new instance of this object.
|
|
141
|
+
*/ constructor() {
|
|
142
|
+
this._data = {
|
|
143
|
+
mimeType: "",
|
|
144
|
+
encoding: "utf8",
|
|
145
|
+
buffer: new Uint8Array([])
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Parses an existing data url and sets all properties.
|
|
150
|
+
*
|
|
151
|
+
* @param url -
|
|
152
|
+
* The url to parse.
|
|
153
|
+
*
|
|
154
|
+
* @returns
|
|
155
|
+
* This object.
|
|
156
|
+
*/ parse(url) {
|
|
157
|
+
this._data = {
|
|
158
|
+
mimeType: "",
|
|
159
|
+
encoding: "utf8",
|
|
160
|
+
buffer: new Uint8Array([])
|
|
161
|
+
};
|
|
162
|
+
if (!url.startsWith("data:")) return this;
|
|
163
|
+
url = url.substring(5);
|
|
164
|
+
const parts = url.split(",");
|
|
165
|
+
if (parts.length < 2) return this;
|
|
166
|
+
const [mimeType, ...bodyParts] = parts;
|
|
167
|
+
let [type, ...params] = mimeType.split(";");
|
|
168
|
+
const isBase64 = (0, lodash_es.last)(params) === "base64";
|
|
169
|
+
this._data.encoding = isBase64 ? "base64" : "utf8";
|
|
170
|
+
if (isBase64) params.pop();
|
|
171
|
+
if (!Object.hasOwnProperty.call(ZSupportedMimeTypes, type)) {
|
|
172
|
+
type = ZMimeTypeApplication.OctetStream;
|
|
173
|
+
params = [];
|
|
174
|
+
}
|
|
175
|
+
type = [type, ...params].join(";");
|
|
176
|
+
this._data.mimeType = type;
|
|
177
|
+
let body = bodyParts.join("%2C");
|
|
178
|
+
if (isBase64) try {
|
|
179
|
+
body = atob(body);
|
|
180
|
+
} catch {
|
|
181
|
+
body = "";
|
|
182
|
+
}
|
|
183
|
+
else body = decodeURIComponent(body);
|
|
184
|
+
this._data.buffer = new TextEncoder().encode(body);
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sets the mime type.
|
|
189
|
+
*
|
|
190
|
+
* @param type -
|
|
191
|
+
* The mime type.
|
|
192
|
+
*
|
|
193
|
+
* @returns
|
|
194
|
+
* This object.
|
|
195
|
+
*/ mimeType(type) {
|
|
196
|
+
this._data.mimeType = type;
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Sets the data buffer.
|
|
201
|
+
*
|
|
202
|
+
* @param data -
|
|
203
|
+
* The data to set. If you pass a raw string, then the input encoding
|
|
204
|
+
* is expected to be utf8.
|
|
205
|
+
* @returns
|
|
206
|
+
* This object.
|
|
207
|
+
*/ buffer(data) {
|
|
208
|
+
this._data.buffer = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sets the output encoding.
|
|
213
|
+
*
|
|
214
|
+
* If you output encode the data as utf8, then it will be properly
|
|
215
|
+
* escaped.
|
|
216
|
+
*
|
|
217
|
+
* @param encoding -
|
|
218
|
+
* The output encoding.
|
|
219
|
+
*
|
|
220
|
+
* @returns
|
|
221
|
+
* This object.
|
|
222
|
+
*/ encode(encoding) {
|
|
223
|
+
this._data.encoding = encoding;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Builds the url string and returns it.
|
|
228
|
+
*
|
|
229
|
+
* @returns The url string.
|
|
230
|
+
*/ build() {
|
|
231
|
+
const protocol = "data";
|
|
232
|
+
const modifier = this._data.encoding === "base64" ? ";base64" : "";
|
|
233
|
+
let raw = new TextDecoder("utf8").decode(this._data.buffer);
|
|
234
|
+
if (this._data.encoding === "utf8") {
|
|
235
|
+
raw = encodeURIComponent(raw);
|
|
236
|
+
raw = raw.split("!").join("%21");
|
|
237
|
+
}
|
|
238
|
+
if (this._data.encoding === "base64") raw = btoa(raw);
|
|
239
|
+
return `${protocol}:${this._data.mimeType}${modifier},${raw}`;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Gets the current information about the url being built.
|
|
243
|
+
*
|
|
244
|
+
* @returns The current information about the url being built.
|
|
245
|
+
*/ info() {
|
|
246
|
+
const other = { ...this._data };
|
|
247
|
+
other.buffer = this._data.buffer.slice();
|
|
248
|
+
return other;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/url/url.mts
|
|
278
253
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
254
|
+
* The api to target for YouTube.
|
|
255
|
+
*/ var ZYouTubeApi = /* @__PURE__ */ function(ZYouTubeApi) {
|
|
256
|
+
/**
|
|
257
|
+
* An embedded video link.
|
|
258
|
+
*/ ZYouTubeApi["Embed"] = "embed";
|
|
259
|
+
/**
|
|
260
|
+
* A watch video link.
|
|
261
|
+
*/ ZYouTubeApi["Watch"] = "watch";
|
|
262
|
+
return ZYouTubeApi;
|
|
288
263
|
}({});
|
|
289
264
|
/**
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* The url to the gravatar api.
|
|
706
|
-
*/ _define_property(ZUrlBuilder, "UrlGravatar", "https://s.gravatar.com/avatar");
|
|
707
|
-
/**
|
|
708
|
-
* The url to youtube.
|
|
709
|
-
*
|
|
710
|
-
* This is mostly used to embed videos.
|
|
711
|
-
*/ _define_property(ZUrlBuilder, "UrlYouTube", "https://www.youtube.com");
|
|
712
|
-
/**
|
|
713
|
-
* A mapping between protocol and default port.
|
|
714
|
-
*/ _define_property(ZUrlBuilder, "ProtocolPorts", {
|
|
715
|
-
http: 80,
|
|
716
|
-
https: 443,
|
|
717
|
-
ftp: 21,
|
|
718
|
-
sftp: 22,
|
|
719
|
-
ssh: 22,
|
|
720
|
-
smtp: 25,
|
|
721
|
-
smb: 445
|
|
722
|
-
});
|
|
723
|
-
|
|
265
|
+
* Represents an object that is helpful in building a url.
|
|
266
|
+
*/ var ZUrlBuilder = class ZUrlBuilder {
|
|
267
|
+
/**
|
|
268
|
+
* The url to the gravatar api.
|
|
269
|
+
*/ static UrlGravatar = "https://s.gravatar.com/avatar";
|
|
270
|
+
/**
|
|
271
|
+
* The url to youtube.
|
|
272
|
+
*
|
|
273
|
+
* This is mostly used to embed videos.
|
|
274
|
+
*/ static UrlYouTube = "https://www.youtube.com";
|
|
275
|
+
/**
|
|
276
|
+
* A mapping between protocol and default port.
|
|
277
|
+
*/ static ProtocolPorts = {
|
|
278
|
+
http: 80,
|
|
279
|
+
https: 443,
|
|
280
|
+
ftp: 21,
|
|
281
|
+
sftp: 22,
|
|
282
|
+
ssh: 22,
|
|
283
|
+
smtp: 25,
|
|
284
|
+
smb: 445
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Gets whether the given protocols default port is port.
|
|
288
|
+
*
|
|
289
|
+
* The main purpose of this method is to determine if a url requires
|
|
290
|
+
* a port section. Therefore, there are some special behaviors which may
|
|
291
|
+
* not be obvious:
|
|
292
|
+
*
|
|
293
|
+
* 1. If the port is falsy then this method returns true.
|
|
294
|
+
* 2. If the port is NaN, then this method returns true.
|
|
295
|
+
* 3. If the port is a string that evaluates to 0, then this method returns true.
|
|
296
|
+
* 4. If port is less than 0, then this method returns true.
|
|
297
|
+
*
|
|
298
|
+
* @param protocol -
|
|
299
|
+
* The protocol to check.
|
|
300
|
+
* @param port -
|
|
301
|
+
* The port to compare.
|
|
302
|
+
*
|
|
303
|
+
* @returns
|
|
304
|
+
* True if the default port for protocol is port.
|
|
305
|
+
*/ static defaults(protocol, port) {
|
|
306
|
+
const numericPort = +port;
|
|
307
|
+
if (isNaN(numericPort) || numericPort < 1) return true;
|
|
308
|
+
return ZUrlBuilder.ProtocolPorts[protocol] === +port;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* The representation of the url object.
|
|
312
|
+
*/ _url;
|
|
313
|
+
/**
|
|
314
|
+
* Initializes a new instance of this object.
|
|
315
|
+
*
|
|
316
|
+
* @param protocol -
|
|
317
|
+
* The protocol to use.
|
|
318
|
+
* @param hostname -
|
|
319
|
+
* The hostname to connect with.
|
|
320
|
+
*/ constructor(protocol = "http", hostname = "localhost") {
|
|
321
|
+
this._url = {
|
|
322
|
+
protocol,
|
|
323
|
+
hostname,
|
|
324
|
+
path: ["/"],
|
|
325
|
+
hash: "",
|
|
326
|
+
params: []
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Fills the information from the current location data.
|
|
331
|
+
*
|
|
332
|
+
* @param loc -
|
|
333
|
+
* The optional location object to populate with.
|
|
334
|
+
*
|
|
335
|
+
* @returns
|
|
336
|
+
* This object.
|
|
337
|
+
*/ location(loc) {
|
|
338
|
+
this.protocol(loc.protocol).hostname(loc.hostname).hash(loc.hash).path(loc.pathname).port(+loc.port);
|
|
339
|
+
let search = loc.search;
|
|
340
|
+
if (search.startsWith("?")) {
|
|
341
|
+
search = search.slice(1);
|
|
342
|
+
search.split("&").map((pair) => pair.split("=")).forEach((matrix) => this.param(matrix[0], matrix[1]));
|
|
343
|
+
}
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Fills the information for an api path call.
|
|
348
|
+
*
|
|
349
|
+
* This is a combination of location, hash with an empty string, and an
|
|
350
|
+
* append of the basePath.
|
|
351
|
+
*
|
|
352
|
+
* @param loc -
|
|
353
|
+
* The optional location object to populate with.
|
|
354
|
+
* @param basePath -
|
|
355
|
+
* The basePath for the api. Generally, it's best to
|
|
356
|
+
* just keep this as api and have your server accept
|
|
357
|
+
* this path.
|
|
358
|
+
*
|
|
359
|
+
* @returns
|
|
360
|
+
* This object.
|
|
361
|
+
*/ api(loc, basePath = "api") {
|
|
362
|
+
return this.location(loc).hash("").path(basePath);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Parses an existing url and sets all properties.
|
|
366
|
+
*
|
|
367
|
+
* If you give this a path without the protocol and hostname, then it will
|
|
368
|
+
* automatically append the protocol and host of the browser window if it
|
|
369
|
+
* exists.
|
|
370
|
+
*
|
|
371
|
+
* This method sets all the properties so if you need to modify the url before
|
|
372
|
+
* parsing it, it is best to always call this method first.
|
|
373
|
+
*
|
|
374
|
+
* @param url -
|
|
375
|
+
* The url to parse.
|
|
376
|
+
*
|
|
377
|
+
* @returns
|
|
378
|
+
* This object.
|
|
379
|
+
*/ parse(url) {
|
|
380
|
+
const current = new url_parse.default(url, true);
|
|
381
|
+
this.protocol(current.protocol).username(current.username).password(current.password).hostname(current.hostname).hash(current.hash).path(current.pathname).port(current.port ? +current.port : void 0);
|
|
382
|
+
Object.keys(current.query).forEach((key) => this.param(key, current.query[key]));
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Sets the url for a user gravatar.
|
|
387
|
+
*
|
|
388
|
+
* @param hash -
|
|
389
|
+
* The md5 email hash.
|
|
390
|
+
* @param size -
|
|
391
|
+
* The dimensional size of the gravatar image.
|
|
392
|
+
*
|
|
393
|
+
* @returns
|
|
394
|
+
* This object.
|
|
395
|
+
*/ gravatar(hash, size) {
|
|
396
|
+
let current = this.parse(ZUrlBuilder.UrlGravatar);
|
|
397
|
+
current = hash ? current.append(hash) : current;
|
|
398
|
+
current = size ? current.param("s", String(size)) : current;
|
|
399
|
+
return current;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Sets the url target to something on YouTube.
|
|
403
|
+
*
|
|
404
|
+
* @param api -
|
|
405
|
+
* The supported api.
|
|
406
|
+
* @param id -
|
|
407
|
+
* The id of the video. If api is set,
|
|
408
|
+
* then this parameter is required.
|
|
409
|
+
*
|
|
410
|
+
* @returns
|
|
411
|
+
* The url for YouTube. If you set the api and
|
|
412
|
+
* id, then the url will be targeted to a specific video,
|
|
413
|
+
* otherwise, the base domain url of YouTube will be returned.
|
|
414
|
+
*/ youTube(api, id) {
|
|
415
|
+
let current = this.parse(ZUrlBuilder.UrlYouTube);
|
|
416
|
+
current = api ? current.path(`${api}/${id}`) : current;
|
|
417
|
+
if (api === "watch") current = current.path(api).param("v", id);
|
|
418
|
+
return current;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Sets the protocol.
|
|
422
|
+
*
|
|
423
|
+
* @param protocol -
|
|
424
|
+
* The protocol.
|
|
425
|
+
*
|
|
426
|
+
* @returns
|
|
427
|
+
* This object.
|
|
428
|
+
*/ protocol(protocol) {
|
|
429
|
+
this._url.protocol = protocol;
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Sets the user name.
|
|
434
|
+
*
|
|
435
|
+
* Used for things like ssh and ftp.
|
|
436
|
+
*
|
|
437
|
+
* @param user -
|
|
438
|
+
* The username
|
|
439
|
+
*
|
|
440
|
+
* @returns
|
|
441
|
+
* This object.
|
|
442
|
+
*/ username(user) {
|
|
443
|
+
this._url.username = user;
|
|
444
|
+
return this;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Sets the password.
|
|
448
|
+
*
|
|
449
|
+
* This is only valid if the username is set.
|
|
450
|
+
*
|
|
451
|
+
* @param pwd -
|
|
452
|
+
* The user password.
|
|
453
|
+
*
|
|
454
|
+
* @returns
|
|
455
|
+
* This object.
|
|
456
|
+
*/ password(pwd) {
|
|
457
|
+
this._url.password = pwd;
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Sets the host name.
|
|
462
|
+
*
|
|
463
|
+
* This sets the entire hostname as the root domain. This
|
|
464
|
+
* will blow away any subdomains added, so it's best to
|
|
465
|
+
* call this method first.
|
|
466
|
+
*
|
|
467
|
+
* @param host -
|
|
468
|
+
* The hostname.
|
|
469
|
+
*
|
|
470
|
+
* @returns
|
|
471
|
+
* This object.
|
|
472
|
+
*/ hostname(host) {
|
|
473
|
+
this._url.hostname = host;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Adds a subdomain in front of the hostname.
|
|
478
|
+
*
|
|
479
|
+
* If a hostname was never set, then domain becomes the hostname.
|
|
480
|
+
*
|
|
481
|
+
* @param domain -
|
|
482
|
+
* The domain to append.
|
|
483
|
+
*
|
|
484
|
+
* @returns
|
|
485
|
+
* This object.
|
|
486
|
+
*/ subdomain(domain) {
|
|
487
|
+
this._url.hostname = this._url.hostname ? `${domain}.${this._url.hostname}` : domain;
|
|
488
|
+
return this;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Removes a subdomain from the current domain.
|
|
492
|
+
*
|
|
493
|
+
* @returns
|
|
494
|
+
* This object.
|
|
495
|
+
*/ popSubdomain() {
|
|
496
|
+
const parts = this._url.hostname.split(".");
|
|
497
|
+
parts.splice(0, 1);
|
|
498
|
+
this._url.hostname = parts.join(".");
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Sets the port.
|
|
503
|
+
*
|
|
504
|
+
* @param port -
|
|
505
|
+
* The port.
|
|
506
|
+
*
|
|
507
|
+
* @returns
|
|
508
|
+
* This object.
|
|
509
|
+
*/ port(port) {
|
|
510
|
+
this._url.port = port;
|
|
511
|
+
return this;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Removes all existing path segments and restarts the path.
|
|
515
|
+
*
|
|
516
|
+
* @param path -
|
|
517
|
+
* The starting path.
|
|
518
|
+
*
|
|
519
|
+
* @returns
|
|
520
|
+
* This object.
|
|
521
|
+
*/ path(path) {
|
|
522
|
+
this._url.path = [path];
|
|
523
|
+
return this;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Appends a path segment.
|
|
527
|
+
*
|
|
528
|
+
* @param path -
|
|
529
|
+
* The segment to append.
|
|
530
|
+
*
|
|
531
|
+
* @returns
|
|
532
|
+
* This object.
|
|
533
|
+
*/ append(path) {
|
|
534
|
+
this._url.path.push(path);
|
|
535
|
+
return this;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Sets the hash section.
|
|
539
|
+
*
|
|
540
|
+
* @param hash -
|
|
541
|
+
* The hash section.
|
|
542
|
+
*
|
|
543
|
+
* @returns
|
|
544
|
+
* This object.
|
|
545
|
+
*/ hash(hash) {
|
|
546
|
+
this._url.hash = hash;
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Adds a search parameter.
|
|
551
|
+
*
|
|
552
|
+
* This version assumes that value is not null.
|
|
553
|
+
*
|
|
554
|
+
* @param key -
|
|
555
|
+
* The parameter key.
|
|
556
|
+
* @param val -
|
|
557
|
+
* The parameter value.
|
|
558
|
+
*
|
|
559
|
+
* @returns
|
|
560
|
+
* This object.
|
|
561
|
+
*/ param(key, val) {
|
|
562
|
+
this._url.params.push({
|
|
563
|
+
key,
|
|
564
|
+
val
|
|
565
|
+
});
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Removes all duplicate params and adds one with the key to the value.
|
|
570
|
+
*
|
|
571
|
+
* @param key -
|
|
572
|
+
* The parameter key that can have only one.
|
|
573
|
+
* @param val -
|
|
574
|
+
* The parameter value. If this is falsy, then
|
|
575
|
+
* the key is deleted.
|
|
576
|
+
*/ onlyParam(key, val) {
|
|
577
|
+
this._url.params = this._url.params.filter((p) => p.key !== key);
|
|
578
|
+
return val ? this.param(key, val) : this;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Adds a page param.
|
|
582
|
+
*
|
|
583
|
+
* @param page -
|
|
584
|
+
* The page param to add. If this null, undefined,
|
|
585
|
+
* or less than 1, then any page param is deleted.
|
|
586
|
+
*
|
|
587
|
+
* @returns
|
|
588
|
+
* This object.
|
|
589
|
+
*/ page(page) {
|
|
590
|
+
return this.onlyParam("page", page == null || page < 1 ? void 0 : String(page));
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Adds a size param.
|
|
594
|
+
*
|
|
595
|
+
* @param size -
|
|
596
|
+
* The size param to add. If this is null, undefined,
|
|
597
|
+
* or less than 0, then any size param is deleted.
|
|
598
|
+
*
|
|
599
|
+
* @returns
|
|
600
|
+
* This object.
|
|
601
|
+
*/ size(size) {
|
|
602
|
+
return this.onlyParam("size", size == null || size < 0 ? void 0 : String(size));
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Adds a search param.
|
|
606
|
+
*
|
|
607
|
+
* @param search -
|
|
608
|
+
* The search param to add. If this is null, undefined,
|
|
609
|
+
* or empty, then any search param is deleted.
|
|
610
|
+
*
|
|
611
|
+
* @returns
|
|
612
|
+
* This object.
|
|
613
|
+
*/ search(search) {
|
|
614
|
+
return this.onlyParam("search", search || void 0);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Adds a filter param.
|
|
618
|
+
*
|
|
619
|
+
* @param filter -
|
|
620
|
+
* The filter param to add. If this is null, undefined,
|
|
621
|
+
* or empty, then any filter param is deleted.
|
|
622
|
+
*
|
|
623
|
+
* @returns
|
|
624
|
+
* This object.
|
|
625
|
+
*/ filter(filter) {
|
|
626
|
+
return this.onlyParam("filter", filter || void 0);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Adds a sort param.
|
|
630
|
+
*
|
|
631
|
+
* @param sort -
|
|
632
|
+
* The sort param to add. If this is null, undefined,
|
|
633
|
+
* or empty, then any filter param is deleted.
|
|
634
|
+
*
|
|
635
|
+
* @returns
|
|
636
|
+
* This object.
|
|
637
|
+
*/ sort(sort) {
|
|
638
|
+
return this.onlyParam("sort", sort || void 0);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Builds the url string and returns it.
|
|
642
|
+
*
|
|
643
|
+
* @returns
|
|
644
|
+
* The url string.
|
|
645
|
+
*/ build() {
|
|
646
|
+
const search = (0, lodash_es.sortBy)(this._url.params, (p) => p.key).map((param) => `${param.key}=${encodeURIComponent(param.val)}`).join("&");
|
|
647
|
+
const user = (0, lodash_es.trim)(this._url.username);
|
|
648
|
+
const password = (0, lodash_es.trim)(this._url.password);
|
|
649
|
+
let protocol = (0, lodash_es.trim)(this._url.protocol);
|
|
650
|
+
let host = (0, lodash_es.trim)(this._url.hostname);
|
|
651
|
+
let port = String(this._url.port);
|
|
652
|
+
let hash = (0, lodash_es.trim)(this._url.hash);
|
|
653
|
+
let path = this._url.path.map((segment) => (0, lodash_es.trim)(segment, "/")).join("/");
|
|
654
|
+
let credentials = "";
|
|
655
|
+
protocol = (0, lodash_es.trimEnd)(protocol, "/:");
|
|
656
|
+
host = (0, lodash_es.trim)(host, "/");
|
|
657
|
+
hash = (0, lodash_es.trimStart)(hash, "#");
|
|
658
|
+
path = (0, lodash_es.trim)(path, "/");
|
|
659
|
+
if (ZUrlBuilder.defaults(protocol, port)) port = "";
|
|
660
|
+
else port = `:${port}`;
|
|
661
|
+
if (user) credentials = password ? `${user}:${password}@` : `${user}@`;
|
|
662
|
+
let url = `${protocol}://${credentials}${host}${port}`;
|
|
663
|
+
if (path) url = `${url}/${path}`;
|
|
664
|
+
if (search) url = `${url}/?${search}`;
|
|
665
|
+
if (hash) url = `${url}#${hash}`;
|
|
666
|
+
return url;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Gets the current information about the uri being built.
|
|
670
|
+
*
|
|
671
|
+
* @returns The current uri information.
|
|
672
|
+
*/ info() {
|
|
673
|
+
return JSON.parse(JSON.stringify(this._url));
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
//#endregion
|
|
724
677
|
exports.ZDataUrlBuilder = ZDataUrlBuilder;
|
|
725
678
|
exports.ZMimeTypeApplication = ZMimeTypeApplication;
|
|
726
679
|
exports.ZMimeTypeImage = ZMimeTypeImage;
|
|
@@ -728,4 +681,5 @@ exports.ZMimeTypeText = ZMimeTypeText;
|
|
|
728
681
|
exports.ZSupportedMimeTypes = ZSupportedMimeTypes;
|
|
729
682
|
exports.ZUrlBuilder = ZUrlBuilder;
|
|
730
683
|
exports.ZYouTubeApi = ZYouTubeApi;
|
|
731
|
-
|
|
684
|
+
|
|
685
|
+
//# sourceMappingURL=index.cjs.map
|