@zthun/webigail-url 4.0.1 → 4.0.3

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