esexts 2.0.6 → 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,822 +1,811 @@
1
- function c(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, h) => (u !== null && o.splice(u >= 0 ? u : o.length + u + 1, 0, h), o);
23
- for (const o of r) {
24
- const [u, h] = Array.isArray(o) ? o : [o, "$" + o + n.toString().replaceAll("-", "_")];
25
- if (n === "")
26
- i[h] = function(...a) {
27
- return t[u].apply(this, s(a, e, this));
28
- };
29
- else if (n === "t")
30
- i[h] = function(...a) {
31
- return t[u].apply(this, s(a, e, this)), this;
32
- };
33
- else if (n === "a")
34
- i[h] = function(...a) {
35
- return t[u].apply(this, s(a, e, this)), a;
36
- };
37
- else if (n >= 0)
38
- i[h] = function(...a) {
39
- return t[u].apply(this, s(a, e, this)), a[n];
40
- };
41
- else if (n < 0)
42
- i[h] = 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 h in s)
70
- i[h] = r(i[h], s[h]);
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 x = b({ array: !1 }), S = b({ array: !0 });
81
- c(Object, {
82
- ...g(),
83
- isObject: function(t) {
84
- return Object.prototype.toString.call(t) === "[object Object]";
85
- },
86
- merge$: function(...t) {
87
- return x(this, ...t);
88
- },
89
- concat: function(...t) {
90
- return S(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
- c(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 x(this, ...t);
104
- },
105
- $concat: function(...t) {
106
- return S(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 h of s[n])
159
- i(h, !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
- c(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
- c(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
- c(String.prototype, {
246
- ...g(),
247
- ...m(["length", "length$"]),
248
- $substring: function(t = 0, e = this.length) {
249
- return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
250
- },
251
- $substr: function(t = 0, e = this.length) {
252
- return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
253
- },
254
- $split: function(t = ",", e = -1) {
255
- const n = this ? this.split(t) : [];
256
- return e === -1 ? n : n.$push(n.splice(e - 1).join(t));
257
- },
258
- $split$number: function(t = ",") {
259
- return this.$split(t).map((e) => +e);
260
- },
261
- $split$segment: function(t = 1) {
262
- const e = [];
263
- for (let n = 0; n < this.length; n += t)
264
- e.push(this.substring(n, n + t));
265
- return e;
266
- },
267
- sprintf: function(...t) {
268
- let [e, ...n] = this.split(/%[sd]/);
269
- for (let r = 0; r < n.length; r++)
270
- e += t[r] + n[r];
271
- return e;
272
- },
273
- subOf: function(t, e, n = 0, r = 0) {
274
- for (let o = 0; o < n && r != -1; o++, r++)
275
- r = this.indexOf(t, r);
276
- let i = this.indexOf(t, r), s = this.indexOf(e, i);
277
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
278
- },
279
- lastSubOf: function(t, e, n = 0, r = 1 / 0) {
280
- for (let o = 0; o < n && r != -1; o++, r--)
281
- r = this.lastIndexOf(t, r);
282
- let i = this.lastIndexOf(t, r), s = this.indexOf(e, i);
283
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
284
- },
285
- camel2under: function() {
286
- return this.substr(0, 1) + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
287
- },
288
- under2camel: function() {
289
- return this.replace(/_([a-z])/g, (t, e) => e.toUpperCase());
290
- },
291
- camel2pascal: function() {
292
- return this.substr(0, 1).toUpperCase() + this.substr(1);
293
- },
294
- pascal2camel: function() {
295
- return this.substr(0, 1).toLowerCase() + this.substr(1);
296
- },
297
- under2kebab: function() {
298
- return this.replace(/_/g, "-");
299
- },
300
- kebab2under: function() {
301
- return this.replace(/-/g, "_");
302
- },
303
- baseConvert: function(t = 64) {
304
- let e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
305
- for (let r = 0; r < this.length; r++)
306
- e = e * t + n.indexOf(this.at(r));
307
- return e;
308
- },
309
- fixed: function(...t) {
310
- return +(+this).toFixed(...t);
311
- },
312
- toDate: function() {
313
- return Date.new(this);
314
- },
315
- // ====== Uint8Array ======
316
- toUint8Array: function() {
317
- return new TextEncoder().encode(this);
318
- },
319
- // ====== hex ======
320
- hexencode: function() {
321
- return new TextEncoder().encode(this).toHex();
322
- },
323
- hexdecode: function() {
324
- return new TextDecoder().decode(Uint8Array.fromHex(this));
325
- },
326
- // ====== base64 ======
327
- base64encode: function() {
328
- return new TextEncoder().encode(this).toBase64();
329
- },
330
- base64decode: function() {
331
- return new TextDecoder().decode(Uint8Array.fromBase64(this));
332
- }
333
- });
334
- c(Array, {
335
- ...g(),
336
- // ====== from pinojs ======
337
- range: function(...t) {
338
- 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, h, a) => u;
339
- switch (t.length) {
340
- case 1:
341
- [r] = t;
342
- break;
343
- case 2:
344
- [n, r] = t;
345
- break;
346
- case 3:
347
- [n, r, i] = t;
348
- break;
349
- default:
350
- throw new Error("the number of parameters is incorrect!");
351
- }
352
- if (i == 0)
353
- throw new Error("step cannot be 0!");
354
- for (let u = 0, h = 0, a = Math.abs(r - n), p = Math.abs(i), d = n <= r ? 1 : -1; h < a; h += p)
355
- e.push(s ? o(n + h * d, u++, e) : o());
356
- return e;
357
- }
358
- });
359
- c(Array.prototype, {
360
- ...m("length"),
361
- ...$(Array.prototype, "entries", "keys", "values"),
362
- ...f(Array.prototype, null, "", "map"),
363
- ...f(Array.prototype, null, "t", ["push", "$push"], ["pop", "$pop"], ["shift", "$shift"], ["unshift", "$unshift"], ["splice", "$splice"]),
364
- ...f(Array.prototype, null, "a", "push", "unshift"),
365
- ...f(Array.prototype, null, 0, "push", "unshift"),
366
- $empty: function() {
367
- return this.length == 0;
368
- },
369
- first: function(t = null) {
370
- return this.length ? this[0] : t;
371
- },
372
- last: function(t = null) {
373
- return this.length ? this[this.length - 1] : t;
374
- },
375
- $find: function(t, e = null) {
376
- return this.find(t) ?? e;
377
- },
378
- equals: function(t) {
379
- return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
380
- },
381
- unique: function(t = (e) => e) {
382
- const e = /* @__PURE__ */ new Set();
383
- return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
384
- },
385
- ...f(Array.prototype, null, "t", ["forEach", "each"]),
386
- each$async: async function(t) {
387
- for (let e = 0; e < this.length; e++)
388
- await t(this[e], e, this);
389
- return this;
390
- },
391
- map$async: async function(t) {
392
- const e = [];
393
- for (let n = 0; n < this.length; n++)
394
- e.push(await t(this[n], n, this));
395
- return e;
396
- },
397
- shuffle: function(t = !1) {
398
- let e = this.length;
399
- for (; e; ) {
400
- const n = Math.random() * e-- | 0;
401
- [this[n], this[e]] = [this[e], this[n]];
402
- }
403
- return this;
404
- },
405
- // ====== collection ======
406
- union: function(t) {
407
- return Set.new(this).union(Set.new(t)).toArray();
408
- },
409
- intersection: function(t) {
410
- return Set.new(this).intersection(Set.new(t)).toArray();
411
- },
412
- difference: function(t) {
413
- return Set.new(this).difference(Set.new(t)).toArray();
414
- },
415
- symmetricDifference: function(t) {
416
- return Set.new(this).symmetricDifference(Set.new(t)).toArray();
417
- },
418
- // ====== convert ======
419
- toMap: function(t = (e, n) => [n, e]) {
420
- return new Map(this.map(t));
421
- },
422
- toSet: function(t = (e) => e) {
423
- return new Set(this.map(t));
424
- },
425
- // ====== Uint8Array ======
426
- toUint8Array: function() {
427
- return new Uint8Array(this);
428
- },
429
- toBase64: function() {
430
- return this.toUint8Array().toBase64();
431
- },
432
- toHex: function() {
433
- return this.toUint8Array().toHex();
434
- },
435
- // ====== TextDecoder ======
436
- decode: function() {
437
- return this.toUint8Array().decode();
438
- },
439
- // ====== Relational ======
440
- assoc: function(t, e, n = {}) {
441
- const r = this.unique$((s) => s[t]), i = r.length == 0 ? {} : typeof n == "function" ? n(r) : n;
442
- return this.each$((s) => s[e] = i[s[t]] ?? null);
443
- },
444
- // ====== Tree ======
445
- toTree: function(t = {}) {
446
- const { id: e = "id", pid: n = "pid", level: r = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: u = null, hasRoot: h = !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 && h ? this.find((l) => l[n] === 0) : { [e]: 0, [n]: -1, [i]: null, [s]: null, [o]: p[0] };
447
- c(d, { [i]: d });
448
- for (const l of this)
449
- c(l, { [i]: d, [s]: a[l[n]] }), l[o] = p[l[e]] || u;
450
- return d.$tree$each((l) => l[r] = l[s] ? l[s][r] + 1 : 0, -1, o), d;
451
- },
452
- $tree2tree: function(t = {}, e = null, n = null) {
453
- const { id: r = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: u = "parent", children: h = "children", empty: a = null } = t;
454
- e = e || { [r]: 0, [i]: -1, [s]: 0, [o]: null, [u]: null, [h]: this }, n = n || e;
455
- for (const p of this)
456
- c(p, { [o]: e, [u]: n }), p[i] = n[r], p[s] = n[s] + 1, p[h] = p[h] && p[h].length ? p[h] : a, p[h]?.$tree2tree(t, e, p);
457
- return e;
458
- },
459
- $tree$find: function(t, e = !0, n = -1, r = "children") {
460
- for (const i of this) {
461
- const s = i.$tree$find(t, e, n, r);
462
- if (s !== null)
463
- return s;
464
- }
465
- return null;
466
- },
467
- $tree$each: function(t, e = !0, n = -1, r = "children") {
468
- for (const i of this)
469
- i.$tree$each(t, e, n, r);
470
- return this;
471
- },
472
- $tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
473
- return this.map((s) => s.$tree$map(t, e, n, r, i));
474
- }
475
- });
476
- c(Map, {
477
- ...g()
478
- });
479
- c(Map.prototype, {
480
- ...m(["size", "$length"]),
481
- ...$(Map.prototype, "entries", "keys", "values"),
482
- ...f(Map.prototype, null, "t", ["set", "$set"], ["delete", "$delete"]),
483
- ...f(Map.prototype, null, "a", "set", "delete"),
484
- ...f(Map.prototype, null, 0, "set", "delete"),
485
- ...f(Map.prototype, null, 1, "set", "delete"),
486
- $getOrInsert: function(t, e = null) {
487
- return this.has(t) ? this.get(t) : this.$set1(t, e);
488
- },
489
- $getOrInsertComputed: function(t, e) {
490
- return this.has(t) ? this.get(t) : this.$set1(t, e(t));
491
- },
492
- $get: function(t, e = null) {
493
- return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? e(t) : e);
494
- },
495
- $get$async: async function(t, e = null) {
496
- return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? await e(t) : e);
497
- },
498
- toObject: function() {
499
- return Object.fromEntries(this);
500
- },
501
- toArray: function() {
502
- return [...this];
503
- },
504
- toJSON: function() {
505
- return [...this];
506
- }
507
- });
508
- typeof Map.prototype.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed);
509
- c(Set, {
510
- ...g()
511
- });
512
- c(Set.prototype, {
513
- ...m(["size", "$length"]),
514
- ...$(Set.prototype, "entries", "keys", "values"),
515
- ...f(Set.prototype, null, "t", ["add", "$add"], ["delete", "$delete"]),
516
- ...f(Set.prototype, null, "a", "add", "delete"),
517
- ...f(Set.prototype, null, 0, "add", "delete"),
518
- $union: function(t) {
519
- return /* @__PURE__ */ new Set([...this, ...t]);
520
- },
521
- $intersection: function(t) {
522
- return new Set([...this].filter((e) => t.has(e)));
523
- },
524
- $difference: function(t) {
525
- return new Set([...this].filter((e) => !t.has(e)));
526
- },
527
- $symmetricDifference: function(t) {
528
- return /* @__PURE__ */ new Set([...[...this].filter((e) => !t.has(e)), ...[...t].filter((e) => !this.has(e))]);
529
- },
530
- toArray: function() {
531
- return [...this];
532
- },
533
- toJSON: function() {
534
- return [...this];
535
- }
536
- });
537
- 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);
538
- c(Date, {
539
- new: function(...t) {
540
- 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);
541
- },
542
- format: function(t = "y-m-d h:i:s") {
543
- return (/* @__PURE__ */ new Date()).format(t);
544
- },
545
- unix: function() {
546
- return this.now() / 1e3 | 0;
547
- },
548
- fromUnix: function(t) {
549
- return new Date((t ?? 0) * 1e3);
550
- },
551
- expr: function(t = {}) {
552
- return (/* @__PURE__ */ new Date()).expr(t);
553
- },
554
- toDayRange: function() {
555
- const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), r = t.getDate(), i = new Date(e, n, r).getTime() / 1e3 | 0;
556
- return [i, i + 86400 - 1];
557
- },
558
- toWeekRange: function() {
559
- let t = /* @__PURE__ */ new Date();
560
- for (; t.getDay() != 1; )
561
- t = new Date(t.getTime() - 86400);
562
- const e = t.getFullYear(), n = t.getMonth(), r = t.getDate(), i = new Date(e, n, r).getTime() / 1e3 | 0;
563
- return [i, i + 86400 * 7 - 1];
564
- },
565
- toMonthRange: function() {
566
- 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;
567
- return [r, i];
568
- },
569
- toYearRange: function() {
570
- 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;
571
- return [n, r];
572
- }
573
- });
574
- c(Date.prototype, {
575
- format: function(t = "y-m-d h:i:s") {
576
- if (this.getTime() === 0)
577
- return "-";
578
- const e = {
579
- y: this.getFullYear(),
580
- m: this.getMonth() + 1,
581
- d: this.getDate(),
582
- h: this.getHours(),
583
- i: this.getMinutes(),
584
- s: this.getSeconds(),
585
- l: this.getMilliseconds(),
586
- e: this.getMonthDay()
587
- };
588
- return t.replace(/([ymdhisle])/ig, (n, r) => r >= "A" && r <= "Z" ? e[r.toLowerCase()] : e[r].toString().padStart(r === "l" ? 3 : 2, "0"));
589
- },
590
- unix: function() {
591
- return this.getTime() / 1e3 | 0;
592
- },
593
- isLeapYear: function() {
594
- return this.getFullYear() % 4 === 0 && this.getFullYear() % 400 !== 0;
595
- },
596
- getMonthDay: function() {
597
- return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
598
- },
599
- expr: function({ y: t = 0, m: e = 0, d: n = 0, h: r = 0, i = 0, s = 0 }) {
600
- const o = new Date(this.getFullYear() + t, this.getMonth() + e + 1, 0);
601
- 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);
602
- },
603
- begin: function(t = 3) {
604
- 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));
605
- },
606
- end: function(t = 3) {
607
- 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));
608
- },
609
- week: function(t, e = 1) {
610
- let n = new Date(this.getTime());
611
- for (; n.getDay() !== t; )
612
- n = new Date(n.getTime() + 864e5 * e);
613
- return n;
614
- },
615
- toJSON: function() {
616
- return this.getTime();
617
- }
618
- });
619
- c(RegExp, {
620
- ...g()
621
- });
622
- c(RegExp.prototype, {
623
- toJSON: function() {
624
- return this.toString();
625
- }
626
- });
627
- c(Promise, {
628
- ...g(),
629
- channel: function() {
630
- let t = null, e = null;
631
- return [new this((r, i) => {
632
- t = r, e = i;
633
- }), t, e];
634
- },
635
- $withResolvers: function() {
636
- let t = null, e = null;
637
- return { promise: new this((r, i) => {
638
- t = r, e = i;
639
- }), resolve: t, reject: e };
640
- }
641
- });
642
- c(Promise.prototype, {
643
- tryCatch: function() {
644
- return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
645
- }
646
- });
647
- typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise.$withResolvers);
648
- c(JSON, {
649
- $parse: function(t, e = null) {
650
- try {
651
- if (typeof t != "string")
652
- throw new Error("not string");
653
- return JSON.parse(t);
654
- } catch {
655
- return e;
656
- }
657
- }
658
- });
659
- typeof Iterator < "u" && c(Iterator.prototype, {
660
- toArray: function() {
661
- return [...this];
662
- }
663
- });
664
- c(ArrayBuffer.prototype, {
665
- toUint8Array: function() {
666
- return new Uint8Array(this);
667
- }
668
- });
669
- c(Uint8Array, {
670
- ...g(),
671
- fromString: function(t) {
672
- return new TextEncoder().encode(t);
673
- },
674
- $fromHex: function(t) {
675
- const e = [];
676
- for (let n = 0; n < t.length; n += 2)
677
- e.push(Number.parseInt(t.substring(n, n + 2), 16));
678
- return new Uint8Array(e);
679
- },
680
- $fromBase64: function(t) {
681
- const e = [], n = {}, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
682
- for (let s = 0; s < r.length; s++)
683
- n[r.charAt(s)] = s;
684
- const i = t.charAt(t.length - 1) != "=" ? t.length : t.charAt(t.length - 2) != "=" ? t.length - 1 : t.length - 2;
685
- for (let s = 3; s < i; s += 4) {
686
- const o = (n[t.charAt(s - 3)] << 18) + (n[t.charAt(s - 2)] << 12) + (n[t.charAt(s - 1)] << 6) + n[t.charAt(s)];
687
- e.push((o & 16711680) >> 16, (o & 65280) >> 8, o & 255);
688
- }
689
- if (i % 4 == 3) {
690
- const s = (n[t.charAt(i - 3)] << 18) + (n[t.charAt(i - 2)] << 12) + (n[t.charAt(i - 1)] << 6);
691
- e.push((s & 16711680) >> 16, (s & 65280) >> 8);
692
- } else if (i % 4 == 2) {
693
- const s = (n[t.charAt(i - 2)] << 18) + (n[t.charAt(i - 1)] << 12);
694
- e.push((s & 16711680) >> 16);
695
- }
696
- return new Uint8Array(e);
697
- }
698
- });
699
- c(Uint8Array.prototype, {
700
- setFromString(t, e = 0) {
701
- const n = Uint8Array.fromString(t);
702
- return this.set(n, e), { read: n.length, written: n.length };
703
- },
704
- $setFromHex(t, e = 0) {
705
- const n = Uint8Array.fromHex(t);
706
- return this.set(n, e), { read: n.length, written: n.length };
707
- },
708
- $setFromBase64(t, e = 0) {
709
- const n = Uint8Array.fromBase64(t);
710
- return this.set(n, e), { read: n.length, written: n.length };
711
- },
712
- toString: function() {
713
- return new TextDecoder().decode(this);
714
- },
715
- $toHex: function() {
716
- let t = "";
717
- for (let e = 0; e < this.length; e++)
718
- t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
719
- return t;
720
- },
721
- $toBase64: function() {
722
- let t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
723
- for (let n = 2; n < this.length; n += 3) {
724
- const r = (this[n - 2] << 16) + (this[n - 1] << 8) + this[n];
725
- t += e.charAt((r & 16515072) >> 18) + e.charAt((r & 258048) >> 12) + e.charAt((r & 4032) >> 6) + e.charAt(r & 63);
726
- }
727
- if (this.length % 3 == 2) {
728
- const n = (this[this.length - 2] << 16) + (this[this.length - 1] << 8);
729
- t += e.charAt((n & 16515072) >> 18) + e.charAt((n & 258048) >> 12) + e.charAt((n & 4032) >> 6) + "=";
730
- } else if (this.length % 3 == 1) {
731
- const n = this[this.length - 1] << 16;
732
- t += e.charAt((n & 16515072) >> 18) + e.charAt((n & 258048) >> 12) + "==";
733
- }
734
- return t;
735
- },
736
- toArray: function() {
737
- return new Array(...this);
738
- }
739
- });
740
- typeof Uint8Array.fromBase64 > "u" && (Uint8Array.fromHex = Uint8Array.$fromHex, Uint8Array.fromBase64 = Uint8Array.$fromBase64);
741
- 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);
742
- let D = 0, w = 0, A = 0;
743
- c(Math, {
744
- randstr: function(t = 16, e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
745
- if (t < e)
746
- throw new Error("randstr: len < slen");
747
- const i = [];
748
- for (let s = 0; s < t; s++)
749
- i.push(n.charAt(Math.random() * n.length | 0));
750
- for (let s = /* @__PURE__ */ new Set(), o = 0, u = 0; u < e; u++) {
751
- do
752
- o = Math.random() * t | 0;
753
- while (s.has(o));
754
- s.set(o, !0), i[o] = r.charAt(Math.random() * r.length | 0);
755
- }
756
- return i.join("");
757
- },
758
- randint: function(t = 0, e = Number.MAX_SAFE_INTEGER) {
759
- return Math.floor(Math.random() * (e - t) + t);
760
- },
761
- incrid: function() {
762
- return ++D;
763
- },
764
- incrstr: function() {
765
- return "" + Math.incrid();
766
- },
767
- uniqid: function(t = Date.now()) {
768
- return t === A ? t * 2048 + ++w % 2048 : (A = t) * 2048 + (w = 0) % 2048;
769
- },
770
- uniqstr: function() {
771
- return "" + Math.uniqid();
772
- },
773
- sleep: function(t) {
774
- return new Promise((e) => setTimeout(e, t));
775
- },
776
- useTemplate: function(t) {
777
- let e = null;
778
- const n = { setup(i, { slots: s }) {
779
- return e = s.default, () => {
780
- };
781
- }, name: t + "Template" }, r = { setup(i, { attrs: s }) {
782
- return () => e?.(s);
783
- }, name: t };
784
- return { [n.name]: n, [r.name]: r };
785
- }
786
- });
787
- class M extends Map {
788
- constructor(e) {
789
- super(), this.capacity = e;
790
- }
791
- get(e) {
792
- if (!super.has(e))
793
- return null;
794
- const n = super.get(e);
795
- return super.delete(e), super.set(e, n), n;
796
- }
797
- getOrInsert(e, n) {
798
- super.has(e) || super.set(e, n);
799
- const r = super.get(e);
800
- return super.delete(e), super.set(e, r), r;
801
- }
802
- getOrInsertComputed(e, n) {
803
- super.has(e) || super.set(e, n(e));
804
- const r = super.get(e);
805
- return super.delete(e), super.set(e, r), r;
806
- }
807
- async getOrInsertComputedAsync(e, n) {
808
- super.has(e) || super.set(e, await n(e));
809
- const r = super.get(e);
810
- return super.delete(e), super.set(e, r), r;
811
- }
812
- set(e, n) {
813
- super.has(e) && super.delete(e), super.set(e, n), super.size > this.capacity && super.delete(super.keys().next().value);
814
- }
815
- put(e, n) {
816
- return this.set(e, n);
817
- }
818
- }
819
- c(M, {
820
- ...g()
821
- });
822
- 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