@zthun/webigail-url 4.0.8 → 5.0.0

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
@@ -92,69 +92,17 @@ import URLParse from 'url-parse';
92
92
  return ZMimeTypeText;
93
93
  }({});
94
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
95
  /**
124
96
  * 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))));
97
+ */ const ZSupportedMimeTypes = Object.freeze({
98
+ ...{
99
+ "": "text/plain;charset=ASCII"
100
+ },
101
+ ...keyBy(Object.values(ZMimeTypeApplication)),
102
+ ...keyBy(Object.values(ZMimeTypeText)),
103
+ ...keyBy(Object.values(ZMimeTypeImage))
104
+ });
128
105
 
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
106
  function _define_property$1(obj, key, value) {
159
107
  if (key in obj) {
160
108
  Object.defineProperty(obj, key, {
@@ -168,63 +116,11 @@ function _define_property$1(obj, key, value) {
168
116
  }
169
117
  return obj;
170
118
  }
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
119
  /**
210
120
  * Represents an object that is helpful in building a data url with support
211
121
  * 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: /**
122
+ */ class ZDataUrlBuilder {
123
+ /**
228
124
  * Parses an existing data url and sets all properties.
229
125
  *
230
126
  * @param url -
@@ -232,55 +128,53 @@ function _unsupported_iterable_to_array(o, minLen) {
232
128
  *
233
129
  * @returns
234
130
  * This object.
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;
131
+ */ parse(url) {
132
+ this._data = {
133
+ mimeType: "",
134
+ encoding: "utf8",
135
+ buffer: new Uint8Array([])
136
+ };
137
+ if (!url.startsWith("data:")) {
138
+ return this;
139
+ }
140
+ url = url.substring(5);
141
+ const parts = url.split(",");
142
+ if (parts.length < 2) {
143
+ return this;
144
+ }
145
+ const [mimeType, ...bodyParts] = parts;
146
+ let [type, ...params] = mimeType.split(";");
147
+ const isBase64 = last(params) === "base64";
148
+ this._data.encoding = isBase64 ? "base64" : "utf8";
149
+ if (isBase64) {
150
+ params.pop();
151
+ }
152
+ if (!Object.hasOwnProperty.call(ZSupportedMimeTypes, type)) {
153
+ type = ZMimeTypeApplication.OctetStream;
154
+ params = [];
155
+ }
156
+ type = [
157
+ type,
158
+ ...params
159
+ ].join(";");
160
+ this._data.mimeType = type;
161
+ // Commas can be in the body. Type this into chrome and you can
162
+ // see that chrome actually parses it: data:text/plain,cat,,,
163
+ // We will support this here, but we're going to properly encode it.
164
+ let body = bodyParts.join("%2C");
165
+ if (isBase64) {
166
+ try {
167
+ body = atob(body);
168
+ } catch {
169
+ body = "";
279
170
  }
280
- },
281
- {
282
- key: "mimeType",
283
- value: /**
171
+ } else {
172
+ body = decodeURIComponent(body);
173
+ }
174
+ this._data.buffer = new TextEncoder().encode(body);
175
+ return this;
176
+ }
177
+ /**
284
178
  * Sets the mime type.
285
179
  *
286
180
  * @param type -
@@ -288,14 +182,11 @@ function _unsupported_iterable_to_array(o, minLen) {
288
182
  *
289
183
  * @returns
290
184
  * This object.
291
- */ function mimeType(type) {
292
- this._data.mimeType = type;
293
- return this;
294
- }
295
- },
296
- {
297
- key: "buffer",
298
- value: /**
185
+ */ mimeType(type) {
186
+ this._data.mimeType = type;
187
+ return this;
188
+ }
189
+ /**
299
190
  * Sets the data buffer.
300
191
  *
301
192
  * @param data -
@@ -303,14 +194,11 @@ function _unsupported_iterable_to_array(o, minLen) {
303
194
  * is expected to be utf8.
304
195
  * @returns
305
196
  * This object.
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: /**
197
+ */ buffer(data) {
198
+ this._data.buffer = typeof data === "string" ? new TextEncoder().encode(data) : data;
199
+ return this;
200
+ }
201
+ /**
314
202
  * Sets the output encoding.
315
203
  *
316
204
  * If you output encode the data as utf8, then it will be properly
@@ -321,69 +209,55 @@ function _unsupported_iterable_to_array(o, minLen) {
321
209
  *
322
210
  * @returns
323
211
  * This object.
324
- */ function encode(encoding) {
325
- this._data.encoding = encoding;
326
- return this;
327
- }
328
- },
329
- {
330
- key: "build",
331
- value: /**
212
+ */ encode(encoding) {
213
+ this._data.encoding = encoding;
214
+ return this;
215
+ }
216
+ /**
332
217
  * Builds the url string and returns it.
333
218
  *
334
219
  * @returns The url string.
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: /**
220
+ */ build() {
221
+ const protocol = "data";
222
+ const modifier = this._data.encoding === "base64" ? ";base64" : "";
223
+ let raw = new TextDecoder("utf8").decode(this._data.buffer);
224
+ if (this._data.encoding === "utf8") {
225
+ raw = encodeURIComponent(raw);
226
+ // Note ! should be encoded as %21, but for uri's..it's not because
227
+ // it's actually valid, but some servers don't accept ! as a character
228
+ // and it must be encoded. Just fix it here.
229
+ raw = raw.split("!").join("%21");
230
+ }
231
+ if (this._data.encoding === "base64") {
232
+ raw = btoa(raw);
233
+ }
234
+ return `${protocol}:${this._data.mimeType}${modifier},${raw}`;
235
+ }
236
+ /**
355
237
  * Gets the current information about the url being built.
356
238
  *
357
239
  * @returns The current information about the url being built.
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");
240
+ */ info() {
241
+ const other = {
242
+ ...this._data
243
+ };
244
+ other.buffer = this._data.buffer.slice();
245
+ return other;
371
246
  }
372
- }
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);
247
+ /**
248
+ * Initializes a new instance of this object.
249
+ */ constructor(){
250
+ /**
251
+ * The representation of the data url object.
252
+ */ _define_property$1(this, "_data", void 0);
253
+ this._data = {
254
+ mimeType: "",
255
+ encoding: "utf8",
256
+ buffer: new Uint8Array([])
257
+ };
380
258
  }
381
259
  }
382
- function _create_class(Constructor, protoProps, staticProps) {
383
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
384
- if (staticProps) _defineProperties(Constructor, staticProps);
385
- return Constructor;
386
- }
260
+
387
261
  function _define_property(obj, key, value) {
388
262
  if (key in obj) {
389
263
  Object.defineProperty(obj, key, {
@@ -410,27 +284,34 @@ function _define_property(obj, key, value) {
410
284
  }({});
411
285
  /**
412
286
  * 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
- };
287
+ */ class ZUrlBuilder {
288
+ /**
289
+ * Gets whether the given protocols default port is port.
290
+ *
291
+ * The main purpose of this method is to determine if a url requires
292
+ * a port section. Therefore, there are some special behaviors which may
293
+ * not be obvious:
294
+ *
295
+ * 1. If the port is falsy then this method returns true.
296
+ * 2. If the port is NaN, then this method returns true.
297
+ * 3. If the port is a string that evaluates to 0, then this method returns true.
298
+ * 4. If port is less than 0, then this method returns true.
299
+ *
300
+ * @param protocol -
301
+ * The protocol to check.
302
+ * @param port -
303
+ * The port to compare.
304
+ *
305
+ * @returns
306
+ * True if the default port for protocol is port.
307
+ */ static defaults(protocol, port) {
308
+ const numericPort = +port;
309
+ if (isNaN(numericPort) || numericPort < 1) {
310
+ return true;
311
+ }
312
+ return ZUrlBuilder.ProtocolPorts[protocol] === +port;
429
313
  }
430
- _create_class(ZUrlBuilder, [
431
- {
432
- key: "location",
433
- value: /**
314
+ /**
434
315
  * Fills the information from the current location data.
435
316
  *
436
317
  * @param loc -
@@ -438,25 +319,17 @@ function _define_property(obj, key, value) {
438
319
  *
439
320
  * @returns
440
321
  * This object.
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: /**
322
+ */ location(loc) {
323
+ this.protocol(loc.protocol).hostname(loc.hostname).hash(loc.hash).path(loc.pathname).port(+loc.port);
324
+ let search = loc.search;
325
+ if (search.startsWith("?")) {
326
+ search = search.slice(1);
327
+ const pairs = search.split("&");
328
+ pairs.map((pair)=>pair.split("=")).forEach((matrix)=>this.param(matrix[0], matrix[1]));
329
+ }
330
+ return this;
331
+ }
332
+ /**
460
333
  * Fills the information for an api path call.
461
334
  *
462
335
  * This is a combination of location, hash with an empty string, and an
@@ -471,14 +344,10 @@ function _define_property(obj, key, value) {
471
344
  *
472
345
  * @returns
473
346
  * This object.
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: /**
347
+ */ api(loc, basePath = "api") {
348
+ return this.location(loc).hash("").path(basePath);
349
+ }
350
+ /**
482
351
  * Parses an existing url and sets all properties.
483
352
  *
484
353
  * If you give this a path without the protocol and hostname, then it will
@@ -493,19 +362,13 @@ function _define_property(obj, key, value) {
493
362
  *
494
363
  * @returns
495
364
  * This object.
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: /**
365
+ */ parse(url) {
366
+ const current = new URLParse(url, true);
367
+ 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);
368
+ Object.keys(current.query).forEach((key)=>this.param(key, current.query[key]));
369
+ return this;
370
+ }
371
+ /**
509
372
  * Sets the url for a user gravatar.
510
373
  *
511
374
  * @param hash -
@@ -515,16 +378,13 @@ function _define_property(obj, key, value) {
515
378
  *
516
379
  * @returns
517
380
  * This object.
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: /**
381
+ */ gravatar(hash, size) {
382
+ let current = this.parse(ZUrlBuilder.UrlGravatar);
383
+ current = hash ? current.append(hash) : current;
384
+ current = size ? current.param("s", String(size)) : current;
385
+ return current;
386
+ }
387
+ /**
528
388
  * Sets the url target to something on YouTube.
529
389
  *
530
390
  * @param api -
@@ -537,20 +397,17 @@ function _define_property(obj, key, value) {
537
397
  * The url for YouTube. If you set the api and
538
398
  * id, then the url will be targeted to a specific video,
539
399
  * otherwise, the base domain url of YouTube will be returned.
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: /**
400
+ */ youTube(api, id) {
401
+ let current = this.parse(ZUrlBuilder.UrlYouTube);
402
+ current = api ? current.path(`${api}/${id}`) : current;
403
+ // The watch api is a little bizarre that they don't actually
404
+ // use the same format as their other apis. So we will handle this here.
405
+ if (api === "watch") {
406
+ current = current.path(api).param("v", id);
407
+ }
408
+ return current;
409
+ }
410
+ /**
554
411
  * Sets the protocol.
555
412
  *
556
413
  * @param protocol -
@@ -558,14 +415,11 @@ function _define_property(obj, key, value) {
558
415
  *
559
416
  * @returns
560
417
  * This object.
561
- */ function protocol(protocol) {
562
- this._url.protocol = protocol;
563
- return this;
564
- }
565
- },
566
- {
567
- key: "username",
568
- value: /**
418
+ */ protocol(protocol) {
419
+ this._url.protocol = protocol;
420
+ return this;
421
+ }
422
+ /**
569
423
  * Sets the user name.
570
424
  *
571
425
  * Used for things like ssh and ftp.
@@ -575,14 +429,11 @@ function _define_property(obj, key, value) {
575
429
  *
576
430
  * @returns
577
431
  * This object.
578
- */ function username(user) {
579
- this._url.username = user;
580
- return this;
581
- }
582
- },
583
- {
584
- key: "password",
585
- value: /**
432
+ */ username(user) {
433
+ this._url.username = user;
434
+ return this;
435
+ }
436
+ /**
586
437
  * Sets the password.
587
438
  *
588
439
  * This is only valid if the username is set.
@@ -592,14 +443,11 @@ function _define_property(obj, key, value) {
592
443
  *
593
444
  * @returns
594
445
  * This object.
595
- */ function password(pwd) {
596
- this._url.password = pwd;
597
- return this;
598
- }
599
- },
600
- {
601
- key: "hostname",
602
- value: /**
446
+ */ password(pwd) {
447
+ this._url.password = pwd;
448
+ return this;
449
+ }
450
+ /**
603
451
  * Sets the host name.
604
452
  *
605
453
  * This sets the entire hostname as the root domain. This
@@ -611,14 +459,11 @@ function _define_property(obj, key, value) {
611
459
  *
612
460
  * @returns
613
461
  * This object.
614
- */ function hostname(host) {
615
- this._url.hostname = host;
616
- return this;
617
- }
618
- },
619
- {
620
- key: "subdomain",
621
- value: /**
462
+ */ hostname(host) {
463
+ this._url.hostname = host;
464
+ return this;
465
+ }
466
+ /**
622
467
  * Adds a subdomain in front of the hostname.
623
468
  *
624
469
  * If a hostname was never set, then domain becomes the hostname.
@@ -628,28 +473,22 @@ function _define_property(obj, key, value) {
628
473
  *
629
474
  * @returns
630
475
  * This object.
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: /**
476
+ */ subdomain(domain) {
477
+ this._url.hostname = this._url.hostname ? `${domain}.${this._url.hostname}` : domain;
478
+ return this;
479
+ }
480
+ /**
639
481
  * Removes a subdomain from the current domain.
640
482
  *
641
483
  * @returns
642
484
  * This object.
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: /**
485
+ */ popSubdomain() {
486
+ const parts = this._url.hostname.split(".");
487
+ parts.splice(0, 1);
488
+ this._url.hostname = parts.join(".");
489
+ return this;
490
+ }
491
+ /**
653
492
  * Sets the port.
654
493
  *
655
494
  * @param port -
@@ -657,14 +496,11 @@ function _define_property(obj, key, value) {
657
496
  *
658
497
  * @returns
659
498
  * This object.
660
- */ function port(port) {
661
- this._url.port = port;
662
- return this;
663
- }
664
- },
665
- {
666
- key: "path",
667
- value: /**
499
+ */ port(port) {
500
+ this._url.port = port;
501
+ return this;
502
+ }
503
+ /**
668
504
  * Removes all existing path segments and restarts the path.
669
505
  *
670
506
  * @param path -
@@ -672,16 +508,13 @@ function _define_property(obj, key, value) {
672
508
  *
673
509
  * @returns
674
510
  * This object.
675
- */ function path(path) {
676
- this._url.path = [
677
- path
678
- ];
679
- return this;
680
- }
681
- },
682
- {
683
- key: "append",
684
- value: /**
511
+ */ path(path) {
512
+ this._url.path = [
513
+ path
514
+ ];
515
+ return this;
516
+ }
517
+ /**
685
518
  * Appends a path segment.
686
519
  *
687
520
  * @param path -
@@ -689,14 +522,11 @@ function _define_property(obj, key, value) {
689
522
  *
690
523
  * @returns
691
524
  * This object.
692
- */ function append(path) {
693
- this._url.path.push(path);
694
- return this;
695
- }
696
- },
697
- {
698
- key: "hash",
699
- value: /**
525
+ */ append(path) {
526
+ this._url.path.push(path);
527
+ return this;
528
+ }
529
+ /**
700
530
  * Sets the hash section.
701
531
  *
702
532
  * @param hash -
@@ -704,14 +534,11 @@ function _define_property(obj, key, value) {
704
534
  *
705
535
  * @returns
706
536
  * This object.
707
- */ function hash(hash) {
708
- this._url.hash = hash;
709
- return this;
710
- }
711
- },
712
- {
713
- key: "param",
714
- value: /**
537
+ */ hash(hash) {
538
+ this._url.hash = hash;
539
+ return this;
540
+ }
541
+ /**
715
542
  * Adds a search parameter.
716
543
  *
717
544
  * This version assumes that value is not null.
@@ -723,17 +550,14 @@ function _define_property(obj, key, value) {
723
550
  *
724
551
  * @returns
725
552
  * This object.
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: /**
553
+ */ param(key, val) {
554
+ this._url.params.push({
555
+ key,
556
+ val
557
+ });
558
+ return this;
559
+ }
560
+ /**
737
561
  * Removes all duplicate params and adds one with the key to the value.
738
562
  *
739
563
  * @param key -
@@ -741,16 +565,11 @@ function _define_property(obj, key, value) {
741
565
  * @param val -
742
566
  * The parameter value. If this is falsy, then
743
567
  * the key is deleted.
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: /**
568
+ */ onlyParam(key, val) {
569
+ this._url.params = this._url.params.filter((p)=>p.key !== key);
570
+ return val ? this.param(key, val) : this;
571
+ }
572
+ /**
754
573
  * Adds a page param.
755
574
  *
756
575
  * @param page -
@@ -759,13 +578,10 @@ function _define_property(obj, key, value) {
759
578
  *
760
579
  * @returns
761
580
  * This object.
762
- */ function page(page) {
763
- return this.onlyParam("page", page == null || page < 1 ? undefined : String(page));
764
- }
765
- },
766
- {
767
- key: "size",
768
- value: /**
581
+ */ page(page) {
582
+ return this.onlyParam("page", page == null || page < 1 ? undefined : String(page));
583
+ }
584
+ /**
769
585
  * Adds a size param.
770
586
  *
771
587
  * @param size -
@@ -774,13 +590,10 @@ function _define_property(obj, key, value) {
774
590
  *
775
591
  * @returns
776
592
  * This object.
777
- */ function size(size) {
778
- return this.onlyParam("size", size == null || size < 0 ? undefined : String(size));
779
- }
780
- },
781
- {
782
- key: "search",
783
- value: /**
593
+ */ size(size) {
594
+ return this.onlyParam("size", size == null || size < 0 ? undefined : String(size));
595
+ }
596
+ /**
784
597
  * Adds a search param.
785
598
  *
786
599
  * @param search -
@@ -789,13 +602,10 @@ function _define_property(obj, key, value) {
789
602
  *
790
603
  * @returns
791
604
  * This object.
792
- */ function search(search) {
793
- return this.onlyParam("search", search || undefined);
794
- }
795
- },
796
- {
797
- key: "filter",
798
- value: /**
605
+ */ search(search) {
606
+ return this.onlyParam("search", search || undefined);
607
+ }
608
+ /**
799
609
  * Adds a filter param.
800
610
  *
801
611
  * @param filter -
@@ -804,13 +614,10 @@ function _define_property(obj, key, value) {
804
614
  *
805
615
  * @returns
806
616
  * This object.
807
- */ function filter(filter) {
808
- return this.onlyParam("filter", filter || undefined);
809
- }
810
- },
811
- {
812
- key: "sort",
813
- value: /**
617
+ */ filter(filter) {
618
+ return this.onlyParam("filter", filter || undefined);
619
+ }
620
+ /**
814
621
  * Adds a sort param.
815
622
  *
816
623
  * @param sort -
@@ -819,101 +626,77 @@ function _define_property(obj, key, value) {
819
626
  *
820
627
  * @returns
821
628
  * This object.
822
- */ function sort(sort) {
823
- return this.onlyParam("sort", sort || undefined);
824
- }
825
- },
826
- {
827
- key: "build",
828
- value: /**
629
+ */ sort(sort) {
630
+ return this.onlyParam("sort", sort || undefined);
631
+ }
632
+ /**
829
633
  * Builds the url string and returns it.
830
634
  *
831
635
  * @returns
832
636
  * The url string.
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: /**
637
+ */ build() {
638
+ const search = sortBy(this._url.params, (p)=>p.key).map((param)=>`${param.key}=${encodeURIComponent(param.val)}`).join("&");
639
+ const user = trim(this._url.username);
640
+ const password = trim(this._url.password);
641
+ let protocol = trim(this._url.protocol);
642
+ let host = trim(this._url.hostname);
643
+ let port = String(this._url.port);
644
+ let hash = trim(this._url.hash);
645
+ let path = this._url.path.map((segment)=>trim(segment, "/")).join("/");
646
+ let credentials = "";
647
+ protocol = trimEnd(protocol, "/:");
648
+ host = trim(host, "/");
649
+ hash = trimStart(hash, "#");
650
+ path = trim(path, "/");
651
+ if (ZUrlBuilder.defaults(protocol, port)) {
652
+ port = "";
653
+ } else {
654
+ port = `:${port}`;
655
+ }
656
+ if (user) {
657
+ credentials = password ? `${user}:${password}@` : `${user}@`;
658
+ }
659
+ let url = `${protocol}://${credentials}${host}${port}`;
660
+ if (path) {
661
+ url = `${url}/${path}`;
662
+ }
663
+ if (search) {
664
+ url = `${url}/?${search}`;
665
+ }
666
+ if (hash) {
667
+ url = `${url}#${hash}`;
668
+ }
669
+ return url;
670
+ }
671
+ /**
877
672
  * Gets the current information about the uri being built.
878
673
  *
879
674
  * @returns The current uri information.
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.
675
+ */ info() {
676
+ return JSON.parse(JSON.stringify(this._url));
677
+ }
678
+ /**
679
+ * Initializes a new instance of this object.
898
680
  *
899
681
  * @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
- }();
682
+ * The protocol to use.
683
+ * @param hostname -
684
+ * The hostname to connect with.
685
+ */ constructor(protocol = "http", hostname = "localhost"){
686
+ /**
687
+ * The representation of the url object.
688
+ */ _define_property(this, "_url", void 0);
689
+ this._url = {
690
+ protocol,
691
+ hostname,
692
+ path: [
693
+ "/"
694
+ ],
695
+ hash: "",
696
+ params: []
697
+ };
698
+ }
699
+ }
917
700
  /**
918
701
  * The url to the gravatar api.
919
702
  */ _define_property(ZUrlBuilder, "UrlGravatar", "https://s.gravatar.com/avatar");