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