esexts 2.1.0 → 2.2.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/esexts.js CHANGED
@@ -1,824 +1,811 @@
1
- function h(t, e) {
2
- return Object.defineProperties(t, Object.fromEntries(Object.keys(e).map((n) => [n, { value: e[n], enumerable: !1, configurable: !0, writable: !0 }])));
1
+ //#region lib/util.js
2
+ function e(e, t) {
3
+ return Object.defineProperties(e, Object.fromEntries(Object.keys(t).map((e) => [e, {
4
+ value: t[e],
5
+ enumerable: !1,
6
+ configurable: !0,
7
+ writable: !0
8
+ }])));
3
9
  }
4
- function g() {
5
- return {
6
- new: function(...t) {
7
- return new this(...t);
8
- }
9
- };
10
+ function t() {
11
+ return { new: function(...e) {
12
+ return new this(...e);
13
+ } };
10
14
  }
11
- function m(...t) {
12
- const e = {};
13
- for (const n of t) {
14
- const [r, i] = Array.isArray(n) ? n : [n, "$" + n];
15
- e[i] = function() {
16
- return this[r];
17
- };
18
- }
19
- return e;
15
+ function n(...e) {
16
+ let t = {};
17
+ for (let n of e) {
18
+ let [e, r] = Array.isArray(n) ? n : [n, "$" + n];
19
+ t[r] = function() {
20
+ return this[e];
21
+ };
22
+ }
23
+ return t;
20
24
  }
21
- function f(t, e, n, ...r) {
22
- const i = {}, s = (o, u, c) => (u !== null && o.splice(u >= 0 ? u : o.length + u + 1, 0, c), o);
23
- for (const o of r) {
24
- const [u, c] = Array.isArray(o) ? o : [o, "$" + o + n.toString().replaceAll("-", "_")];
25
- if (n === "")
26
- i[c] = function(...a) {
27
- return t[u].apply(this, s(a, e, this));
28
- };
29
- else if (n === "t")
30
- i[c] = function(...a) {
31
- return t[u].apply(this, s(a, e, this)), this;
32
- };
33
- else if (n === "a")
34
- i[c] = function(...a) {
35
- return t[u].apply(this, s(a, e, this)), a;
36
- };
37
- else if (n >= 0)
38
- i[c] = function(...a) {
39
- return t[u].apply(this, s(a, e, this)), a[n];
40
- };
41
- else if (n < 0)
42
- i[c] = function(...a) {
43
- return t[u].apply(this, s(a, e, this)), a[a.length + n];
44
- };
45
- else
46
- throw Error("unreachable");
47
- }
48
- return i;
25
+ function r(e, t, n, ...r) {
26
+ let i = {}, a = (e, t, n) => (t !== null && e.splice(t >= 0 ? t : e.length + t + 1, 0, n), e);
27
+ for (let o of r) {
28
+ let [r, s] = Array.isArray(o) ? o : [o, "$" + o + n.toString().replaceAll("-", "_")];
29
+ if (n === "") i[s] = function(...n) {
30
+ return e[r].apply(this, a(n, t, this));
31
+ };
32
+ else if (n === "t") i[s] = function(...n) {
33
+ return e[r].apply(this, a(n, t, this)), this;
34
+ };
35
+ else if (n === "a") i[s] = function(...n) {
36
+ return e[r].apply(this, a(n, t, this)), n;
37
+ };
38
+ else if (n >= 0) i[s] = function(...i) {
39
+ return e[r].apply(this, a(i, t, this)), i[n];
40
+ };
41
+ else if (n < 0) i[s] = function(...i) {
42
+ return e[r].apply(this, a(i, t, this)), i[i.length + n];
43
+ };
44
+ else throw Error("unreachable");
45
+ }
46
+ return i;
49
47
  }
50
- function $(t, ...e) {
51
- const n = {};
52
- for (const r of e) {
53
- const [i, s] = Array.isArray(r) ? r : [r, "$" + r];
54
- n[s] = function(...o) {
55
- return [...t[i].apply(this, o)];
56
- };
57
- }
58
- return n;
48
+ function i(e, ...t) {
49
+ let n = {};
50
+ for (let r of t) {
51
+ let [t, i] = Array.isArray(r) ? r : [r, "$" + r];
52
+ n[i] = function(...n) {
53
+ return [...e[t].apply(this, n)];
54
+ };
55
+ }
56
+ return n;
59
57
  }
60
- function b(t = { array: !1 }) {
61
- return function(e = {}, ...n) {
62
- const r = (i, s) => {
63
- const o = Object.prototype.toString.call(i), u = Object.prototype.toString.call(s);
64
- if (o !== u)
65
- return s;
66
- if (o === "[object Array]")
67
- return t.array ? i.concat(...s) : s;
68
- if (o === "[object Object]") {
69
- for (const c in s)
70
- i[c] = r(i[c], s[c]);
71
- return i;
72
- } else
73
- return s;
74
- };
75
- for (const i of n)
76
- e = r(e, i);
77
- return e;
78
- };
58
+ //#endregion
59
+ //#region lib/Object.js
60
+ function a(e = { array: !1 }) {
61
+ return function(t = {}, ...n) {
62
+ let r = (t, n) => {
63
+ let i = Object.prototype.toString.call(t);
64
+ if (i !== Object.prototype.toString.call(n)) return n;
65
+ if (i === "[object Array]") return e.array ? t.concat(...n) : n;
66
+ if (i === "[object Object]") {
67
+ for (let e in n) t[e] = r(t[e], n[e]);
68
+ return t;
69
+ } else return n;
70
+ };
71
+ for (let e of n) t = r(t, e);
72
+ return t;
73
+ };
79
74
  }
80
- const S = b({ array: !1 }), x = b({ array: !0 });
81
- h(Object, {
82
- ...g(),
83
- isObject: function(t) {
84
- return Object.prototype.toString.call(t) === "[object Object]";
85
- },
86
- merge: function(...t) {
87
- return S(this, ...t);
88
- },
89
- concat: function(...t) {
90
- return x(this, ...t);
91
- }
75
+ var o = a({ array: !1 }), s = a({ array: !0 });
76
+ e(Object, {
77
+ ...t(),
78
+ isObject: function(e) {
79
+ return Object.prototype.toString.call(e) === "[object Object]";
80
+ },
81
+ merge: function(...e) {
82
+ return o(this, ...e);
83
+ },
84
+ concat: function(...e) {
85
+ return s(this, ...e);
86
+ }
87
+ }), e(Object.prototype, {
88
+ $clone: function() {
89
+ return JSON.parse(JSON.stringify(this));
90
+ },
91
+ $length: function() {
92
+ return Object.keys(this).length;
93
+ },
94
+ ...r(Object, 0, "", "entries", "keys", "values", "assign"),
95
+ ...r(JSON, 0, "", "stringify"),
96
+ $merge: function(...e) {
97
+ return o(this, ...e);
98
+ },
99
+ $concat: function(...e) {
100
+ return s(this, ...e);
101
+ },
102
+ $empty: function() {
103
+ return Object.keys(this).length == 0;
104
+ },
105
+ $has: function(e) {
106
+ return e in this;
107
+ },
108
+ $pick: function(...e) {
109
+ let t = {};
110
+ for (let n of e) t[n] = this[n];
111
+ return t;
112
+ },
113
+ $omit: function(...e) {
114
+ let t = {}, n = new Set(e);
115
+ for (let e in this) n.has(e) || (t[e] = this[e]);
116
+ return t;
117
+ },
118
+ $attr: function(...e) {
119
+ if (typeof this != "object") return this;
120
+ let [t, n, { defval: r, exists: i, define: a, add: o, sub: s, mul: c, div: l }] = e;
121
+ return e.length == 1 ? this[t] : e.length == 2 ? (this[t] = n, this) : r === void 0 ? typeof i == "boolean" ? (t in this === i && (this[t] = n), this) : a === void 0 ? o === void 0 ? s === void 0 ? c === void 0 ? (l === void 0 || (this[t] = (t in this ? this[t] : r) / l), this) : (this[t] = (t in this ? this[t] : r) * c, this) : (this[t] = (t in this ? this[t] : r) - s, this) : (this[t] = (t in this ? this[t] : r) + o, this) : Object.defineProperty(this, t, {
122
+ value: n,
123
+ enumerable: !1,
124
+ configurable: !0,
125
+ writable: !0,
126
+ ...a
127
+ }) : t in this ? this[t] : r;
128
+ },
129
+ $pipe: function(e, ...t) {
130
+ return e(this, ...t);
131
+ },
132
+ $tee: function(e, ...t) {
133
+ return e(this, ...t), this;
134
+ },
135
+ $toArray: function() {
136
+ return Array.isArray(this) ? this : [this];
137
+ },
138
+ ...r(console, -1, "t", ["debug", "$debug"], ["log", "$log"], ["info", "$info"], ["warn", "$warn"], ["error", "$error"], ["dir", "$dir"]),
139
+ $debugger: function(...e) {
140
+ return console.debug(this, ...e), this;
141
+ },
142
+ $getParents: function(e = !1, t = -1, n = "parent") {
143
+ let r = e ? [this] : [], i = this[n];
144
+ for (; i && t-- != 0;) r.push(i), i = i[n];
145
+ return r;
146
+ },
147
+ $getChildrens: function(e = !1, t = -1, n = "children") {
148
+ let r = [], i = (e, t, a) => {
149
+ if (t && r.push(e), !(a == 0 || !e[n] || e[n].length == 0)) for (let t of e[n]) i(t, !0, a - 1);
150
+ };
151
+ return i(this, e, t), r;
152
+ },
153
+ $tree$find: function(e, t = !0, n = -1, r = "children") {
154
+ if (t && e(this)) return this;
155
+ if (n == 0 || !this[r] || this[r].length == 0) return null;
156
+ for (let t of this[r]) {
157
+ let i = t.$tree$find(e, !0, n - 1, r);
158
+ if (i !== null) return i;
159
+ }
160
+ return null;
161
+ },
162
+ $tree$each: function(e, t = !0, n = -1, r = "children") {
163
+ if (t && e(this), !(n == 0 || !this[r] || this[r].length == 0)) {
164
+ for (let t of this[r]) t.$tree$each(e, !0, n - 1, r);
165
+ return this;
166
+ }
167
+ },
168
+ $tree$map: function(e, t = !0, n = -1, r = "children", i = null) {
169
+ let a = t ? e(this) : this, o = [];
170
+ if (n == 0 || !this[r] || this[r].length == 0) return a;
171
+ for (let t of this[r]) o.push(t.$tree$map(e, !0, n - 1, r, i));
172
+ return a[r] = o, a;
173
+ }
174
+ }), e(Number.prototype, {
175
+ ...r(Math, 0, "", ["ceil", "ceil"], ["floor", "floor"], ["trunc", "trunc"], ["abs", "abs"], ["max", "max"], ["min", "min"]),
176
+ fixed: function(e = 0) {
177
+ return +this.toFixed(e);
178
+ },
179
+ round: function(e = 0) {
180
+ return Math.round(this * 10 ** e) / 10 ** e;
181
+ },
182
+ add: function(e, ...t) {
183
+ return typeof e == "function" ? e(this, ...t) : this + e;
184
+ },
185
+ sub: function(e, ...t) {
186
+ return typeof e == "function" ? e(this, ...t) : this - e;
187
+ },
188
+ mul: function(e, ...t) {
189
+ return typeof e == "function" ? e(this, ...t) : this * e;
190
+ },
191
+ div: function(e, ...t) {
192
+ return typeof e == "function" ? e(this, ...t) : this / e;
193
+ },
194
+ baseConvert: function(e = 64) {
195
+ let t = "", n = this;
196
+ for (; n > 0;) t = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-".at(n % e) + t, n = Math.floor(n / e);
197
+ return t || "0";
198
+ },
199
+ unit: function(e, t = 0) {
200
+ let n = this, r = "";
201
+ for (let [t, i] of Object.entries(e)) {
202
+ if (r = t, i === 0 || n < i) break;
203
+ n /= i;
204
+ }
205
+ return t < 0 ? +n.toFixed(0 - t) + r : n.toFixed(t) + r;
206
+ },
207
+ units: function(e, t = !1) {
208
+ let n = this, r = [];
209
+ for (let [t, i] of Object.entries(e)) if (i == 0 || n < i) {
210
+ r.push([n, t]);
211
+ break;
212
+ } else r.push([n % i, t]), n = Math.floor(n / i);
213
+ return t ? r : r.reverse().map(([e, t]) => e + t).join("");
214
+ },
215
+ toDate: function() {
216
+ return Date.new(this);
217
+ }
218
+ }), e(BigInt.prototype, { toJSON: function() {
219
+ return this >= BigInt(-(2 ** 53 - 1)) && this <= BigInt(2 ** 53 - 1) ? Number(this) : this.toString();
220
+ } }), e(String, { ...t() }), e(String.prototype, {
221
+ ...n(["length", "length$"]),
222
+ $substring: function(e = 0, t = this.length) {
223
+ return e = e >= 0 ? e : this.length + e, t = t >= 0 ? t : this.length + t, this.substring(e, t);
224
+ },
225
+ $substr: function(e = 0, t = this.length) {
226
+ return e = e >= 0 ? e : this.length + e, t = e + t, this.substring(e, t);
227
+ },
228
+ $split: function(e = ",", t = -1) {
229
+ let n = this ? this.split(e) : [];
230
+ return t === -1 ? n : n.$push(n.splice(t - 1).join(e));
231
+ },
232
+ $split$number: function(e = ",") {
233
+ return this.$split(e).map((e) => +e);
234
+ },
235
+ $split$segment: function(e = 1) {
236
+ let t = [];
237
+ for (let n = 0; n < this.length; n += e) t.push(this.substring(n, n + e));
238
+ return t;
239
+ },
240
+ sprintf: function(...e) {
241
+ let [t, ...n] = this.split(/%[sd]/);
242
+ for (let r = 0; r < n.length; r++) t += e[r] + n[r];
243
+ return t;
244
+ },
245
+ subOf: function(e, t, n = 0, r = 0) {
246
+ for (let t = 0; t < n && r != -1; t++, r++) r = this.indexOf(e, r);
247
+ let i = this.indexOf(e, r), a = this.indexOf(t, i);
248
+ return i == -1 || a == -1 ? "" : (i += e.length, this.substring(i, a));
249
+ },
250
+ lastSubOf: function(e, t, n = 0, r = Infinity) {
251
+ for (let t = 0; t < n && r != -1; t++, r--) r = this.lastIndexOf(e, r);
252
+ let i = this.lastIndexOf(e, r), a = this.indexOf(t, i);
253
+ return i == -1 || a == -1 ? "" : (i += e.length, this.substring(i, a));
254
+ },
255
+ camel2under: function() {
256
+ return this.substr(0, 1) + this.substr(1).replace(/([A-Z])/g, (e, t) => "_" + t.toLowerCase());
257
+ },
258
+ under2camel: function() {
259
+ return this.replace(/_([a-z])/g, (e, t) => t.toUpperCase());
260
+ },
261
+ camel2pascal: function() {
262
+ return this.substr(0, 1).toUpperCase() + this.substr(1);
263
+ },
264
+ pascal2camel: function() {
265
+ return this.substr(0, 1).toLowerCase() + this.substr(1);
266
+ },
267
+ under2kebab: function() {
268
+ return this.replace(/_/g, "-");
269
+ },
270
+ kebab2under: function() {
271
+ return this.replace(/-/g, "_");
272
+ },
273
+ baseConvert: function(e = 64) {
274
+ let t = 0;
275
+ for (let n = 0; n < this.length; n++) t = t * e + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-".indexOf(this.at(n));
276
+ return t;
277
+ },
278
+ fixed: function(...e) {
279
+ return +(+this).toFixed(...e);
280
+ },
281
+ toDate: function() {
282
+ return Date.new(this);
283
+ },
284
+ toUint8Array: function() {
285
+ return new TextEncoder().encode(this);
286
+ },
287
+ hexencode: function() {
288
+ return new TextEncoder().encode(this).toHex();
289
+ },
290
+ hexdecode: function() {
291
+ return new TextDecoder().decode(Uint8Array.fromHex(this));
292
+ },
293
+ base64encode: function() {
294
+ return new TextEncoder().encode(this).toBase64();
295
+ },
296
+ base64decode: function() {
297
+ return new TextDecoder().decode(Uint8Array.fromBase64(this));
298
+ }
299
+ }), e(Array, {
300
+ ...t(),
301
+ range: function(...e) {
302
+ let t = [], n = 0, r = 0, i = 1, a = typeof e[e.length - 1] == "boolean" ? e.pop() : !0, o = typeof e[e.length - 1] == "function" ? e.pop() : (e, t, n) => e;
303
+ switch (e.length) {
304
+ case 1:
305
+ [r] = e;
306
+ break;
307
+ case 2:
308
+ [n, r] = e;
309
+ break;
310
+ case 3:
311
+ [n, r, i] = e;
312
+ break;
313
+ default: throw Error("the number of parameters is incorrect!");
314
+ }
315
+ if (i == 0) throw Error("step cannot be 0!");
316
+ for (let e = 0, s = 0, c = Math.abs(r - n), l = Math.abs(i), u = n <= r ? 1 : -1; s < c; s += l) t.push(a ? o(n + s * u, e++, t) : o());
317
+ return t;
318
+ }
319
+ }), e(Array.prototype, {
320
+ ...n("length"),
321
+ ...i(Array.prototype, "entries", "keys", "values"),
322
+ ...r(Array.prototype, null, "", "map"),
323
+ ...r(Array.prototype, null, "t", ["push", "$push"], ["pop", "$pop"], ["shift", "$shift"], ["unshift", "$unshift"], ["splice", "$splice"]),
324
+ ...r(Array.prototype, null, "a", "push", "unshift"),
325
+ ...r(Array.prototype, null, 0, "push", "unshift"),
326
+ $empty: function() {
327
+ return this.length == 0;
328
+ },
329
+ first: function(e = null) {
330
+ return this.length ? this[0] : e;
331
+ },
332
+ last: function(e = null) {
333
+ return this.length ? this[this.length - 1] : e;
334
+ },
335
+ $find: function(e, t = null) {
336
+ return this.find(e) ?? t;
337
+ },
338
+ equals: function(e) {
339
+ return this.length === e.length && (this === e || this.length === 0 || this.every((t, n) => t === e[n]));
340
+ },
341
+ unique: function(e = (e) => e) {
342
+ let t = /* @__PURE__ */ new Set();
343
+ return this.filter((n) => t.has(e(n)) ? !1 : !!t.add(e(n)));
344
+ },
345
+ ...r(Array.prototype, null, "t", ["forEach", "each"]),
346
+ each$async: async function(e) {
347
+ for (let t = 0; t < this.length; t++) await e(this[t], t, this);
348
+ return this;
349
+ },
350
+ map$async: async function(e) {
351
+ let t = [];
352
+ for (let n = 0; n < this.length; n++) t.push(await e(this[n], n, this));
353
+ return t;
354
+ },
355
+ shuffle: function(e = !1) {
356
+ let t = this.length;
357
+ for (; t;) {
358
+ let e = Math.random() * t-- | 0;
359
+ [this[e], this[t]] = [this[t], this[e]];
360
+ }
361
+ return this;
362
+ },
363
+ union: function(e) {
364
+ return Set.new(this).union(Set.new(e)).toArray();
365
+ },
366
+ intersection: function(e) {
367
+ return Set.new(this).intersection(Set.new(e)).toArray();
368
+ },
369
+ difference: function(e) {
370
+ return Set.new(this).difference(Set.new(e)).toArray();
371
+ },
372
+ symmetricDifference: function(e) {
373
+ return Set.new(this).symmetricDifference(Set.new(e)).toArray();
374
+ },
375
+ toMap: function(e = (e, t) => [t, e]) {
376
+ return new Map(this.map(e));
377
+ },
378
+ toSet: function(e = (e) => e) {
379
+ return new Set(this.map(e));
380
+ },
381
+ toUint8Array: function() {
382
+ return new Uint8Array(this);
383
+ },
384
+ toBase64: function() {
385
+ return this.toUint8Array().toBase64();
386
+ },
387
+ toHex: function() {
388
+ return this.toUint8Array().toHex();
389
+ },
390
+ decode: function() {
391
+ return this.toUint8Array().toString();
392
+ },
393
+ assoc: function(e, t, n = {}) {
394
+ let r = this.unique$((t) => t[e]), i = r.length == 0 ? {} : typeof n == "function" ? n(r) : n;
395
+ return this.each$((n) => n[t] = i[n[e]] ?? null);
396
+ },
397
+ toTree: function(t = {}) {
398
+ let { id: n = "id", pid: r = "pid", level: i = "level", root: a = "root", parent: o = "parent", children: s = "children", empty: c = null, hasRoot: l = !0 } = t, u = this.reduce((e, t) => e.$attr(t[n], t), {}), d = this.reduce((e, t) => (e.$attr(t[r], [], !1).$attr(t[r]).$push(t), e), {}), f = this.length && l ? this.find((e) => e[r] === 0) : {
399
+ [n]: 0,
400
+ [r]: -1,
401
+ [a]: null,
402
+ [o]: null,
403
+ [s]: d[0]
404
+ };
405
+ e(f, { [a]: f });
406
+ for (let t of this) e(t, {
407
+ [a]: f,
408
+ [o]: u[t[r]]
409
+ }), t[s] = d[t[n]] || c;
410
+ return f.$tree$each((e) => e[i] = e[o] ? e[o][i] + 1 : 0, -1, s), f;
411
+ },
412
+ $tree2tree: function(t = {}, n = null, r = null) {
413
+ let { id: i = "id", pid: a = "pid", level: o = "level", root: s = "root", parent: c = "parent", children: l = "children", empty: u = null } = t;
414
+ n ||= {
415
+ [i]: 0,
416
+ [a]: -1,
417
+ [o]: 0,
418
+ [s]: null,
419
+ [c]: null,
420
+ [l]: this
421
+ }, r ||= n;
422
+ for (let d of this) e(d, {
423
+ [s]: n,
424
+ [c]: r
425
+ }), d[a] = r[i], d[o] = r[o] + 1, d[l] = d[l] && d[l].length ? d[l] : u, d[l]?.$tree2tree(t, n, d);
426
+ return n;
427
+ },
428
+ $tree$find: function(e, t = !0, n = -1, r = "children") {
429
+ for (let i of this) {
430
+ let a = i.$tree$find(e, t, n, r);
431
+ if (a !== null) return a;
432
+ }
433
+ return null;
434
+ },
435
+ $tree$each: function(e, t = !0, n = -1, r = "children") {
436
+ for (let i of this) i.$tree$each(e, t, n, r);
437
+ return this;
438
+ },
439
+ $tree$map: function(e, t = !0, n = -1, r = "children", i = null) {
440
+ return this.map((a) => a.$tree$map(e, t, n, r, i));
441
+ }
442
+ }), e(Map, { ...t() }), e(Map.prototype, {
443
+ ...n(["size", "$length"]),
444
+ ...i(Map.prototype, "entries", "keys", "values"),
445
+ ...r(Map.prototype, null, "t", ["set", "$set"], ["delete", "$delete"]),
446
+ ...r(Map.prototype, null, "a", "set", "delete"),
447
+ ...r(Map.prototype, null, 0, "set", "delete"),
448
+ ...r(Map.prototype, null, 1, "set", "delete"),
449
+ $getOrInsert: function(e, t = null) {
450
+ return this.has(e) ? this.get(e) : this.$set1(e, t);
451
+ },
452
+ $getOrInsertComputed: function(e, t) {
453
+ return this.has(e) ? this.get(e) : this.$set1(e, t(e));
454
+ },
455
+ $get: function(e, t = null) {
456
+ return this.has(e) ? this.get(e) : this.$set1(e, typeof t == "function" ? t(e) : t);
457
+ },
458
+ $get$async: async function(e, t = null) {
459
+ return this.has(e) ? this.get(e) : this.$set1(e, typeof t == "function" ? await t(e) : t);
460
+ },
461
+ toObject: function() {
462
+ return Object.fromEntries(this);
463
+ },
464
+ toArray: function() {
465
+ return [...this];
466
+ },
467
+ toJSON: function() {
468
+ return [...this];
469
+ }
470
+ }), Map.prototype.getOrInsert === void 0 && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed), e(Set, { ...t() }), e(Set.prototype, {
471
+ ...n(["size", "$length"]),
472
+ ...i(Set.prototype, "entries", "keys", "values"),
473
+ ...r(Set.prototype, null, "t", ["add", "$add"], ["delete", "$delete"]),
474
+ ...r(Set.prototype, null, "a", "add", "delete"),
475
+ ...r(Set.prototype, null, 0, "add", "delete"),
476
+ $union: function(e) {
477
+ return new Set([...this, ...e]);
478
+ },
479
+ $intersection: function(e) {
480
+ return new Set([...this].filter((t) => e.has(t)));
481
+ },
482
+ $difference: function(e) {
483
+ return new Set([...this].filter((t) => !e.has(t)));
484
+ },
485
+ $symmetricDifference: function(e) {
486
+ return new Set([...[...this].filter((t) => !e.has(t)), ...[...e].filter((e) => !this.has(e))]);
487
+ },
488
+ toArray: function() {
489
+ return [...this];
490
+ },
491
+ toJSON: function() {
492
+ return [...this];
493
+ }
494
+ }), Set.prototype.union === void 0 && (Set.prototype.union = Set.prototype.$union, Set.prototype.intersection = Set.prototype.$intersection, Set.prototype.difference = Set.prototype.$difference, Set.prototype.symmetricDifference = Set.prototype.$symmetricDifference), e(Date, {
495
+ new: function(...e) {
496
+ return e.length == 1 ? Number.isNaN(+e[0]) ? new Date(e[0].includes("T") ? e[0] : e[0].replace(/-/g, "/")) : new Date(e[0] > 25e8 ? e[0] : e[0] * 1e3) : new Date(...e);
497
+ },
498
+ format: function(e = "y-m-d h:i:s") {
499
+ return (/* @__PURE__ */ new Date()).format(e);
500
+ },
501
+ unix: function() {
502
+ return this.now() / 1e3 | 0;
503
+ },
504
+ fromUnix: function(e) {
505
+ return /* @__PURE__ */ new Date((e ?? 0) * 1e3);
506
+ },
507
+ expr: function(e = {}) {
508
+ return (/* @__PURE__ */ new Date()).expr(e);
509
+ },
510
+ toDayRange: function() {
511
+ let e = /* @__PURE__ */ new Date(), t = e.getFullYear(), n = e.getMonth(), r = e.getDate(), i = new Date(t, n, r).getTime() / 1e3 | 0;
512
+ return [i, i + 86400 - 1];
513
+ },
514
+ toWeekRange: function() {
515
+ let e = /* @__PURE__ */ new Date();
516
+ for (; e.getDay() != 1;) e = /* @__PURE__ */ new Date(e.getTime() - 86400);
517
+ let t = e.getFullYear(), n = e.getMonth(), r = e.getDate(), i = new Date(t, n, r).getTime() / 1e3 | 0;
518
+ return [i, i + 86400 * 7 - 1];
519
+ },
520
+ toMonthRange: function() {
521
+ let e = /* @__PURE__ */ new Date(), t = e.getFullYear(), n = e.getMonth();
522
+ return [new Date(t, n, 1).getTime() / 1e3 | 0, new Date(t, n + 1, 0, 23, 59, 59).getTime() / 1e3 | 0];
523
+ },
524
+ toYearRange: function() {
525
+ let e = (/* @__PURE__ */ new Date()).getFullYear();
526
+ return [new Date(e, 1, 1).getTime() / 1e3 | 0, new Date(e + 1, 1, 0, 23, 59, 59).getTime() / 1e3 | 0];
527
+ }
528
+ }), e(Date.prototype, {
529
+ format: function(e = "y-m-d h:i:s") {
530
+ if (this.getTime() === 0) return "-";
531
+ let t = {
532
+ y: this.getFullYear(),
533
+ m: this.getMonth() + 1,
534
+ d: this.getDate(),
535
+ h: this.getHours(),
536
+ i: this.getMinutes(),
537
+ s: this.getSeconds(),
538
+ l: this.getMilliseconds(),
539
+ e: this.getMonthDay()
540
+ };
541
+ return e.replace(/([ymdhisle])/gi, (e, n) => n >= "A" && n <= "Z" ? t[n.toLowerCase()] : t[n].toString().padStart(n === "l" ? 3 : 2, "0"));
542
+ },
543
+ unix: function() {
544
+ return this.getTime() / 1e3 | 0;
545
+ },
546
+ isLeapYear: function() {
547
+ return this.getFullYear() % 4 == 0 && this.getFullYear() % 400 != 0;
548
+ },
549
+ getMonthDay: function() {
550
+ return [
551
+ 31,
552
+ 0,
553
+ 31,
554
+ 30,
555
+ 31,
556
+ 30,
557
+ 31,
558
+ 31,
559
+ 30,
560
+ 31,
561
+ 30,
562
+ 31
563
+ ][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
564
+ },
565
+ expr: function({ y: e = 0, m: t = 0, d: n = 0, h: r = 0, i = 0, s: a = 0 }) {
566
+ let o = new Date(this.getFullYear() + e, this.getMonth() + t + 1, 0);
567
+ return new Date(this.getFullYear() + e, this.getMonth() + t, Math.min(o.getDate(), this.getDate()) + n, this.getHours() + r, this.getMinutes() + i, this.getSeconds() + a);
568
+ },
569
+ begin: function(e = 3) {
570
+ return new Date(...[
571
+ this.getFullYear(),
572
+ this.getMonth(),
573
+ this.getDate(),
574
+ this.getHours(),
575
+ this.getMinutes(),
576
+ this.getSeconds()
577
+ ].slice(0, e), ...[
578
+ this.getFullYear(),
579
+ 0,
580
+ 1,
581
+ 0,
582
+ 0,
583
+ 0
584
+ ].slice(e));
585
+ },
586
+ end: function(e = 3) {
587
+ return new Date(...[
588
+ this.getFullYear(),
589
+ this.getMonth(),
590
+ this.getDate(),
591
+ this.getHours(),
592
+ this.getMinutes(),
593
+ this.getSeconds()
594
+ ].slice(0, e), ...[
595
+ this.getFullYear(),
596
+ 11,
597
+ e < 2 ? 31 : this.getMonthDay(),
598
+ 23,
599
+ 59,
600
+ 59
601
+ ].slice(e));
602
+ },
603
+ week: function(e, t = 1) {
604
+ let n = new Date(this.getTime());
605
+ for (; n.getDay() !== e;) n = new Date(n.getTime() + 864e5 * t);
606
+ return n;
607
+ },
608
+ toJSON: function() {
609
+ return this.getTime();
610
+ }
611
+ }), e(RegExp, { ...t() }), e(RegExp.prototype, { toJSON: function() {
612
+ return this.toString();
613
+ } }), e(Promise, {
614
+ ...t(),
615
+ $channel: function() {
616
+ let e = null, t = null;
617
+ return [
618
+ new this((n, r) => {
619
+ e = n, t = r;
620
+ }),
621
+ e,
622
+ t
623
+ ];
624
+ },
625
+ $withResolvers: function() {
626
+ let e = null, t = null;
627
+ return {
628
+ promise: new this((n, r) => {
629
+ e = n, t = r;
630
+ }),
631
+ resolve: e,
632
+ reject: t
633
+ };
634
+ }
635
+ }), e(Promise.prototype, { tryCatch: function() {
636
+ return new Promise((e) => this.then((t) => e([t, null])).catch((t) => e([null, t])));
637
+ } }), Promise.withResolvers === void 0 && (Promise.withResolvers = Promise.$withResolvers), e(JSON, { $parse: function(e, t = null) {
638
+ try {
639
+ if (typeof e != "string") throw Error("not string");
640
+ return JSON.parse(e);
641
+ } catch {
642
+ return t;
643
+ }
644
+ } }), typeof Iterator < "u" && e(Iterator.prototype, { toArray: function() {
645
+ return [...this];
646
+ } }), e(ArrayBuffer.prototype, { toUint8Array: function() {
647
+ return new Uint8Array(this);
648
+ } }), e(Uint8Array, {
649
+ ...t(),
650
+ fromString: function(e) {
651
+ return new TextEncoder().encode(e);
652
+ },
653
+ $fromHex: function(e) {
654
+ let t = [];
655
+ for (let n = 0; n < e.length; n += 2) t.push(Number.parseInt(e.substring(n, n + 2), 16));
656
+ return new Uint8Array(t);
657
+ },
658
+ $fromBase64: function(e) {
659
+ let t = [], n = {};
660
+ for (let e = 0; e < 64; e++) n["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)] = e;
661
+ let r = e.charAt(e.length - 1) == "=" ? e.charAt(e.length - 2) == "=" ? e.length - 2 : e.length - 1 : e.length;
662
+ for (let i = 3; i < r; i += 4) {
663
+ let r = (n[e.charAt(i - 3)] << 18) + (n[e.charAt(i - 2)] << 12) + (n[e.charAt(i - 1)] << 6) + n[e.charAt(i)];
664
+ t.push((r & 16711680) >> 16, (r & 65280) >> 8, r & 255);
665
+ }
666
+ if (r % 4 == 3) {
667
+ let i = (n[e.charAt(r - 3)] << 18) + (n[e.charAt(r - 2)] << 12) + (n[e.charAt(r - 1)] << 6);
668
+ t.push((i & 16711680) >> 16, (i & 65280) >> 8);
669
+ } else if (r % 4 == 2) {
670
+ let i = (n[e.charAt(r - 2)] << 18) + (n[e.charAt(r - 1)] << 12);
671
+ t.push((i & 16711680) >> 16);
672
+ }
673
+ return new Uint8Array(t);
674
+ }
675
+ }), e(Uint8Array.prototype, {
676
+ setFromString(e, t = 0) {
677
+ let n = Uint8Array.fromString(e);
678
+ return this.set(n, t), {
679
+ read: n.length,
680
+ written: n.length
681
+ };
682
+ },
683
+ $setFromHex(e, t = 0) {
684
+ let n = Uint8Array.fromHex(e);
685
+ return this.set(n, t), {
686
+ read: n.length,
687
+ written: n.length
688
+ };
689
+ },
690
+ $setFromBase64(e, t = 0) {
691
+ let n = Uint8Array.fromBase64(e);
692
+ return this.set(n, t), {
693
+ read: n.length,
694
+ written: n.length
695
+ };
696
+ },
697
+ toString: function() {
698
+ return new TextDecoder().decode(this);
699
+ },
700
+ $toHex: function() {
701
+ let e = "";
702
+ for (let t = 0; t < this.length; t++) e += (this[t] < 16 ? "0" : "") + this[t].toString(16);
703
+ return e;
704
+ },
705
+ $toBase64: function() {
706
+ let e = "", t = {}, n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
707
+ for (let e = 0; e < 64; e++) t[n.charAt(e)] = e;
708
+ for (let t = 2; t < this.length; t += 3) {
709
+ let r = (this[t - 2] << 16) + (this[t - 1] << 8) + this[t];
710
+ e += n.charAt((r & 16515072) >> 18) + n.charAt((r & 258048) >> 12) + n.charAt((r & 4032) >> 6) + n.charAt(r & 63);
711
+ }
712
+ if (this.length % 3 == 2) {
713
+ let t = (this[this.length - 2] << 16) + (this[this.length - 1] << 8);
714
+ e += n.charAt((t & 16515072) >> 18) + n.charAt((t & 258048) >> 12) + n.charAt((t & 4032) >> 6) + "=";
715
+ } else if (this.length % 3 == 1) {
716
+ let t = this[this.length - 1] << 16;
717
+ e += n.charAt((t & 16515072) >> 18) + n.charAt((t & 258048) >> 12) + "==";
718
+ }
719
+ return e;
720
+ },
721
+ toArray: function() {
722
+ return new Array(...this);
723
+ }
724
+ }), Uint8Array.fromBase64 === void 0 && (Uint8Array.fromHex = Uint8Array.$fromHex, Uint8Array.fromBase64 = Uint8Array.$fromBase64), Uint8Array.prototype.setFromHex === void 0 && (Uint8Array.prototype.setFromHex = Uint8Array.prototype.$setFromHex, Uint8Array.prototype.setFromBase64 = Uint8Array.prototype.$setFromBase64, Uint8Array.prototype.toHex = Uint8Array.prototype.$toHex, Uint8Array.prototype.toBase64 = Uint8Array.prototype.$toBase64);
725
+ //#endregion
726
+ //#region lib/Math.js
727
+ var c = 0, l = 0, u = 0;
728
+ e(Math, {
729
+ randstr: function(e = 16, t = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
730
+ if (e < t) throw Error("randstr: len < slen");
731
+ let i = [];
732
+ for (let t = 0; t < e; t++) i.push(n.charAt(Math.random() * n.length | 0));
733
+ for (let n = /* @__PURE__ */ new Set(), a = 0, o = 0; o < t; o++) {
734
+ do
735
+ a = Math.random() * e | 0;
736
+ while (n.has(a));
737
+ n.set(a, !0), i[a] = r.charAt(Math.random() * r.length | 0);
738
+ }
739
+ return i.join("");
740
+ },
741
+ randint: function(e = 0, t = 2 ** 53 - 1) {
742
+ return Math.floor(Math.random() * (t - e) + e);
743
+ },
744
+ incrid: function() {
745
+ return ++c;
746
+ },
747
+ incrstr: function() {
748
+ return "" + Math.incrid();
749
+ },
750
+ uniqid: function(e = Date.now()) {
751
+ return e === u ? e * 2048 + ++l % 2048 : (u = e) * 2048 + (l = 0) % 2048;
752
+ },
753
+ uniqstr: function() {
754
+ return "" + Math.uniqid();
755
+ },
756
+ sleep: function(e) {
757
+ return new Promise((t) => setTimeout(t, e));
758
+ },
759
+ useTemplate: function(e) {
760
+ let t = null, n = {
761
+ setup(e, { slots: n }) {
762
+ return t = n.default, () => {};
763
+ },
764
+ name: e + "Template"
765
+ }, r = {
766
+ setup(e, { attrs: n }) {
767
+ return () => t?.(n);
768
+ },
769
+ name: e
770
+ };
771
+ return {
772
+ [n.name]: n,
773
+ [r.name]: r
774
+ };
775
+ }
92
776
  });
93
- h(Object.prototype, {
94
- $clone: function() {
95
- return JSON.parse(JSON.stringify(this));
96
- },
97
- $length: function() {
98
- return Object.keys(this).length;
99
- },
100
- ...f(Object, 0, "", "entries", "keys", "values", "assign"),
101
- ...f(JSON, 0, "", "stringify"),
102
- $merge: function(...t) {
103
- return S(this, ...t);
104
- },
105
- $concat: function(...t) {
106
- return x(this, ...t);
107
- },
108
- $empty: function() {
109
- return Object.keys(this).length == 0;
110
- },
111
- $has: function(t) {
112
- return t in this;
113
- },
114
- $pick: function(...t) {
115
- const e = {};
116
- for (const n of t)
117
- e[n] = this[n];
118
- return e;
119
- },
120
- $omit: function(...t) {
121
- const e = {}, n = new Set(t);
122
- for (const r in this)
123
- n.has(r) || (e[r] = this[r]);
124
- return e;
125
- },
126
- $attr: function(...t) {
127
- if (typeof this != "object")
128
- return this;
129
- const [e, n, r, i] = t;
130
- return t.length == 1 ? this[e] : t.length == 2 ? (this[e] = n, this) : typeof r == "boolean" ? (e in this === r && (this[e] = n), this) : r == "define" || r === null ? Object.defineProperty(this, e, { value: n, enumerable: !1, configurable: !0, writable: !0, ...i }) : r === "+" ? (this[e] = (this[e] ?? i ?? 0) + n, this) : r === "-" ? (this[e] = (this[e] ?? i ?? 0) - n, this) : r === "*" ? (this[e] = (this[e] ?? i ?? 0) * n, this) : r === "/" ? (this[e] = (this[e] ?? i ?? 0) / n, this) : this;
131
- },
132
- $pipe: function(t, ...e) {
133
- return t(this, ...e);
134
- },
135
- $tee: function(t, ...e) {
136
- return t(this, ...e), this;
137
- },
138
- $toArray: function() {
139
- return Array.isArray(this) ? this : [this];
140
- },
141
- ...f(console, -1, "t", ["debug", "$debug"], ["log", "$log"], ["info", "$info"], ["warn", "$warn"], ["error", "$error"], ["dir", "$dir"]),
142
- $debugger: function(...t) {
143
- console.debug(this, ...t);
144
- debugger;
145
- return this;
146
- },
147
- // ====== Tree ======
148
- $getParents: function(t = !1, e = -1, n = "parent") {
149
- const r = t ? [this] : [];
150
- let i = this[n];
151
- for (; i && e-- != 0; )
152
- r.push(i), i = i[n];
153
- return r;
154
- },
155
- $getChildrens: function(t = !1, e = -1, n = "children") {
156
- const r = [], i = (s, o, u) => {
157
- if (o && r.push(s), !(u == 0 || !s[n] || s[n].length == 0))
158
- for (const c of s[n])
159
- i(c, !0, u - 1);
160
- };
161
- return i(this, t, e), r;
162
- },
163
- $tree$find: function(t, e = !0, n = -1, r = "children") {
164
- if (e && t(this))
165
- return this;
166
- if (n == 0 || !this[r] || this[r].length == 0)
167
- return null;
168
- for (const i of this[r]) {
169
- const s = i.$tree$find(t, !0, n - 1, r);
170
- if (s !== null)
171
- return s;
172
- }
173
- return null;
174
- },
175
- $tree$each: function(t, e = !0, n = -1, r = "children") {
176
- if (e && t(this), !(n == 0 || !this[r] || this[r].length == 0)) {
177
- for (const i of this[r])
178
- i.$tree$each(t, !0, n - 1, r);
179
- return this;
180
- }
181
- },
182
- $tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
183
- const s = e ? t(this) : this, o = [];
184
- if (n == 0 || !this[r] || this[r].length == 0)
185
- return s;
186
- for (const u of this[r])
187
- o.push(u.$tree$map(t, !0, n - 1, r, i));
188
- return s[r] = o, s;
189
- }
190
- });
191
- h(Number.prototype, {
192
- ...f(Math, 0, "", ["ceil", "ceil"], ["floor", "floor"], ["trunc", "trunc"], ["abs", "abs"], ["max", "max"], ["min", "min"]),
193
- fixed: function(t = 0) {
194
- return +this.toFixed(t);
195
- },
196
- round: function(t = 0) {
197
- return Math.round(this * 10 ** t) / 10 ** t;
198
- },
199
- add: function(t, ...e) {
200
- return typeof t == "function" ? t(this, ...e) : this + t;
201
- },
202
- sub: function(t, ...e) {
203
- return typeof t == "function" ? t(this, ...e) : this - t;
204
- },
205
- mul: function(t, ...e) {
206
- return typeof t == "function" ? t(this, ...e) : this * t;
207
- },
208
- div: function(t, ...e) {
209
- return typeof t == "function" ? t(this, ...e) : this / t;
210
- },
211
- baseConvert: function(t = 64) {
212
- let e = "", n = this, r = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
213
- for (; n > 0; )
214
- e = r.at(n % t) + e, n = Math.floor(n / t);
215
- return e || "0";
216
- },
217
- unit: function(t, e = 0) {
218
- let n = this, r = "";
219
- for (const [i, s] of Object.entries(t)) {
220
- if (r = i, s === 0 || n < s)
221
- break;
222
- n = n / s;
223
- }
224
- return e < 0 ? +n.toFixed(0 - e) + r : n.toFixed(e) + r;
225
- },
226
- units: function(t, e = !1) {
227
- let n = this, r = [];
228
- for ([unit, size] of Object.entries(t))
229
- if (size == 0 || n < size) {
230
- r.push([n, unit]);
231
- break;
232
- } else
233
- r.push([n % size, unit]), n = Math.floor(n / size);
234
- return e ? r : r.reverse().map(([i, s]) => i + s).join("");
235
- },
236
- toDate: function() {
237
- return Date.new(this);
238
- }
239
- });
240
- h(BigInt.prototype, {
241
- toJSON: function() {
242
- return this >= BigInt(Number.MIN_SAFE_INTEGER) && this <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(this) : this.toString();
243
- }
244
- });
245
- h(String, {
246
- ...g()
247
- });
248
- h(String.prototype, {
249
- ...m(["length", "length$"]),
250
- $substring: function(t = 0, e = this.length) {
251
- return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
252
- },
253
- $substr: function(t = 0, e = this.length) {
254
- return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
255
- },
256
- $split: function(t = ",", e = -1) {
257
- const n = this ? this.split(t) : [];
258
- return e === -1 ? n : n.$push(n.splice(e - 1).join(t));
259
- },
260
- $split$number: function(t = ",") {
261
- return this.$split(t).map((e) => +e);
262
- },
263
- $split$segment: function(t = 1) {
264
- const e = [];
265
- for (let n = 0; n < this.length; n += t)
266
- e.push(this.substring(n, n + t));
267
- return e;
268
- },
269
- sprintf: function(...t) {
270
- let [e, ...n] = this.split(/%[sd]/);
271
- for (let r = 0; r < n.length; r++)
272
- e += t[r] + n[r];
273
- return e;
274
- },
275
- subOf: function(t, e, n = 0, r = 0) {
276
- for (let o = 0; o < n && r != -1; o++, r++)
277
- r = this.indexOf(t, r);
278
- let i = this.indexOf(t, r), s = this.indexOf(e, i);
279
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
280
- },
281
- lastSubOf: function(t, e, n = 0, r = 1 / 0) {
282
- for (let o = 0; o < n && r != -1; o++, r--)
283
- r = this.lastIndexOf(t, r);
284
- let i = this.lastIndexOf(t, r), s = this.indexOf(e, i);
285
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
286
- },
287
- camel2under: function() {
288
- return this.substr(0, 1) + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
289
- },
290
- under2camel: function() {
291
- return this.replace(/_([a-z])/g, (t, e) => e.toUpperCase());
292
- },
293
- camel2pascal: function() {
294
- return this.substr(0, 1).toUpperCase() + this.substr(1);
295
- },
296
- pascal2camel: function() {
297
- return this.substr(0, 1).toLowerCase() + this.substr(1);
298
- },
299
- under2kebab: function() {
300
- return this.replace(/_/g, "-");
301
- },
302
- kebab2under: function() {
303
- return this.replace(/-/g, "_");
304
- },
305
- baseConvert: function(t = 64) {
306
- let e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
307
- for (let r = 0; r < this.length; r++)
308
- e = e * t + n.indexOf(this.at(r));
309
- return e;
310
- },
311
- fixed: function(...t) {
312
- return +(+this).toFixed(...t);
313
- },
314
- toDate: function() {
315
- return Date.new(this);
316
- },
317
- // ====== Uint8Array ======
318
- toUint8Array: function() {
319
- return new TextEncoder().encode(this);
320
- },
321
- // ====== hex ======
322
- hexencode: function() {
323
- return new TextEncoder().encode(this).toHex();
324
- },
325
- hexdecode: function() {
326
- return new TextDecoder().decode(Uint8Array.fromHex(this));
327
- },
328
- // ====== base64 ======
329
- base64encode: function() {
330
- return new TextEncoder().encode(this).toBase64();
331
- },
332
- base64decode: function() {
333
- return new TextDecoder().decode(Uint8Array.fromBase64(this));
334
- }
335
- });
336
- h(Array, {
337
- ...g(),
338
- // ====== from pinojs ======
339
- range: function(...t) {
340
- let e = [], n = 0, r = 0, i = 1, s = typeof t[t.length - 1] == "boolean" ? t.pop() : !0, o = typeof t[t.length - 1] == "function" ? t.pop() : (u, c, a) => u;
341
- switch (t.length) {
342
- case 1:
343
- [r] = t;
344
- break;
345
- case 2:
346
- [n, r] = t;
347
- break;
348
- case 3:
349
- [n, r, i] = t;
350
- break;
351
- default:
352
- throw new Error("the number of parameters is incorrect!");
353
- }
354
- if (i == 0)
355
- throw new Error("step cannot be 0!");
356
- for (let u = 0, c = 0, a = Math.abs(r - n), p = Math.abs(i), d = n <= r ? 1 : -1; c < a; c += p)
357
- e.push(s ? o(n + c * d, u++, e) : o());
358
- return e;
359
- }
360
- });
361
- h(Array.prototype, {
362
- ...m("length"),
363
- ...$(Array.prototype, "entries", "keys", "values"),
364
- ...f(Array.prototype, null, "", "map"),
365
- ...f(Array.prototype, null, "t", ["push", "$push"], ["pop", "$pop"], ["shift", "$shift"], ["unshift", "$unshift"], ["splice", "$splice"]),
366
- ...f(Array.prototype, null, "a", "push", "unshift"),
367
- ...f(Array.prototype, null, 0, "push", "unshift"),
368
- $empty: function() {
369
- return this.length == 0;
370
- },
371
- first: function(t = null) {
372
- return this.length ? this[0] : t;
373
- },
374
- last: function(t = null) {
375
- return this.length ? this[this.length - 1] : t;
376
- },
377
- $find: function(t, e = null) {
378
- return this.find(t) ?? e;
379
- },
380
- equals: function(t) {
381
- return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
382
- },
383
- unique: function(t = (e) => e) {
384
- const e = /* @__PURE__ */ new Set();
385
- return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
386
- },
387
- ...f(Array.prototype, null, "t", ["forEach", "each"]),
388
- each$async: async function(t) {
389
- for (let e = 0; e < this.length; e++)
390
- await t(this[e], e, this);
391
- return this;
392
- },
393
- map$async: async function(t) {
394
- const e = [];
395
- for (let n = 0; n < this.length; n++)
396
- e.push(await t(this[n], n, this));
397
- return e;
398
- },
399
- shuffle: function(t = !1) {
400
- let e = this.length;
401
- for (; e; ) {
402
- const n = Math.random() * e-- | 0;
403
- [this[n], this[e]] = [this[e], this[n]];
404
- }
405
- return this;
406
- },
407
- // ====== collection ======
408
- union: function(t) {
409
- return Set.new(this).union(Set.new(t)).toArray();
410
- },
411
- intersection: function(t) {
412
- return Set.new(this).intersection(Set.new(t)).toArray();
413
- },
414
- difference: function(t) {
415
- return Set.new(this).difference(Set.new(t)).toArray();
416
- },
417
- symmetricDifference: function(t) {
418
- return Set.new(this).symmetricDifference(Set.new(t)).toArray();
419
- },
420
- // ====== convert ======
421
- toMap: function(t = (e, n) => [n, e]) {
422
- return new Map(this.map(t));
423
- },
424
- toSet: function(t = (e) => e) {
425
- return new Set(this.map(t));
426
- },
427
- // ====== Uint8Array ======
428
- toUint8Array: function() {
429
- return new Uint8Array(this);
430
- },
431
- toBase64: function() {
432
- return this.toUint8Array().toBase64();
433
- },
434
- toHex: function() {
435
- return this.toUint8Array().toHex();
436
- },
437
- // ====== TextDecoder ======
438
- decode: function() {
439
- return this.toUint8Array().toString();
440
- },
441
- // ====== Relational ======
442
- assoc: function(t, e, n = {}) {
443
- const r = this.unique$((s) => s[t]), i = r.length == 0 ? {} : typeof n == "function" ? n(r) : n;
444
- return this.each$((s) => s[e] = i[s[t]] ?? null);
445
- },
446
- // ====== Tree ======
447
- toTree: function(t = {}) {
448
- const { id: e = "id", pid: n = "pid", level: r = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: u = null, hasRoot: c = !0 } = t, a = this.reduce((l, y) => l.$attr(y[e], y), {}), p = this.reduce((l, y) => (l.$attr(y[n], [], !1).$attr(y[n]).$push(y), l), {}), d = this.length && c ? this.find((l) => l[n] === 0) : { [e]: 0, [n]: -1, [i]: null, [s]: null, [o]: p[0] };
449
- h(d, { [i]: d });
450
- for (const l of this)
451
- h(l, { [i]: d, [s]: a[l[n]] }), l[o] = p[l[e]] || u;
452
- return d.$tree$each((l) => l[r] = l[s] ? l[s][r] + 1 : 0, -1, o), d;
453
- },
454
- $tree2tree: function(t = {}, e = null, n = null) {
455
- const { id: r = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: u = "parent", children: c = "children", empty: a = null } = t;
456
- e = e || { [r]: 0, [i]: -1, [s]: 0, [o]: null, [u]: null, [c]: this }, n = n || e;
457
- for (const p of this)
458
- h(p, { [o]: e, [u]: n }), p[i] = n[r], p[s] = n[s] + 1, p[c] = p[c] && p[c].length ? p[c] : a, p[c]?.$tree2tree(t, e, p);
459
- return e;
460
- },
461
- $tree$find: function(t, e = !0, n = -1, r = "children") {
462
- for (const i of this) {
463
- const s = i.$tree$find(t, e, n, r);
464
- if (s !== null)
465
- return s;
466
- }
467
- return null;
468
- },
469
- $tree$each: function(t, e = !0, n = -1, r = "children") {
470
- for (const i of this)
471
- i.$tree$each(t, e, n, r);
472
- return this;
473
- },
474
- $tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
475
- return this.map((s) => s.$tree$map(t, e, n, r, i));
476
- }
477
- });
478
- h(Map, {
479
- ...g()
480
- });
481
- h(Map.prototype, {
482
- ...m(["size", "$length"]),
483
- ...$(Map.prototype, "entries", "keys", "values"),
484
- ...f(Map.prototype, null, "t", ["set", "$set"], ["delete", "$delete"]),
485
- ...f(Map.prototype, null, "a", "set", "delete"),
486
- ...f(Map.prototype, null, 0, "set", "delete"),
487
- ...f(Map.prototype, null, 1, "set", "delete"),
488
- $getOrInsert: function(t, e = null) {
489
- return this.has(t) ? this.get(t) : this.$set1(t, e);
490
- },
491
- $getOrInsertComputed: function(t, e) {
492
- return this.has(t) ? this.get(t) : this.$set1(t, e(t));
493
- },
494
- $get: function(t, e = null) {
495
- return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? e(t) : e);
496
- },
497
- $get$async: async function(t, e = null) {
498
- return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? await e(t) : e);
499
- },
500
- toObject: function() {
501
- return Object.fromEntries(this);
502
- },
503
- toArray: function() {
504
- return [...this];
505
- },
506
- toJSON: function() {
507
- return [...this];
508
- }
509
- });
510
- typeof Map.prototype.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed);
511
- h(Set, {
512
- ...g()
513
- });
514
- h(Set.prototype, {
515
- ...m(["size", "$length"]),
516
- ...$(Set.prototype, "entries", "keys", "values"),
517
- ...f(Set.prototype, null, "t", ["add", "$add"], ["delete", "$delete"]),
518
- ...f(Set.prototype, null, "a", "add", "delete"),
519
- ...f(Set.prototype, null, 0, "add", "delete"),
520
- $union: function(t) {
521
- return /* @__PURE__ */ new Set([...this, ...t]);
522
- },
523
- $intersection: function(t) {
524
- return new Set([...this].filter((e) => t.has(e)));
525
- },
526
- $difference: function(t) {
527
- return new Set([...this].filter((e) => !t.has(e)));
528
- },
529
- $symmetricDifference: function(t) {
530
- return /* @__PURE__ */ new Set([...[...this].filter((e) => !t.has(e)), ...[...t].filter((e) => !this.has(e))]);
531
- },
532
- toArray: function() {
533
- return [...this];
534
- },
535
- toJSON: function() {
536
- return [...this];
537
- }
538
- });
539
- typeof Set.prototype.union > "u" && (Set.prototype.union = Set.prototype.$union, Set.prototype.intersection = Set.prototype.$intersection, Set.prototype.difference = Set.prototype.$difference, Set.prototype.symmetricDifference = Set.prototype.$symmetricDifference);
540
- h(Date, {
541
- new: function(...t) {
542
- return t.length != 1 ? new Date(...t) : Number.isNaN(+t[0]) ? new Date(t[0].includes("T") ? t[0] : t[0].replace(/-/g, "/")) : new Date(t[0] > 25e8 ? t[0] : t[0] * 1e3);
543
- },
544
- format: function(t = "y-m-d h:i:s") {
545
- return (/* @__PURE__ */ new Date()).format(t);
546
- },
547
- unix: function() {
548
- return this.now() / 1e3 | 0;
549
- },
550
- fromUnix: function(t) {
551
- return new Date((t ?? 0) * 1e3);
552
- },
553
- expr: function(t = {}) {
554
- return (/* @__PURE__ */ new Date()).expr(t);
555
- },
556
- toDayRange: function() {
557
- const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), r = t.getDate(), i = new Date(e, n, r).getTime() / 1e3 | 0;
558
- return [i, i + 86400 - 1];
559
- },
560
- toWeekRange: function() {
561
- let t = /* @__PURE__ */ new Date();
562
- for (; t.getDay() != 1; )
563
- t = new Date(t.getTime() - 86400);
564
- const e = t.getFullYear(), n = t.getMonth(), r = t.getDate(), i = new Date(e, n, r).getTime() / 1e3 | 0;
565
- return [i, i + 86400 * 7 - 1];
566
- },
567
- toMonthRange: function() {
568
- const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), r = new Date(e, n, 1).getTime() / 1e3 | 0, i = new Date(e, n + 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
569
- return [r, i];
570
- },
571
- toYearRange: function() {
572
- const e = (/* @__PURE__ */ new Date()).getFullYear(), n = new Date(e, 1, 1).getTime() / 1e3 | 0, r = new Date(e + 1, 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
573
- return [n, r];
574
- }
575
- });
576
- h(Date.prototype, {
577
- format: function(t = "y-m-d h:i:s") {
578
- if (this.getTime() === 0)
579
- return "-";
580
- const e = {
581
- y: this.getFullYear(),
582
- m: this.getMonth() + 1,
583
- d: this.getDate(),
584
- h: this.getHours(),
585
- i: this.getMinutes(),
586
- s: this.getSeconds(),
587
- l: this.getMilliseconds(),
588
- e: this.getMonthDay()
589
- };
590
- return t.replace(/([ymdhisle])/ig, (n, r) => r >= "A" && r <= "Z" ? e[r.toLowerCase()] : e[r].toString().padStart(r === "l" ? 3 : 2, "0"));
591
- },
592
- unix: function() {
593
- return this.getTime() / 1e3 | 0;
594
- },
595
- isLeapYear: function() {
596
- return this.getFullYear() % 4 === 0 && this.getFullYear() % 400 !== 0;
597
- },
598
- getMonthDay: function() {
599
- return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
600
- },
601
- expr: function({ y: t = 0, m: e = 0, d: n = 0, h: r = 0, i = 0, s = 0 }) {
602
- const o = new Date(this.getFullYear() + t, this.getMonth() + e + 1, 0);
603
- return new Date(this.getFullYear() + t, this.getMonth() + e, Math.min(o.getDate(), this.getDate()) + n, this.getHours() + r, this.getMinutes() + i, this.getSeconds() + s);
604
- },
605
- begin: function(t = 3) {
606
- return new Date(...[this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()].slice(0, t), ...[this.getFullYear(), 0, 1, 0, 0, 0].slice(t));
607
- },
608
- end: function(t = 3) {
609
- return new Date(...[this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()].slice(0, t), ...[this.getFullYear(), 11, t < 2 ? 31 : this.getMonthDay(), 23, 59, 59].slice(t));
610
- },
611
- week: function(t, e = 1) {
612
- let n = new Date(this.getTime());
613
- for (; n.getDay() !== t; )
614
- n = new Date(n.getTime() + 864e5 * e);
615
- return n;
616
- },
617
- toJSON: function() {
618
- return this.getTime();
619
- }
620
- });
621
- h(RegExp, {
622
- ...g()
623
- });
624
- h(RegExp.prototype, {
625
- toJSON: function() {
626
- return this.toString();
627
- }
628
- });
629
- h(Promise, {
630
- ...g(),
631
- $channel: function() {
632
- let t = null, e = null;
633
- return [new this((r, i) => {
634
- t = r, e = i;
635
- }), t, e];
636
- },
637
- $withResolvers: function() {
638
- let t = null, e = null;
639
- return { promise: new this((r, i) => {
640
- t = r, e = i;
641
- }), resolve: t, reject: e };
642
- }
643
- });
644
- h(Promise.prototype, {
645
- tryCatch: function() {
646
- return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
647
- }
648
- });
649
- typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise.$withResolvers);
650
- h(JSON, {
651
- $parse: function(t, e = null) {
652
- try {
653
- if (typeof t != "string")
654
- throw new Error("not string");
655
- return JSON.parse(t);
656
- } catch {
657
- return e;
658
- }
659
- }
660
- });
661
- typeof Iterator < "u" && h(Iterator.prototype, {
662
- toArray: function() {
663
- return [...this];
664
- }
665
- });
666
- h(ArrayBuffer.prototype, {
667
- toUint8Array: function() {
668
- return new Uint8Array(this);
669
- }
670
- });
671
- h(Uint8Array, {
672
- ...g(),
673
- fromString: function(t) {
674
- return new TextEncoder().encode(t);
675
- },
676
- $fromHex: function(t) {
677
- const e = [];
678
- for (let n = 0; n < t.length; n += 2)
679
- e.push(Number.parseInt(t.substring(n, n + 2), 16));
680
- return new Uint8Array(e);
681
- },
682
- $fromBase64: function(t) {
683
- const e = [], n = {}, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
684
- for (let s = 0; s < r.length; s++)
685
- n[r.charAt(s)] = s;
686
- const i = t.charAt(t.length - 1) != "=" ? t.length : t.charAt(t.length - 2) != "=" ? t.length - 1 : t.length - 2;
687
- for (let s = 3; s < i; s += 4) {
688
- const o = (n[t.charAt(s - 3)] << 18) + (n[t.charAt(s - 2)] << 12) + (n[t.charAt(s - 1)] << 6) + n[t.charAt(s)];
689
- e.push((o & 16711680) >> 16, (o & 65280) >> 8, o & 255);
690
- }
691
- if (i % 4 == 3) {
692
- const s = (n[t.charAt(i - 3)] << 18) + (n[t.charAt(i - 2)] << 12) + (n[t.charAt(i - 1)] << 6);
693
- e.push((s & 16711680) >> 16, (s & 65280) >> 8);
694
- } else if (i % 4 == 2) {
695
- const s = (n[t.charAt(i - 2)] << 18) + (n[t.charAt(i - 1)] << 12);
696
- e.push((s & 16711680) >> 16);
697
- }
698
- return new Uint8Array(e);
699
- }
700
- });
701
- h(Uint8Array.prototype, {
702
- setFromString(t, e = 0) {
703
- const n = Uint8Array.fromString(t);
704
- return this.set(n, e), { read: n.length, written: n.length };
705
- },
706
- $setFromHex(t, e = 0) {
707
- const n = Uint8Array.fromHex(t);
708
- return this.set(n, e), { read: n.length, written: n.length };
709
- },
710
- $setFromBase64(t, e = 0) {
711
- const n = Uint8Array.fromBase64(t);
712
- return this.set(n, e), { read: n.length, written: n.length };
713
- },
714
- toString: function() {
715
- return new TextDecoder().decode(this);
716
- },
717
- $toHex: function() {
718
- let t = "";
719
- for (let e = 0; e < this.length; e++)
720
- t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
721
- return t;
722
- },
723
- $toBase64: function() {
724
- let t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
725
- for (let n = 2; n < this.length; n += 3) {
726
- const r = (this[n - 2] << 16) + (this[n - 1] << 8) + this[n];
727
- t += e.charAt((r & 16515072) >> 18) + e.charAt((r & 258048) >> 12) + e.charAt((r & 4032) >> 6) + e.charAt(r & 63);
728
- }
729
- if (this.length % 3 == 2) {
730
- const n = (this[this.length - 2] << 16) + (this[this.length - 1] << 8);
731
- t += e.charAt((n & 16515072) >> 18) + e.charAt((n & 258048) >> 12) + e.charAt((n & 4032) >> 6) + "=";
732
- } else if (this.length % 3 == 1) {
733
- const n = this[this.length - 1] << 16;
734
- t += e.charAt((n & 16515072) >> 18) + e.charAt((n & 258048) >> 12) + "==";
735
- }
736
- return t;
737
- },
738
- toArray: function() {
739
- return new Array(...this);
740
- }
741
- });
742
- typeof Uint8Array.fromBase64 > "u" && (Uint8Array.fromHex = Uint8Array.$fromHex, Uint8Array.fromBase64 = Uint8Array.$fromBase64);
743
- typeof Uint8Array.prototype.setFromHex > "u" && (Uint8Array.prototype.setFromHex = Uint8Array.prototype.$setFromHex, Uint8Array.prototype.setFromBase64 = Uint8Array.prototype.$setFromBase64, Uint8Array.prototype.toHex = Uint8Array.prototype.$toHex, Uint8Array.prototype.toBase64 = Uint8Array.prototype.$toBase64);
744
- let D = 0, w = 0, A = 0;
745
- h(Math, {
746
- randstr: function(t = 16, e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
747
- if (t < e)
748
- throw new Error("randstr: len < slen");
749
- const i = [];
750
- for (let s = 0; s < t; s++)
751
- i.push(n.charAt(Math.random() * n.length | 0));
752
- for (let s = /* @__PURE__ */ new Set(), o = 0, u = 0; u < e; u++) {
753
- do
754
- o = Math.random() * t | 0;
755
- while (s.has(o));
756
- s.set(o, !0), i[o] = r.charAt(Math.random() * r.length | 0);
757
- }
758
- return i.join("");
759
- },
760
- randint: function(t = 0, e = Number.MAX_SAFE_INTEGER) {
761
- return Math.floor(Math.random() * (e - t) + t);
762
- },
763
- incrid: function() {
764
- return ++D;
765
- },
766
- incrstr: function() {
767
- return "" + Math.incrid();
768
- },
769
- uniqid: function(t = Date.now()) {
770
- return t === A ? t * 2048 + ++w % 2048 : (A = t) * 2048 + (w = 0) % 2048;
771
- },
772
- uniqstr: function() {
773
- return "" + Math.uniqid();
774
- },
775
- sleep: function(t) {
776
- return new Promise((e) => setTimeout(e, t));
777
- },
778
- useTemplate: function(t) {
779
- let e = null;
780
- const n = { setup(i, { slots: s }) {
781
- return e = s.default, () => {
782
- };
783
- }, name: t + "Template" }, r = { setup(i, { attrs: s }) {
784
- return () => e?.(s);
785
- }, name: t };
786
- return { [n.name]: n, [r.name]: r };
787
- }
788
- });
789
- class M extends Map {
790
- constructor(e) {
791
- super(), this.capacity = e;
792
- }
793
- get(e) {
794
- if (!super.has(e))
795
- return null;
796
- const n = super.get(e);
797
- return super.delete(e), super.set(e, n), n;
798
- }
799
- getOrInsert(e, n) {
800
- super.has(e) || super.set(e, n);
801
- const r = super.get(e);
802
- return super.delete(e), super.set(e, r), r;
803
- }
804
- getOrInsertComputed(e, n) {
805
- super.has(e) || super.set(e, n(e));
806
- const r = super.get(e);
807
- return super.delete(e), super.set(e, r), r;
808
- }
809
- async getOrInsertComputedAsync(e, n) {
810
- super.has(e) || super.set(e, await n(e));
811
- const r = super.get(e);
812
- return super.delete(e), super.set(e, r), r;
813
- }
814
- set(e, n) {
815
- super.has(e) && super.delete(e), super.set(e, n), super.size > this.capacity && super.delete(super.keys().next().value);
816
- }
817
- put(e, n) {
818
- return this.set(e, n);
819
- }
820
- }
821
- h(M, {
822
- ...g()
823
- });
824
- typeof globalThis.LRU > "u" && (globalThis.LRU = M);
777
+ //#endregion
778
+ //#region lib/LRU.js
779
+ var d = class extends Map {
780
+ constructor(e) {
781
+ super(), this.capacity = e;
782
+ }
783
+ get(e) {
784
+ if (!super.has(e)) return null;
785
+ let t = super.get(e);
786
+ return super.delete(e), super.set(e, t), t;
787
+ }
788
+ getOrInsert(e, t) {
789
+ super.has(e) || super.set(e, t);
790
+ let n = super.get(e);
791
+ return super.delete(e), super.set(e, n), n;
792
+ }
793
+ getOrInsertComputed(e, t) {
794
+ super.has(e) || super.set(e, t(e));
795
+ let n = super.get(e);
796
+ return super.delete(e), super.set(e, n), n;
797
+ }
798
+ async getOrInsertComputedAsync(e, t) {
799
+ super.has(e) || super.set(e, await t(e));
800
+ let n = super.get(e);
801
+ return super.delete(e), super.set(e, n), n;
802
+ }
803
+ set(e, t) {
804
+ super.has(e) && super.delete(e), super.set(e, t), super.size > this.capacity && super.delete(super.keys().next().value);
805
+ }
806
+ put(e, t) {
807
+ return this.set(e, t);
808
+ }
809
+ };
810
+ e(d, { ...t() }), globalThis.LRU === void 0 && (globalThis.LRU = d);
811
+ //#endregion