@ztimson/utils 0.10.3 → 0.11.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/utils.mjs DELETED
@@ -1,617 +0,0 @@
1
- var D = Object.defineProperty;
2
- var k = (n, e, t) => e in n ? D(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var c = (n, e, t) => (k(n, typeof e != "symbol" ? e + "" : e, t), t);
4
- function G(n, e = !1) {
5
- if (n == null)
6
- throw new Error("Cannot clean a NULL value");
7
- return Array.isArray(n) ? n = n.filter((t) => t != null) : Object.entries(n).forEach(([t, r]) => {
8
- (e && r === void 0 || !e && r == null) && delete n[t];
9
- }), n;
10
- }
11
- function _(n) {
12
- return JSON.parse(JSON.stringify(n));
13
- }
14
- function A(n, e, t) {
15
- if (!(n == null || !e))
16
- return e.split(/[.[\]]/g).filter((r) => r.length).reduce((r, o, s, i) => {
17
- if ((o[0] == '"' || o[0] == "'") && (o = o.slice(1, -1)), !(r != null && r.hasOwnProperty(o))) {
18
- if (t == null)
19
- return;
20
- r[o] = {};
21
- }
22
- return t !== void 0 && s == i.length - 1 ? r[o] = t : r[o];
23
- }, n);
24
- }
25
- function j(n, e, t = {}) {
26
- if (typeof n == "object" && !Array.isArray(n)) {
27
- for (const r of Object.keys(n)) {
28
- const o = e ? e + "." + r : r;
29
- typeof n[r] == "object" ? j(n[r], o, t) : t[o] = n[r];
30
- }
31
- return t;
32
- }
33
- }
34
- function T(n, e, t = !1) {
35
- if (n == null)
36
- return t;
37
- if (Array.isArray(e))
38
- return e.findIndex((o, s) => !T(n[s], e[s], t)) == -1;
39
- const r = typeof e;
40
- return r != typeof n ? !1 : r == "object" ? Object.keys(e).find((o) => !T(n[o], e[o], t)) == null : r == "function" ? n.toString() == e.toString() : n == e;
41
- }
42
- function B(n, e) {
43
- const t = typeof n, r = typeof e;
44
- return t != "object" || n == null || r != "object" || e == null ? t == "function" && r == "function" ? n.toString() == e.toString() : n === e : Object.keys(n).length != Object.keys(e).length ? !1 : Object.keys(n).every((s) => B(n[s], e[s]));
45
- }
46
- function tt(n, e) {
47
- e.forEach((t) => {
48
- Object.getOwnPropertyNames(t.prototype).forEach((r) => {
49
- Object.defineProperty(
50
- n.prototype,
51
- r,
52
- Object.getOwnPropertyDescriptor(t.prototype, r) || /* @__PURE__ */ Object.create(null)
53
- );
54
- });
55
- });
56
- }
57
- function et(n, e) {
58
- let t = [];
59
- return JSON.parse(JSON.stringify(n, (r, o) => {
60
- if (typeof o == "object" && o !== null) {
61
- if (t.includes(o))
62
- return;
63
- t.push(o);
64
- }
65
- return o;
66
- }, e));
67
- }
68
- function nt(n, e) {
69
- return n.indexOf(e) === -1 && n.push(e), n;
70
- }
71
- function rt(n, e) {
72
- return P([
73
- ...n.filter((t) => !e.includes((r) => B(t, r))),
74
- ...e.filter((t) => !n.includes((r) => B(t, r)))
75
- ]);
76
- }
77
- function ot(n) {
78
- return function(e, t) {
79
- const r = A(e, n), o = A(t, n);
80
- return typeof r != "string" || typeof o != "string" ? 1 : r.toLowerCase().localeCompare(o.toLowerCase());
81
- };
82
- }
83
- function M(n, e = []) {
84
- return n.forEach((t) => Array.isArray(t) ? M(t, e) : e.push(t)), e;
85
- }
86
- function st(n, e = !1) {
87
- return function(t, r) {
88
- const o = A(t, n), s = A(r, n);
89
- return typeof o == "number" && typeof s == "number" ? (e ? -1 : 1) * (o - s) : o > s ? e ? -1 : 1 : o < s ? e ? 1 : -1 : 0;
90
- };
91
- }
92
- function it(n, e) {
93
- return (t) => B(t[n], e);
94
- }
95
- function P(n) {
96
- for (let e = n.length - 1; e >= 0; e--)
97
- n.slice(0, e).find((t) => B(t, n[e])) && n.splice(e, 1);
98
- return n;
99
- }
100
- function ct(n) {
101
- return Array.isArray(n) ? n : [n];
102
- }
103
- class x extends Array {
104
- get size() {
105
- return this.length;
106
- }
107
- constructor(e = []) {
108
- super(), e != null && e.forEach && e.forEach((t) => this.add(t));
109
- }
110
- add(e) {
111
- this.has(e) || this.push(e);
112
- }
113
- delete(e) {
114
- const t = this.indexOf(e);
115
- t != -1 && this.slice(t, 1);
116
- }
117
- difference(e) {
118
- return new x(this.reduce((t, r) => (e.has(r) || t.push(r), t), []));
119
- }
120
- has(e) {
121
- return this.indexOf(e) != -1;
122
- }
123
- intersection(e) {
124
- return new x(this.reduce((t, r) => (e.has(r) && t.push(r), t), []));
125
- }
126
- isDisjointFrom(e) {
127
- return this.intersection(e).size == 0;
128
- }
129
- isSubsetOf(e) {
130
- return this.findIndex((t) => !e.has(t)) == -1;
131
- }
132
- isSuperset(e) {
133
- return e.findIndex((t) => !this.has(t)) == -1;
134
- }
135
- symmetricDifference(e) {
136
- return new x([...this.difference(e), ...e.difference(this)]);
137
- }
138
- union(e) {
139
- return new x([...this, ...e]);
140
- }
141
- }
142
- function ut(n, e) {
143
- const t = document.createElement("a");
144
- t.href = n, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
145
- }
146
- class $ {
147
- constructor() {
148
- c(this, "listeners", {});
149
- }
150
- static emit(e, ...t) {
151
- (this.listeners["*"] || []).forEach((r) => r(e, ...t)), (this.listeners[e.toString()] || []).forEach((r) => r(...t));
152
- }
153
- static off(e, t) {
154
- const r = e.toString();
155
- this.listeners[r] = (this.listeners[r] || []).filter((o) => o === t);
156
- }
157
- static on(e, t) {
158
- var o;
159
- const r = e.toString();
160
- return this.listeners[r] || (this.listeners[r] = []), (o = this.listeners[r]) == null || o.push(t), () => this.off(e, t);
161
- }
162
- static once(e, t) {
163
- return new Promise((r) => {
164
- const o = this.on(e, (...s) => {
165
- r(s.length == 1 ? s[0] : s), t && t(...s), o();
166
- });
167
- });
168
- }
169
- emit(e, ...t) {
170
- (this.listeners["*"] || []).forEach((r) => r(e, ...t)), (this.listeners[e] || []).forEach((r) => r(...t));
171
- }
172
- off(e, t) {
173
- this.listeners[e] = (this.listeners[e] || []).filter((r) => r === t);
174
- }
175
- on(e, t) {
176
- var r;
177
- return this.listeners[e] || (this.listeners[e] = []), (r = this.listeners[e]) == null || r.push(t), () => this.off(e, t);
178
- }
179
- once(e, t) {
180
- return new Promise((r) => {
181
- const o = this.on(e, (...s) => {
182
- r(s.length == 1 ? s[0] : s), t && t(...s), o();
183
- });
184
- });
185
- }
186
- }
187
- c($, "listeners", {});
188
- class E extends Error {
189
- constructor(t, r) {
190
- super(t);
191
- c(this, "_code");
192
- r != null && (this._code = r);
193
- }
194
- get code() {
195
- return this._code || this.constructor.code;
196
- }
197
- set code(t) {
198
- this._code = t;
199
- }
200
- static from(t) {
201
- const r = Number(t.statusCode) ?? Number(t.code), o = new this(t.message || t.toString());
202
- return Object.assign(o, {
203
- stack: t.stack,
204
- ...t,
205
- code: r ?? void 0
206
- });
207
- }
208
- static instanceof(t) {
209
- return t.constructor.code != null;
210
- }
211
- toString() {
212
- return this.message || super.toString();
213
- }
214
- }
215
- c(E, "code", 500);
216
- class U extends E {
217
- constructor(e = "Bad Request") {
218
- super(e);
219
- }
220
- static instanceof(e) {
221
- return e.constructor.code == this.code;
222
- }
223
- }
224
- c(U, "code", 400);
225
- class Y extends E {
226
- constructor(e = "Unauthorized") {
227
- super(e);
228
- }
229
- static instanceof(e) {
230
- return e.constructor.code == this.code;
231
- }
232
- }
233
- c(Y, "code", 401);
234
- class H extends E {
235
- constructor(e = "Forbidden") {
236
- super(e);
237
- }
238
- static instanceof(e) {
239
- return e.constructor.code == this.code;
240
- }
241
- }
242
- c(H, "code", 403);
243
- class W extends E {
244
- constructor(e = "Not Found") {
245
- super(e);
246
- }
247
- static instanceof(e) {
248
- return e.constructor.code == this.code;
249
- }
250
- }
251
- c(W, "code", 404);
252
- class F extends E {
253
- constructor(e = "Internal Server Error") {
254
- super(e);
255
- }
256
- static instanceof(e) {
257
- return e.constructor.code == this.code;
258
- }
259
- }
260
- c(F, "code", 500);
261
- const m = {
262
- CLEAR: "\x1B[0m",
263
- BRIGHT: "\x1B[1m",
264
- DIM: "\x1B[2m",
265
- UNDERSCORE: "\x1B[4m",
266
- BLINK: "\x1B[5m",
267
- REVERSE: "\x1B[7m",
268
- HIDDEN: "\x1B[8m"
269
- }, w = {
270
- BLACK: "\x1B[30m",
271
- RED: "\x1B[31m",
272
- GREEN: "\x1B[32m",
273
- YELLOW: "\x1B[33m",
274
- BLUE: "\x1B[34m",
275
- MAGENTA: "\x1B[35m",
276
- CYAN: "\x1B[36m",
277
- LIGHT_GREY: "\x1B[37m",
278
- GREY: "\x1B[90m",
279
- LIGHT_RED: "\x1B[91m",
280
- LIGHT_GREEN: "\x1B[92m",
281
- LIGHT_YELLOW: "\x1B[93m",
282
- LIGHT_BLUE: "\x1B[94m",
283
- LIGHT_MAGENTA: "\x1B[95m",
284
- LIGHT_CYAN: "\x1B[96m",
285
- WHITE: "\x1B[97m"
286
- }, at = {
287
- BLACK: "\x1B[40m",
288
- RED: "\x1B[41m",
289
- GREEN: "\x1B[42m",
290
- YELLOW: "\x1B[43m",
291
- BLUE: "\x1B[44m",
292
- MAGENTA: "\x1B[45m",
293
- CYAN: "\x1B[46m",
294
- WHITE: "\x1B[47m",
295
- GREY: "\x1B[100m"
296
- };
297
- var q = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(q || {});
298
- const f = class f extends $ {
299
- constructor(e) {
300
- super(), this.namespace = e;
301
- }
302
- pad(e, t, r, o = !1) {
303
- const s = e.toString(), i = t - s.length;
304
- if (i <= 0)
305
- return s;
306
- const d = Array(~~(i / r.length)).fill(r).join("");
307
- return o ? s + d : d + s;
308
- }
309
- format(...e) {
310
- const t = /* @__PURE__ */ new Date();
311
- return `${`${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()} ${this.pad(t.getHours().toString(), 2, "0")}:${this.pad(t.getMinutes().toString(), 2, "0")}:${this.pad(t.getSeconds().toString(), 2, "0")}.${this.pad(t.getMilliseconds().toString(), 3, "0", !0)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${e.join(" ")}`;
312
- }
313
- debug(...e) {
314
- if (f.LOG_LEVEL < 4)
315
- return;
316
- const t = this.format(...e);
317
- f.emit(4, t), console.debug(w.LIGHT_GREY + t + m.CLEAR);
318
- }
319
- log(...e) {
320
- if (f.LOG_LEVEL < 3)
321
- return;
322
- const t = this.format(...e);
323
- f.emit(3, t), console.log(m.CLEAR + t);
324
- }
325
- info(...e) {
326
- if (f.LOG_LEVEL < 2)
327
- return;
328
- const t = this.format(...e);
329
- f.emit(2, t), console.info(w.BLUE + t + m.CLEAR);
330
- }
331
- warn(...e) {
332
- if (f.LOG_LEVEL < 1)
333
- return;
334
- const t = this.format(...e);
335
- f.emit(1, t), console.warn(w.YELLOW + t + m.CLEAR);
336
- }
337
- error(...e) {
338
- if (f.LOG_LEVEL < 0)
339
- return;
340
- const t = this.format(...e);
341
- f.emit(0, t), console.error(w.RED + t + m.CLEAR);
342
- }
343
- };
344
- c(f, "LOG_LEVEL", 4);
345
- let L = f;
346
- function ht(n) {
347
- const e = (d, p) => p < 1e-7 ? d : e(p, ~~(d % p)), t = n.toString().length - 2;
348
- let r = Math.pow(10, t), o = n * r;
349
- const s = e(o, r);
350
- o = ~~(o / s), r = ~~(r / s);
351
- const i = ~~(o / r);
352
- return o -= i * r, `${i ? i + " " : ""}${~~o}/${~~r}`;
353
- }
354
- function lt(n) {
355
- let e = n.split(" ");
356
- const t = e.length == 2 ? Number(e[0]) : 0;
357
- return e = e.pop().split("/"), t + Number(e[0]) / Number(e[1]);
358
- }
359
- function ft(n, e) {
360
- return n.length - n.replaceAll(e, "").length;
361
- }
362
- function dt(n) {
363
- return Array(n).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
364
- }
365
- const R = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", N = "0123456789", b = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", v = R + N + b;
366
- function pt(n) {
367
- const e = /(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(n);
368
- if (!e)
369
- throw new Error(`Number cannot be parsed: ${n}`);
370
- return `${e[1] ?? ""} (${e[2]}) ${e[3]}-${e[4]}`.trim();
371
- }
372
- function gt(n, e, t) {
373
- return `${n.slice(0, t)}${e}${n.slice(t + 1)}`;
374
- }
375
- function yt(n, e, t, r = !0) {
376
- const o = n.toString(), s = e - o.length;
377
- if (s <= 0)
378
- return o;
379
- const i = Array(~~(s / t.length)).fill(t).join("");
380
- return r ? i + o : o + i;
381
- }
382
- function Et(n, e = v) {
383
- return Array(n).fill(null).map(() => {
384
- const t = ~~(Math.random() * e.length);
385
- return e[t];
386
- }).join("");
387
- }
388
- function mt(n, e = !1, t = !1, r = !1) {
389
- if (!e && !t && !r)
390
- throw new Error("Must enable at least one: letters, numbers, symbols");
391
- return Array(n).fill(null).map(() => {
392
- let o;
393
- do {
394
- const s = ~~(Math.random() * 3);
395
- e && s == 0 ? o = R[~~(Math.random() * R.length)] : t && s == 1 ? o = N[~~(Math.random() * N.length)] : r && s == 2 && (o = b[~~(Math.random() * b.length)]);
396
- } while (!o);
397
- return o;
398
- }).join("");
399
- }
400
- function xt(n, e) {
401
- if (typeof e == "string" && (e = new RegExp(e, "g")), !e.global)
402
- throw new TypeError("Regular expression must be global.");
403
- let t = [], r;
404
- for (; (r = e.exec(n)) !== null; )
405
- t.push(r);
406
- return t;
407
- }
408
- function z(n) {
409
- var e = J(V(Z(K(n), 8 * n.length)));
410
- return e.toLowerCase();
411
- }
412
- function J(n) {
413
- for (var e, t = "0123456789ABCDEF", r = "", o = 0; o < n.length; o++)
414
- e = n.charCodeAt(o), r += t.charAt(e >>> 4 & 15) + t.charAt(15 & e);
415
- return r;
416
- }
417
- function K(n) {
418
- for (var e = Array(n.length >> 2), t = 0; t < e.length; t++)
419
- e[t] = 0;
420
- for (t = 0; t < 8 * n.length; t += 8)
421
- e[t >> 5] |= (255 & n.charCodeAt(t / 8)) << t % 32;
422
- return e;
423
- }
424
- function V(n) {
425
- for (var e = "", t = 0; t < 32 * n.length; t += 8)
426
- e += String.fromCharCode(n[t >> 5] >>> t % 32 & 255);
427
- return e;
428
- }
429
- function Z(n, e) {
430
- n[e >> 5] |= 128 << e % 32, n[14 + (e + 64 >>> 9 << 4)] = e;
431
- for (var t = 1732584193, r = -271733879, o = -1732584194, s = 271733878, i = 0; i < n.length; i += 16) {
432
- var d = t, p = r, O = o, S = s;
433
- r = l(r = l(r = l(r = l(r = h(r = h(r = h(r = h(r = a(r = a(r = a(r = a(r = u(r = u(r = u(r = u(r, o = u(o, s = u(s, t = u(t, r, o, s, n[i + 0], 7, -680876936), r, o, n[i + 1], 12, -389564586), t, r, n[i + 2], 17, 606105819), s, t, n[i + 3], 22, -1044525330), o = u(o, s = u(s, t = u(t, r, o, s, n[i + 4], 7, -176418897), r, o, n[i + 5], 12, 1200080426), t, r, n[i + 6], 17, -1473231341), s, t, n[i + 7], 22, -45705983), o = u(o, s = u(s, t = u(t, r, o, s, n[i + 8], 7, 1770035416), r, o, n[i + 9], 12, -1958414417), t, r, n[i + 10], 17, -42063), s, t, n[i + 11], 22, -1990404162), o = u(o, s = u(s, t = u(t, r, o, s, n[i + 12], 7, 1804603682), r, o, n[i + 13], 12, -40341101), t, r, n[i + 14], 17, -1502002290), s, t, n[i + 15], 22, 1236535329), o = a(o, s = a(s, t = a(t, r, o, s, n[i + 1], 5, -165796510), r, o, n[i + 6], 9, -1069501632), t, r, n[i + 11], 14, 643717713), s, t, n[i + 0], 20, -373897302), o = a(o, s = a(s, t = a(t, r, o, s, n[i + 5], 5, -701558691), r, o, n[i + 10], 9, 38016083), t, r, n[i + 15], 14, -660478335), s, t, n[i + 4], 20, -405537848), o = a(o, s = a(s, t = a(t, r, o, s, n[i + 9], 5, 568446438), r, o, n[i + 14], 9, -1019803690), t, r, n[i + 3], 14, -187363961), s, t, n[i + 8], 20, 1163531501), o = a(o, s = a(s, t = a(t, r, o, s, n[i + 13], 5, -1444681467), r, o, n[i + 2], 9, -51403784), t, r, n[i + 7], 14, 1735328473), s, t, n[i + 12], 20, -1926607734), o = h(o, s = h(s, t = h(t, r, o, s, n[i + 5], 4, -378558), r, o, n[i + 8], 11, -2022574463), t, r, n[i + 11], 16, 1839030562), s, t, n[i + 14], 23, -35309556), o = h(o, s = h(s, t = h(t, r, o, s, n[i + 1], 4, -1530992060), r, o, n[i + 4], 11, 1272893353), t, r, n[i + 7], 16, -155497632), s, t, n[i + 10], 23, -1094730640), o = h(o, s = h(s, t = h(t, r, o, s, n[i + 13], 4, 681279174), r, o, n[i + 0], 11, -358537222), t, r, n[i + 3], 16, -722521979), s, t, n[i + 6], 23, 76029189), o = h(o, s = h(s, t = h(t, r, o, s, n[i + 9], 4, -640364487), r, o, n[i + 12], 11, -421815835), t, r, n[i + 15], 16, 530742520), s, t, n[i + 2], 23, -995338651), o = l(o, s = l(s, t = l(t, r, o, s, n[i + 0], 6, -198630844), r, o, n[i + 7], 10, 1126891415), t, r, n[i + 14], 15, -1416354905), s, t, n[i + 5], 21, -57434055), o = l(o, s = l(s, t = l(t, r, o, s, n[i + 12], 6, 1700485571), r, o, n[i + 3], 10, -1894986606), t, r, n[i + 10], 15, -1051523), s, t, n[i + 1], 21, -2054922799), o = l(o, s = l(s, t = l(t, r, o, s, n[i + 8], 6, 1873313359), r, o, n[i + 15], 10, -30611744), t, r, n[i + 6], 15, -1560198380), s, t, n[i + 13], 21, 1309151649), o = l(o, s = l(s, t = l(t, r, o, s, n[i + 4], 6, -145523070), r, o, n[i + 11], 10, -1120210379), t, r, n[i + 2], 15, 718787259), s, t, n[i + 9], 21, -343485551), t = y(t, d), r = y(r, p), o = y(o, O), s = y(s, S);
434
- }
435
- return Array(t, r, o, s);
436
- }
437
- function C(n, e, t, r, o, s) {
438
- return y(Q(y(y(e, n), y(r, s)), o), t);
439
- }
440
- function u(n, e, t, r, o, s, i) {
441
- return C(e & t | ~e & r, n, e, o, s, i);
442
- }
443
- function a(n, e, t, r, o, s, i) {
444
- return C(e & r | t & ~r, n, e, o, s, i);
445
- }
446
- function h(n, e, t, r, o, s, i) {
447
- return C(e ^ t ^ r, n, e, o, s, i);
448
- }
449
- function l(n, e, t, r, o, s, i) {
450
- return C(t ^ (e | ~r), n, e, o, s, i);
451
- }
452
- function y(n, e) {
453
- var t = (65535 & n) + (65535 & e);
454
- return (n >> 16) + (e >> 16) + (t >> 16) << 16 | 65535 & t;
455
- }
456
- function Q(n, e) {
457
- return n << e | n >>> 32 - e;
458
- }
459
- function Bt(n) {
460
- return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(n);
461
- }
462
- function wt(n) {
463
- return Object.entries(n).map(
464
- ([e, t]) => encodeURIComponent(e) + "=" + encodeURIComponent(t)
465
- ).join("&");
466
- }
467
- function At(n, e = "mp") {
468
- return n ? `https://www.gravatar.com/avatar/${z(n)}?d=${e}` : "";
469
- }
470
- function Ct(n) {
471
- const e = new RegExp(
472
- "(?:(?<protocol>[\\w\\d]+)\\:\\/\\/)?(?:(?<user>.+)\\@)?(?<host>(?<domain>[^:\\/\\?#@\\n]+)(?:\\:(?<port>\\d*))?)(?<path>\\/.*?)?(?:\\?(?<query>.*?))?(?:#(?<fragment>.*?))?$",
473
- "gm"
474
- ).exec(n), t = (e == null ? void 0 : e.groups) ?? {}, r = t.domain.split(".");
475
- if (t.port != null && (t.port = Number(t.port)), r.length > 2 && (t.domain = r.splice(-2, 2).join("."), t.subdomain = r.join(".")), t.query) {
476
- const o = t.query.split("&"), s = {};
477
- o.forEach((i) => {
478
- const [d, p] = i.split("=");
479
- s[d] = p;
480
- }), t.query = s;
481
- }
482
- return t;
483
- }
484
- class Ot extends Promise {
485
- constructor(t) {
486
- super((r, o) => t(
487
- (s) => r(s),
488
- (s) => o(s),
489
- (s) => this.progress = s
490
- ));
491
- c(this, "listeners", []);
492
- c(this, "_progress", 0);
493
- }
494
- get progress() {
495
- return this._progress;
496
- }
497
- set progress(t) {
498
- t != this._progress && (this._progress = t, this.listeners.forEach((r) => r(t)));
499
- }
500
- onProgress(t) {
501
- return this.listeners.push(t), this;
502
- }
503
- }
504
- function St(n) {
505
- return (n instanceof Date ? n.getTime() : n) - (/* @__PURE__ */ new Date()).getTime();
506
- }
507
- function Rt(n) {
508
- return new Promise((e) => setTimeout(e, n));
509
- }
510
- function Nt(n) {
511
- const e = n instanceof Date ? n : new Date(n);
512
- return new Intl.DateTimeFormat("en-us", {
513
- weekday: "long",
514
- month: "short",
515
- day: "numeric",
516
- hour: "numeric",
517
- minute: "numeric",
518
- hour12: !0
519
- }).format(e);
520
- }
521
- const g = class g {
522
- constructor(e = {}) {
523
- c(this, "interceptors", {});
524
- c(this, "headers", {});
525
- this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => g.addInterceptor(t));
526
- }
527
- static addInterceptor(e) {
528
- const t = Object.keys(g.interceptors).length.toString();
529
- return g.interceptors[t] = e, () => {
530
- g.interceptors[t] = null;
531
- };
532
- }
533
- addInterceptor(e) {
534
- const t = Object.keys(this.interceptors).length.toString();
535
- return this.interceptors[t] = e, () => {
536
- this.interceptors[t] = null;
537
- };
538
- }
539
- async request(e = {}) {
540
- var o, s;
541
- if (!this.opts.url && !e.url)
542
- throw new Error("URL needs to be set");
543
- const t = ((o = e.url) != null && o.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1"), r = G({
544
- "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
545
- ...g.headers,
546
- ...this.headers,
547
- ...e.headers
548
- });
549
- return fetch(t, {
550
- headers: r,
551
- method: e.method || (e.body ? "POST" : "GET"),
552
- body: (s = r["Content-Type"]) != null && s.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
553
- }).then(async (i) => {
554
- var d, p;
555
- for (let O of [...Object.values(g.interceptors), ...Object.values(this.interceptors)])
556
- await new Promise((S) => O(i, () => S()));
557
- if (!i.ok)
558
- throw new Error(i.statusText);
559
- return !e.skipConverting && ((d = i.headers.get("Content-Type")) != null && d.startsWith("application/json")) ? await i.json() : !e.skipConverting && ((p = i.headers.get("Content-Type")) != null && p.startsWith("text/plain")) ? await i.text() : i;
560
- });
561
- }
562
- };
563
- c(g, "interceptors", {}), c(g, "headers", {});
564
- let I = g;
565
- export {
566
- x as ASet,
567
- U as BadRequestError,
568
- at as CliBackground,
569
- m as CliEffects,
570
- w as CliForeground,
571
- E as CustomError,
572
- H as ForbiddenError,
573
- F as InternalServerError,
574
- q as LOG_LEVEL,
575
- L as Logger,
576
- W as NotFoundError,
577
- Ot as PromiseProgress,
578
- $ as TypedEmitter,
579
- Y as UnauthorizedError,
580
- I as XHR,
581
- nt as addUnique,
582
- rt as arrayDiff,
583
- ot as caseInsensitiveSort,
584
- G as clean,
585
- ft as countChars,
586
- dt as createHex,
587
- ht as dec2Frac,
588
- _ as deepCopy,
589
- A as dotNotation,
590
- ut as download,
591
- it as findByProp,
592
- M as flattenArr,
593
- j as flattenObj,
594
- wt as formEncode,
595
- Nt as formatDate,
596
- pt as formatPhoneNumber,
597
- lt as fracToDec,
598
- At as gravatar,
599
- T as includes,
600
- gt as insertAt,
601
- B as isEqual,
602
- ct as makeArray,
603
- P as makeUnique,
604
- xt as matchAll,
605
- z as md5,
606
- tt as mixin,
607
- yt as pad,
608
- Et as randomString,
609
- mt as randomStringBuilder,
610
- et as sanitizedJSON,
611
- Rt as sleep,
612
- st as sortByProp,
613
- St as timeUntil,
614
- Ct as urlParser,
615
- Bt as validateEmail
616
- };
617
- //# sourceMappingURL=utils.mjs.map