@zthun/webigail-url 4.0.1 → 4.0.4

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,51 +1,234 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const lodashEs = require("lodash-es");
4
- const URLParse = require("url-parse");
5
- var ZMimeTypeApplication = /* @__PURE__ */ ((ZMimeTypeApplication2) => {
6
- ZMimeTypeApplication2["JSON"] = "application/json";
7
- ZMimeTypeApplication2["OctetStream"] = "application/octet-stream";
8
- ZMimeTypeApplication2["Zip"] = "application/zip";
9
- return ZMimeTypeApplication2;
10
- })(ZMimeTypeApplication || {});
11
- var ZMimeTypeImage = /* @__PURE__ */ ((ZMimeTypeImage2) => {
12
- ZMimeTypeImage2["APNG"] = "image/apng";
13
- ZMimeTypeImage2["AVIF"] = "image/avif";
14
- ZMimeTypeImage2["GIF"] = "image/gif";
15
- ZMimeTypeImage2["JPEG"] = "image/jpeg";
16
- ZMimeTypeImage2["PNG"] = "image/png";
17
- ZMimeTypeImage2["SVG"] = "image/svg+xml";
18
- ZMimeTypeImage2["WebP"] = "image/webp";
19
- return ZMimeTypeImage2;
20
- })(ZMimeTypeImage || {});
21
- var ZMimeTypeText = /* @__PURE__ */ ((ZMimeTypeText2) => {
22
- ZMimeTypeText2["CSS"] = "text/css";
23
- ZMimeTypeText2["CSV"] = "text/csv";
24
- ZMimeTypeText2["EcmaScript"] = "text/ecmascript";
25
- ZMimeTypeText2["HTML"] = "text/html";
26
- ZMimeTypeText2["JavaScript"] = "text/javascript";
27
- ZMimeTypeText2["Plain"] = "text/plain";
28
- ZMimeTypeText2["XML"] = "text/xml";
29
- return ZMimeTypeText2;
30
- })(ZMimeTypeText || {});
31
- const ZSupportedMimeTypes = Object.freeze({
32
- ...{ "": "text/plain;charset=ASCII" },
33
- ...lodashEs.keyBy(Object.values(ZMimeTypeApplication)),
34
- ...lodashEs.keyBy(Object.values(ZMimeTypeText)),
35
- ...lodashEs.keyBy(Object.values(ZMimeTypeImage))
36
- });
37
- class ZDataUrlBuilder {
38
- /**
39
- * Initializes a new instance of this object.
40
- */
41
- constructor() {
42
- this._data = {
43
- mimeType: "",
44
- encoding: "utf8",
45
- buffer: new Uint8Array([])
46
- };
47
- }
48
- /**
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;
23
+ }({});
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;
65
+ }({});
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;
97
+ }({});
98
+
99
+ function _define_property$2(obj, key, value) {
100
+ if (key in obj) {
101
+ Object.defineProperty(obj, key, {
102
+ value: value,
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true
106
+ });
107
+ } else {
108
+ obj[key] = value;
109
+ }
110
+ return obj;
111
+ }
112
+ function _object_spread$1(target) {
113
+ for(var i = 1; i < arguments.length; i++){
114
+ var source = arguments[i] != null ? arguments[i] : {};
115
+ var ownKeys = Object.keys(source);
116
+ if (typeof Object.getOwnPropertySymbols === "function") {
117
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
118
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
119
+ }));
120
+ }
121
+ ownKeys.forEach(function(key) {
122
+ _define_property$2(target, key, source[key]);
123
+ });
124
+ }
125
+ return target;
126
+ }
127
+ /**
128
+ * A mapping of supported mime types.
129
+ */ var ZSupportedMimeTypes = Object.freeze(_object_spread$1({}, {
130
+ "": "text/plain;charset=ASCII"
131
+ }, lodashEs.keyBy(Object.values(ZMimeTypeApplication)), lodashEs.keyBy(Object.values(ZMimeTypeText)), lodashEs.keyBy(Object.values(ZMimeTypeImage))));
132
+
133
+ function _array_like_to_array(arr, len) {
134
+ if (len == null || len > arr.length) len = arr.length;
135
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
136
+ return arr2;
137
+ }
138
+ function _array_with_holes(arr) {
139
+ if (Array.isArray(arr)) return arr;
140
+ }
141
+ function _array_without_holes(arr) {
142
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
143
+ }
144
+ function _class_call_check$1(instance, Constructor) {
145
+ if (!(instance instanceof Constructor)) {
146
+ throw new TypeError("Cannot call a class as a function");
147
+ }
148
+ }
149
+ function _defineProperties$1(target, props) {
150
+ for(var i = 0; i < props.length; i++){
151
+ var descriptor = props[i];
152
+ descriptor.enumerable = descriptor.enumerable || false;
153
+ descriptor.configurable = true;
154
+ if ("value" in descriptor) descriptor.writable = true;
155
+ Object.defineProperty(target, descriptor.key, descriptor);
156
+ }
157
+ }
158
+ function _create_class$1(Constructor, protoProps, staticProps) {
159
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
160
+ return Constructor;
161
+ }
162
+ function _define_property$1(obj, key, value) {
163
+ if (key in obj) {
164
+ Object.defineProperty(obj, key, {
165
+ value: value,
166
+ enumerable: true,
167
+ configurable: true,
168
+ writable: true
169
+ });
170
+ } else {
171
+ obj[key] = value;
172
+ }
173
+ return obj;
174
+ }
175
+ function _iterable_to_array(iter) {
176
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
177
+ }
178
+ function _non_iterable_rest() {
179
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
180
+ }
181
+ function _non_iterable_spread() {
182
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
183
+ }
184
+ function _object_spread(target) {
185
+ for(var i = 1; i < arguments.length; i++){
186
+ var source = arguments[i] != null ? arguments[i] : {};
187
+ var ownKeys = Object.keys(source);
188
+ if (typeof Object.getOwnPropertySymbols === "function") {
189
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
190
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
191
+ }));
192
+ }
193
+ ownKeys.forEach(function(key) {
194
+ _define_property$1(target, key, source[key]);
195
+ });
196
+ }
197
+ return target;
198
+ }
199
+ function _to_array(arr) {
200
+ return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
201
+ }
202
+ function _to_consumable_array(arr) {
203
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
204
+ }
205
+ function _unsupported_iterable_to_array(o, minLen) {
206
+ if (!o) return;
207
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
208
+ var n = Object.prototype.toString.call(o).slice(8, -1);
209
+ if (n === "Object" && o.constructor) n = o.constructor.name;
210
+ if (n === "Map" || n === "Set") return Array.from(n);
211
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
212
+ }
213
+ /**
214
+ * Represents an object that is helpful in building a data url with support
215
+ * for data encoding.
216
+ */ var ZDataUrlBuilder = /*#__PURE__*/ function() {
217
+ function ZDataUrlBuilder() {
218
+ _class_call_check$1(this, ZDataUrlBuilder);
219
+ /**
220
+ * The representation of the data url object.
221
+ */ _define_property$1(this, "_data", void 0);
222
+ this._data = {
223
+ mimeType: "",
224
+ encoding: "utf8",
225
+ buffer: new Uint8Array([])
226
+ };
227
+ }
228
+ _create_class$1(ZDataUrlBuilder, [
229
+ {
230
+ key: "parse",
231
+ value: /**
49
232
  * Parses an existing data url and sets all properties.
50
233
  *
51
234
  * @param url -
@@ -53,48 +236,55 @@ class ZDataUrlBuilder {
53
236
  *
54
237
  * @returns
55
238
  * This object.
56
- */
57
- parse(url) {
58
- this._data = {
59
- mimeType: "",
60
- encoding: "utf8",
61
- buffer: new Uint8Array([])
62
- };
63
- if (!url.startsWith("data:")) {
64
- return this;
65
- }
66
- url = url.substring(5);
67
- const parts = url.split(",");
68
- if (parts.length < 2) {
69
- return this;
70
- }
71
- const [mimeType, ...bodyParts] = parts;
72
- let [type, ...params] = mimeType.split(";");
73
- const isBase64 = lodashEs.last(params) === "base64";
74
- this._data.encoding = isBase64 ? "base64" : "utf8";
75
- if (isBase64) {
76
- params.pop();
77
- }
78
- if (!Object.hasOwnProperty.call(ZSupportedMimeTypes, type)) {
79
- type = ZMimeTypeApplication.OctetStream;
80
- params = [];
81
- }
82
- type = [type, ...params].join(";");
83
- this._data.mimeType = type;
84
- let body = bodyParts.join("%2C");
85
- if (isBase64) {
86
- try {
87
- body = atob(body);
88
- } catch {
89
- body = "";
90
- }
91
- } else {
92
- body = decodeURIComponent(body);
93
- }
94
- this._data.buffer = new TextEncoder().encode(body);
95
- return this;
96
- }
97
- /**
239
+ */ function parse(url) {
240
+ this._data = {
241
+ mimeType: "",
242
+ encoding: "utf8",
243
+ buffer: new Uint8Array([])
244
+ };
245
+ if (!url.startsWith("data:")) {
246
+ return this;
247
+ }
248
+ url = url.substring(5);
249
+ var parts = url.split(",");
250
+ if (parts.length < 2) {
251
+ return this;
252
+ }
253
+ var _parts = _to_array(parts), mimeType = _parts[0], bodyParts = _parts.slice(1);
254
+ var _mimeType_split = _to_array(mimeType.split(";")), type = _mimeType_split[0], params = _mimeType_split.slice(1);
255
+ var isBase64 = lodashEs.last(params) === "base64";
256
+ this._data.encoding = isBase64 ? "base64" : "utf8";
257
+ if (isBase64) {
258
+ params.pop();
259
+ }
260
+ if (!Object.hasOwnProperty.call(ZSupportedMimeTypes, type)) {
261
+ type = ZMimeTypeApplication.OctetStream;
262
+ params = [];
263
+ }
264
+ type = [
265
+ type
266
+ ].concat(_to_consumable_array(params)).join(";");
267
+ this._data.mimeType = type;
268
+ // Commas can be in the body. Type this into chrome and you can
269
+ // see that chrome actually parses it: data:text/plain,cat,,,
270
+ // We will support this here, but we're going to properly encode it.
271
+ var body = bodyParts.join("%2C");
272
+ if (isBase64) {
273
+ try {
274
+ body = atob(body);
275
+ } catch (e) {
276
+ body = "";
277
+ }
278
+ } else {
279
+ body = decodeURIComponent(body);
280
+ }
281
+ this._data.buffer = new TextEncoder().encode(body);
282
+ return this;
283
+ }
284
+ },
285
+ {
286
+ key: "mimeType",
287
+ value: /**
98
288
  * Sets the mime type.
99
289
  *
100
290
  * @param type -
@@ -102,12 +292,14 @@ class ZDataUrlBuilder {
102
292
  *
103
293
  * @returns
104
294
  * This object.
105
- */
106
- mimeType(type) {
107
- this._data.mimeType = type;
108
- return this;
109
- }
110
- /**
295
+ */ function mimeType(type) {
296
+ this._data.mimeType = type;
297
+ return this;
298
+ }
299
+ },
300
+ {
301
+ key: "buffer",
302
+ value: /**
111
303
  * Sets the data buffer.
112
304
  *
113
305
  * @param data -
@@ -115,12 +307,14 @@ class ZDataUrlBuilder {
115
307
  * is expected to be utf8.
116
308
  * @returns
117
309
  * This object.
118
- */
119
- buffer(data) {
120
- this._data.buffer = typeof data === "string" ? new TextEncoder().encode(data) : data;
121
- return this;
122
- }
123
- /**
310
+ */ function buffer(data) {
311
+ this._data.buffer = typeof data === "string" ? new TextEncoder().encode(data) : data;
312
+ return this;
313
+ }
314
+ },
315
+ {
316
+ key: "encode",
317
+ value: /**
124
318
  * Sets the output encoding.
125
319
  *
126
320
  * If you output encode the data as utf8, then it will be properly
@@ -131,91 +325,116 @@ class ZDataUrlBuilder {
131
325
  *
132
326
  * @returns
133
327
  * This object.
134
- */
135
- encode(encoding) {
136
- this._data.encoding = encoding;
137
- return this;
138
- }
139
- /**
328
+ */ function encode(encoding) {
329
+ this._data.encoding = encoding;
330
+ return this;
331
+ }
332
+ },
333
+ {
334
+ key: "build",
335
+ value: /**
140
336
  * Builds the url string and returns it.
141
337
  *
142
338
  * @returns The url string.
143
- */
144
- build() {
145
- const protocol = "data";
146
- const modifier = this._data.encoding === "base64" ? ";base64" : "";
147
- let raw = new TextDecoder("utf8").decode(this._data.buffer);
148
- if (this._data.encoding === "utf8") {
149
- raw = encodeURIComponent(raw);
150
- raw = raw.split("!").join("%21");
151
- }
152
- if (this._data.encoding === "base64") {
153
- raw = btoa(raw);
154
- }
155
- return `${protocol}:${this._data.mimeType}${modifier},${raw}`;
156
- }
157
- /**
339
+ */ function build() {
340
+ var protocol = "data";
341
+ var modifier = this._data.encoding === "base64" ? ";base64" : "";
342
+ var raw = new TextDecoder("utf8").decode(this._data.buffer);
343
+ if (this._data.encoding === "utf8") {
344
+ raw = encodeURIComponent(raw);
345
+ // Note ! should be encoded as %21, but for uri's..it's not because
346
+ // it's actually valid, but some servers don't accept ! as a character
347
+ // and it must be encoded. Just fix it here.
348
+ raw = raw.split("!").join("%21");
349
+ }
350
+ if (this._data.encoding === "base64") {
351
+ raw = btoa(raw);
352
+ }
353
+ return "".concat(protocol, ":").concat(this._data.mimeType).concat(modifier, ",").concat(raw);
354
+ }
355
+ },
356
+ {
357
+ key: "info",
358
+ value: /**
158
359
  * Gets the current information about the url being built.
159
360
  *
160
361
  * @returns The current information about the url being built.
161
- */
162
- info() {
163
- const other = { ...this._data };
164
- other.buffer = this._data.buffer.slice();
165
- return other;
166
- }
362
+ */ function info() {
363
+ var other = _object_spread({}, this._data);
364
+ other.buffer = this._data.buffer.slice();
365
+ return other;
366
+ }
367
+ }
368
+ ]);
369
+ return ZDataUrlBuilder;
370
+ }();
371
+
372
+ function _class_call_check(instance, Constructor) {
373
+ if (!(instance instanceof Constructor)) {
374
+ throw new TypeError("Cannot call a class as a function");
375
+ }
167
376
  }
168
- var ZYouTubeApi = /* @__PURE__ */ ((ZYouTubeApi2) => {
169
- ZYouTubeApi2["Embed"] = "embed";
170
- ZYouTubeApi2["Watch"] = "watch";
171
- return ZYouTubeApi2;
172
- })(ZYouTubeApi || {});
173
- const _ZUrlBuilder = class _ZUrlBuilder {
174
- /**
175
- * Gets whether the given protocols default port is port.
176
- *
177
- * The main purpose of this method is to determine if a url requires
178
- * a port section. Therefore, there are some special behaviors which may
179
- * not be obvious:
180
- *
181
- * 1. If the port is falsy then this method returns true.
182
- * 2. If the port is NaN, then this method returns true.
183
- * 3. If the port is a string that evaluates to 0, then this method returns true.
184
- * 4. If port is less than 0, then this method returns true.
185
- *
186
- * @param protocol -
187
- * The protocol to check.
188
- * @param port -
189
- * The port to compare.
190
- *
191
- * @returns
192
- * True if the default port for protocol is port.
193
- */
194
- static defaults(protocol, port) {
195
- const numericPort = +port;
196
- if (isNaN(numericPort) || numericPort < 1) {
197
- return true;
377
+ function _defineProperties(target, props) {
378
+ for(var i = 0; i < props.length; i++){
379
+ var descriptor = props[i];
380
+ descriptor.enumerable = descriptor.enumerable || false;
381
+ descriptor.configurable = true;
382
+ if ("value" in descriptor) descriptor.writable = true;
383
+ Object.defineProperty(target, descriptor.key, descriptor);
198
384
  }
199
- return _ZUrlBuilder.ProtocolPorts[protocol] === +port;
200
- }
201
- /**
202
- * Initializes a new instance of this object.
203
- *
204
- * @param protocol -
205
- * The protocol to use.
206
- * @param hostname -
207
- * The hostname to connect with.
208
- */
209
- constructor(protocol = "http", hostname = "localhost") {
210
- this._url = {
211
- protocol,
212
- hostname,
213
- path: ["/"],
214
- hash: "",
215
- params: []
216
- };
217
- }
218
- /**
385
+ }
386
+ function _create_class(Constructor, protoProps, staticProps) {
387
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
388
+ if (staticProps) _defineProperties(Constructor, staticProps);
389
+ return Constructor;
390
+ }
391
+ function _define_property(obj, key, value) {
392
+ if (key in obj) {
393
+ Object.defineProperty(obj, key, {
394
+ value: value,
395
+ enumerable: true,
396
+ configurable: true,
397
+ writable: true
398
+ });
399
+ } else {
400
+ obj[key] = value;
401
+ }
402
+ return obj;
403
+ }
404
+ /**
405
+ * The api to target for YouTube.
406
+ */ var ZYouTubeApi = /*#__PURE__*/ function(ZYouTubeApi) {
407
+ /**
408
+ * An embedded video link.
409
+ */ ZYouTubeApi["Embed"] = "embed";
410
+ /**
411
+ * A watch video link.
412
+ */ ZYouTubeApi["Watch"] = "watch";
413
+ return ZYouTubeApi;
414
+ }({});
415
+ /**
416
+ * Represents an object that is helpful in building a url.
417
+ */ var ZUrlBuilder = /*#__PURE__*/ function() {
418
+ function ZUrlBuilder() {
419
+ var protocol = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "http", hostname = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "localhost";
420
+ _class_call_check(this, ZUrlBuilder);
421
+ /**
422
+ * The representation of the url object.
423
+ */ _define_property(this, "_url", void 0);
424
+ this._url = {
425
+ protocol: protocol,
426
+ hostname: hostname,
427
+ path: [
428
+ "/"
429
+ ],
430
+ hash: "",
431
+ params: []
432
+ };
433
+ }
434
+ _create_class(ZUrlBuilder, [
435
+ {
436
+ key: "location",
437
+ value: /**
219
438
  * Fills the information from the current location data.
220
439
  *
221
440
  * @param loc -
@@ -223,18 +442,25 @@ const _ZUrlBuilder = class _ZUrlBuilder {
223
442
  *
224
443
  * @returns
225
444
  * This object.
226
- */
227
- location(loc) {
228
- this.protocol(loc.protocol).hostname(loc.hostname).hash(loc.hash).path(loc.pathname).port(+loc.port);
229
- let search = loc.search;
230
- if (search.startsWith("?")) {
231
- search = search.slice(1);
232
- const pairs = search.split("&");
233
- pairs.map((pair) => pair.split("=")).forEach((matrix) => this.param(matrix[0], matrix[1]));
234
- }
235
- return this;
236
- }
237
- /**
445
+ */ function location(loc) {
446
+ var _this = this;
447
+ this.protocol(loc.protocol).hostname(loc.hostname).hash(loc.hash).path(loc.pathname).port(+loc.port);
448
+ var search = loc.search;
449
+ if (search.startsWith("?")) {
450
+ search = search.slice(1);
451
+ var pairs = search.split("&");
452
+ pairs.map(function(pair) {
453
+ return pair.split("=");
454
+ }).forEach(function(matrix) {
455
+ return _this.param(matrix[0], matrix[1]);
456
+ });
457
+ }
458
+ return this;
459
+ }
460
+ },
461
+ {
462
+ key: "api",
463
+ value: /**
238
464
  * Fills the information for an api path call.
239
465
  *
240
466
  * This is a combination of location, hash with an empty string, and an
@@ -249,11 +475,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
249
475
  *
250
476
  * @returns
251
477
  * This object.
252
- */
253
- api(loc, basePath = "api") {
254
- return this.location(loc).hash("").path(basePath);
255
- }
256
- /**
478
+ */ function api(loc) {
479
+ var basePath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "api";
480
+ return this.location(loc).hash("").path(basePath);
481
+ }
482
+ },
483
+ {
484
+ key: "parse",
485
+ value: /**
257
486
  * Parses an existing url and sets all properties.
258
487
  *
259
488
  * If you give this a path without the protocol and hostname, then it will
@@ -268,16 +497,19 @@ const _ZUrlBuilder = class _ZUrlBuilder {
268
497
  *
269
498
  * @returns
270
499
  * This object.
271
- */
272
- parse(url) {
273
- const current = new URLParse(url, true);
274
- 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);
275
- Object.keys(current.query).forEach(
276
- (key) => this.param(key, current.query[key])
277
- );
278
- return this;
279
- }
280
- /**
500
+ */ function parse(url) {
501
+ var _this = this;
502
+ var current = new URLParse(url, true);
503
+ 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);
504
+ Object.keys(current.query).forEach(function(key) {
505
+ return _this.param(key, current.query[key]);
506
+ });
507
+ return this;
508
+ }
509
+ },
510
+ {
511
+ key: "gravatar",
512
+ value: /**
281
513
  * Sets the url for a user gravatar.
282
514
  *
283
515
  * @param hash -
@@ -287,14 +519,16 @@ const _ZUrlBuilder = class _ZUrlBuilder {
287
519
  *
288
520
  * @returns
289
521
  * This object.
290
- */
291
- gravatar(hash, size) {
292
- let current = this.parse(_ZUrlBuilder.UrlGravatar);
293
- current = hash ? current.append(hash) : current;
294
- current = size ? current.param("s", String(size)) : current;
295
- return current;
296
- }
297
- /**
522
+ */ function gravatar(hash, size) {
523
+ var current = this.parse(ZUrlBuilder.UrlGravatar);
524
+ current = hash ? current.append(hash) : current;
525
+ current = size ? current.param("s", String(size)) : current;
526
+ return current;
527
+ }
528
+ },
529
+ {
530
+ key: "youTube",
531
+ value: /**
298
532
  * Sets the url target to something on YouTube.
299
533
  *
300
534
  * @param api -
@@ -307,16 +541,20 @@ const _ZUrlBuilder = class _ZUrlBuilder {
307
541
  * The url for YouTube. If you set the api and
308
542
  * id, then the url will be targeted to a specific video,
309
543
  * otherwise, the base domain url of YouTube will be returned.
310
- */
311
- youTube(api, id) {
312
- let current = this.parse(_ZUrlBuilder.UrlYouTube);
313
- current = api ? current.path(`${api}/${id}`) : current;
314
- if (api === "watch") {
315
- current = current.path(api).param("v", id);
316
- }
317
- return current;
318
- }
319
- /**
544
+ */ function youTube(api, id) {
545
+ var current = this.parse(ZUrlBuilder.UrlYouTube);
546
+ current = api ? current.path("".concat(api, "/").concat(id)) : current;
547
+ // The watch api is a little bizarre that they don't actually
548
+ // use the same format as their other apis. So we will handle this here.
549
+ if (api === "watch") {
550
+ current = current.path(api).param("v", id);
551
+ }
552
+ return current;
553
+ }
554
+ },
555
+ {
556
+ key: "protocol",
557
+ value: /**
320
558
  * Sets the protocol.
321
559
  *
322
560
  * @param protocol -
@@ -324,12 +562,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
324
562
  *
325
563
  * @returns
326
564
  * This object.
327
- */
328
- protocol(protocol) {
329
- this._url.protocol = protocol;
330
- return this;
331
- }
332
- /**
565
+ */ function protocol(protocol) {
566
+ this._url.protocol = protocol;
567
+ return this;
568
+ }
569
+ },
570
+ {
571
+ key: "username",
572
+ value: /**
333
573
  * Sets the user name.
334
574
  *
335
575
  * Used for things like ssh and ftp.
@@ -339,12 +579,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
339
579
  *
340
580
  * @returns
341
581
  * This object.
342
- */
343
- username(user) {
344
- this._url.username = user;
345
- return this;
346
- }
347
- /**
582
+ */ function username(user) {
583
+ this._url.username = user;
584
+ return this;
585
+ }
586
+ },
587
+ {
588
+ key: "password",
589
+ value: /**
348
590
  * Sets the password.
349
591
  *
350
592
  * This is only valid if the username is set.
@@ -354,12 +596,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
354
596
  *
355
597
  * @returns
356
598
  * This object.
357
- */
358
- password(pwd) {
359
- this._url.password = pwd;
360
- return this;
361
- }
362
- /**
599
+ */ function password(pwd) {
600
+ this._url.password = pwd;
601
+ return this;
602
+ }
603
+ },
604
+ {
605
+ key: "hostname",
606
+ value: /**
363
607
  * Sets the host name.
364
608
  *
365
609
  * This sets the entire hostname as the root domain. This
@@ -371,12 +615,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
371
615
  *
372
616
  * @returns
373
617
  * This object.
374
- */
375
- hostname(host) {
376
- this._url.hostname = host;
377
- return this;
378
- }
379
- /**
618
+ */ function hostname(host) {
619
+ this._url.hostname = host;
620
+ return this;
621
+ }
622
+ },
623
+ {
624
+ key: "subdomain",
625
+ value: /**
380
626
  * Adds a subdomain in front of the hostname.
381
627
  *
382
628
  * If a hostname was never set, then domain becomes the hostname.
@@ -386,24 +632,28 @@ const _ZUrlBuilder = class _ZUrlBuilder {
386
632
  *
387
633
  * @returns
388
634
  * This object.
389
- */
390
- subdomain(domain) {
391
- this._url.hostname = this._url.hostname ? `${domain}.${this._url.hostname}` : domain;
392
- return this;
393
- }
394
- /**
635
+ */ function subdomain(domain) {
636
+ this._url.hostname = this._url.hostname ? "".concat(domain, ".").concat(this._url.hostname) : domain;
637
+ return this;
638
+ }
639
+ },
640
+ {
641
+ key: "popSubdomain",
642
+ value: /**
395
643
  * Removes a subdomain from the current domain.
396
644
  *
397
645
  * @returns
398
646
  * This object.
399
- */
400
- popSubdomain() {
401
- const parts = this._url.hostname.split(".");
402
- parts.splice(0, 1);
403
- this._url.hostname = parts.join(".");
404
- return this;
405
- }
406
- /**
647
+ */ function popSubdomain() {
648
+ var parts = this._url.hostname.split(".");
649
+ parts.splice(0, 1);
650
+ this._url.hostname = parts.join(".");
651
+ return this;
652
+ }
653
+ },
654
+ {
655
+ key: "port",
656
+ value: /**
407
657
  * Sets the port.
408
658
  *
409
659
  * @param port -
@@ -411,12 +661,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
411
661
  *
412
662
  * @returns
413
663
  * This object.
414
- */
415
- port(port) {
416
- this._url.port = port;
417
- return this;
418
- }
419
- /**
664
+ */ function port(port) {
665
+ this._url.port = port;
666
+ return this;
667
+ }
668
+ },
669
+ {
670
+ key: "path",
671
+ value: /**
420
672
  * Removes all existing path segments and restarts the path.
421
673
  *
422
674
  * @param path -
@@ -424,12 +676,16 @@ const _ZUrlBuilder = class _ZUrlBuilder {
424
676
  *
425
677
  * @returns
426
678
  * This object.
427
- */
428
- path(path) {
429
- this._url.path = [path];
430
- return this;
431
- }
432
- /**
679
+ */ function path(path) {
680
+ this._url.path = [
681
+ path
682
+ ];
683
+ return this;
684
+ }
685
+ },
686
+ {
687
+ key: "append",
688
+ value: /**
433
689
  * Appends a path segment.
434
690
  *
435
691
  * @param path -
@@ -437,12 +693,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
437
693
  *
438
694
  * @returns
439
695
  * This object.
440
- */
441
- append(path) {
442
- this._url.path.push(path);
443
- return this;
444
- }
445
- /**
696
+ */ function append(path) {
697
+ this._url.path.push(path);
698
+ return this;
699
+ }
700
+ },
701
+ {
702
+ key: "hash",
703
+ value: /**
446
704
  * Sets the hash section.
447
705
  *
448
706
  * @param hash -
@@ -450,12 +708,14 @@ const _ZUrlBuilder = class _ZUrlBuilder {
450
708
  *
451
709
  * @returns
452
710
  * This object.
453
- */
454
- hash(hash) {
455
- this._url.hash = hash;
456
- return this;
457
- }
458
- /**
711
+ */ function hash(hash) {
712
+ this._url.hash = hash;
713
+ return this;
714
+ }
715
+ },
716
+ {
717
+ key: "param",
718
+ value: /**
459
719
  * Adds a search parameter.
460
720
  *
461
721
  * This version assumes that value is not null.
@@ -467,12 +727,17 @@ const _ZUrlBuilder = class _ZUrlBuilder {
467
727
  *
468
728
  * @returns
469
729
  * This object.
470
- */
471
- param(key, val) {
472
- this._url.params.push({ key, val });
473
- return this;
474
- }
475
- /**
730
+ */ function param(key, val) {
731
+ this._url.params.push({
732
+ key: key,
733
+ val: val
734
+ });
735
+ return this;
736
+ }
737
+ },
738
+ {
739
+ key: "onlyParam",
740
+ value: /**
476
741
  * Removes all duplicate params and adds one with the key to the value.
477
742
  *
478
743
  * @param key -
@@ -480,12 +745,16 @@ const _ZUrlBuilder = class _ZUrlBuilder {
480
745
  * @param val -
481
746
  * The parameter value. If this is falsy, then
482
747
  * the key is deleted.
483
- */
484
- onlyParam(key, val) {
485
- this._url.params = this._url.params.filter((p) => p.key !== key);
486
- return val ? this.param(key, val) : this;
487
- }
488
- /**
748
+ */ function onlyParam(key, val) {
749
+ this._url.params = this._url.params.filter(function(p) {
750
+ return p.key !== key;
751
+ });
752
+ return val ? this.param(key, val) : this;
753
+ }
754
+ },
755
+ {
756
+ key: "page",
757
+ value: /**
489
758
  * Adds a page param.
490
759
  *
491
760
  * @param page -
@@ -494,14 +763,13 @@ const _ZUrlBuilder = class _ZUrlBuilder {
494
763
  *
495
764
  * @returns
496
765
  * This object.
497
- */
498
- page(page) {
499
- return this.onlyParam(
500
- "page",
501
- page == null || page < 1 ? void 0 : String(page)
502
- );
503
- }
504
- /**
766
+ */ function page(page) {
767
+ return this.onlyParam("page", page == null || page < 1 ? undefined : String(page));
768
+ }
769
+ },
770
+ {
771
+ key: "size",
772
+ value: /**
505
773
  * Adds a size param.
506
774
  *
507
775
  * @param size -
@@ -510,14 +778,13 @@ const _ZUrlBuilder = class _ZUrlBuilder {
510
778
  *
511
779
  * @returns
512
780
  * This object.
513
- */
514
- size(size) {
515
- return this.onlyParam(
516
- "size",
517
- size == null || size < 0 ? void 0 : String(size)
518
- );
519
- }
520
- /**
781
+ */ function size(size) {
782
+ return this.onlyParam("size", size == null || size < 0 ? undefined : String(size));
783
+ }
784
+ },
785
+ {
786
+ key: "search",
787
+ value: /**
521
788
  * Adds a search param.
522
789
  *
523
790
  * @param search -
@@ -526,11 +793,13 @@ const _ZUrlBuilder = class _ZUrlBuilder {
526
793
  *
527
794
  * @returns
528
795
  * This object.
529
- */
530
- search(search) {
531
- return this.onlyParam("search", search || void 0);
532
- }
533
- /**
796
+ */ function search(search) {
797
+ return this.onlyParam("search", search || undefined);
798
+ }
799
+ },
800
+ {
801
+ key: "filter",
802
+ value: /**
534
803
  * Adds a filter param.
535
804
  *
536
805
  * @param filter -
@@ -539,11 +808,13 @@ const _ZUrlBuilder = class _ZUrlBuilder {
539
808
  *
540
809
  * @returns
541
810
  * This object.
542
- */
543
- filter(filter) {
544
- return this.onlyParam("filter", filter || void 0);
545
- }
546
- /**
811
+ */ function filter(filter) {
812
+ return this.onlyParam("filter", filter || undefined);
813
+ }
814
+ },
815
+ {
816
+ key: "sort",
817
+ value: /**
547
818
  * Adds a sort param.
548
819
  *
549
820
  * @param sort -
@@ -552,71 +823,121 @@ const _ZUrlBuilder = class _ZUrlBuilder {
552
823
  *
553
824
  * @returns
554
825
  * This object.
555
- */
556
- sort(sort) {
557
- return this.onlyParam("sort", sort || void 0);
558
- }
559
- /**
826
+ */ function sort(sort) {
827
+ return this.onlyParam("sort", sort || undefined);
828
+ }
829
+ },
830
+ {
831
+ key: "build",
832
+ value: /**
560
833
  * Builds the url string and returns it.
561
834
  *
562
835
  * @returns
563
836
  * The url string.
564
- */
565
- build() {
566
- const search = lodashEs.sortBy(this._url.params, (p) => p.key).map((param) => `${param.key}=${encodeURIComponent(param.val)}`).join("&");
567
- const user = lodashEs.trim(this._url.username);
568
- const password = lodashEs.trim(this._url.password);
569
- let protocol = lodashEs.trim(this._url.protocol);
570
- let host = lodashEs.trim(this._url.hostname);
571
- let port = String(this._url.port);
572
- let hash = lodashEs.trim(this._url.hash);
573
- let path = this._url.path.map((segment) => lodashEs.trim(segment, "/")).join("/");
574
- let credentials = "";
575
- protocol = lodashEs.trimEnd(protocol, "/:");
576
- host = lodashEs.trim(host, "/");
577
- hash = lodashEs.trimStart(hash, "#");
578
- path = lodashEs.trim(path, "/");
579
- if (_ZUrlBuilder.defaults(protocol, port)) {
580
- port = "";
581
- } else {
582
- port = `:${port}`;
583
- }
584
- if (user) {
585
- credentials = password ? `${user}:${password}@` : `${user}@`;
586
- }
587
- let url = `${protocol}://${credentials}${host}${port}`;
588
- if (path) {
589
- url = `${url}/${path}`;
590
- }
591
- if (search) {
592
- url = `${url}/?${search}`;
593
- }
594
- if (hash) {
595
- url = `${url}#${hash}`;
596
- }
597
- return url;
598
- }
599
- /**
837
+ */ function build() {
838
+ var search = lodashEs.sortBy(this._url.params, function(p) {
839
+ return p.key;
840
+ }).map(function(param) {
841
+ return "".concat(param.key, "=").concat(encodeURIComponent(param.val));
842
+ }).join("&");
843
+ var user = lodashEs.trim(this._url.username);
844
+ var password = lodashEs.trim(this._url.password);
845
+ var protocol = lodashEs.trim(this._url.protocol);
846
+ var host = lodashEs.trim(this._url.hostname);
847
+ var port = String(this._url.port);
848
+ var hash = lodashEs.trim(this._url.hash);
849
+ var path = this._url.path.map(function(segment) {
850
+ return lodashEs.trim(segment, "/");
851
+ }).join("/");
852
+ var credentials = "";
853
+ protocol = lodashEs.trimEnd(protocol, "/:");
854
+ host = lodashEs.trim(host, "/");
855
+ hash = lodashEs.trimStart(hash, "#");
856
+ path = lodashEs.trim(path, "/");
857
+ if (ZUrlBuilder.defaults(protocol, port)) {
858
+ port = "";
859
+ } else {
860
+ port = ":".concat(port);
861
+ }
862
+ if (user) {
863
+ credentials = password ? "".concat(user, ":").concat(password, "@") : "".concat(user, "@");
864
+ }
865
+ var url = "".concat(protocol, "://").concat(credentials).concat(host).concat(port);
866
+ if (path) {
867
+ url = "".concat(url, "/").concat(path);
868
+ }
869
+ if (search) {
870
+ url = "".concat(url, "/?").concat(search);
871
+ }
872
+ if (hash) {
873
+ url = "".concat(url, "#").concat(hash);
874
+ }
875
+ return url;
876
+ }
877
+ },
878
+ {
879
+ key: "info",
880
+ value: /**
600
881
  * Gets the current information about the uri being built.
601
882
  *
602
883
  * @returns The current uri information.
603
- */
604
- info() {
605
- return JSON.parse(JSON.stringify(this._url));
606
- }
607
- };
608
- _ZUrlBuilder.UrlGravatar = "https://s.gravatar.com/avatar";
609
- _ZUrlBuilder.UrlYouTube = "https://www.youtube.com";
610
- _ZUrlBuilder.ProtocolPorts = {
611
- http: 80,
612
- https: 443,
613
- ftp: 21,
614
- sftp: 22,
615
- ssh: 22,
616
- smtp: 25,
617
- smb: 445
618
- };
619
- let ZUrlBuilder = _ZUrlBuilder;
884
+ */ function info() {
885
+ return JSON.parse(JSON.stringify(this._url));
886
+ }
887
+ }
888
+ ], [
889
+ {
890
+ key: "defaults",
891
+ value: /**
892
+ * Gets whether the given protocols default port is port.
893
+ *
894
+ * The main purpose of this method is to determine if a url requires
895
+ * a port section. Therefore, there are some special behaviors which may
896
+ * not be obvious:
897
+ *
898
+ * 1. If the port is falsy then this method returns true.
899
+ * 2. If the port is NaN, then this method returns true.
900
+ * 3. If the port is a string that evaluates to 0, then this method returns true.
901
+ * 4. If port is less than 0, then this method returns true.
902
+ *
903
+ * @param protocol -
904
+ * The protocol to check.
905
+ * @param port -
906
+ * The port to compare.
907
+ *
908
+ * @returns
909
+ * True if the default port for protocol is port.
910
+ */ function defaults(protocol, port) {
911
+ var numericPort = +port;
912
+ if (isNaN(numericPort) || numericPort < 1) {
913
+ return true;
914
+ }
915
+ return ZUrlBuilder.ProtocolPorts[protocol] === +port;
916
+ }
917
+ }
918
+ ]);
919
+ return ZUrlBuilder;
920
+ }();
921
+ /**
922
+ * The url to the gravatar api.
923
+ */ _define_property(ZUrlBuilder, "UrlGravatar", "https://s.gravatar.com/avatar");
924
+ /**
925
+ * The url to youtube.
926
+ *
927
+ * This is mostly used to embed videos.
928
+ */ _define_property(ZUrlBuilder, "UrlYouTube", "https://www.youtube.com");
929
+ /**
930
+ * A mapping between protocol and default port.
931
+ */ _define_property(ZUrlBuilder, "ProtocolPorts", {
932
+ http: 80,
933
+ https: 443,
934
+ ftp: 21,
935
+ sftp: 22,
936
+ ssh: 22,
937
+ smtp: 25,
938
+ smb: 445
939
+ });
940
+
620
941
  exports.ZDataUrlBuilder = ZDataUrlBuilder;
621
942
  exports.ZMimeTypeApplication = ZMimeTypeApplication;
622
943
  exports.ZMimeTypeImage = ZMimeTypeImage;