esexts 2.0.2 → 2.0.4
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 +227 -167
- package/dist/esexts.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/esexts.js
CHANGED
|
@@ -11,36 +11,36 @@ function g() {
|
|
|
11
11
|
function m(...t) {
|
|
12
12
|
const e = {};
|
|
13
13
|
for (const n of t) {
|
|
14
|
-
const [r, i] = Array.isArray(n) ? n : [n,
|
|
14
|
+
const [r, i] = Array.isArray(n) ? n : [n, "$" + n];
|
|
15
15
|
e[i] = function() {
|
|
16
16
|
return this[r];
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
return e;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
const i = {},
|
|
23
|
-
for (const
|
|
24
|
-
const [u, h] = Array.isArray(
|
|
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
25
|
if (n === "")
|
|
26
26
|
i[h] = function(...a) {
|
|
27
|
-
return t[u].apply(this,
|
|
27
|
+
return t[u].apply(this, s(a, e, this));
|
|
28
28
|
};
|
|
29
29
|
else if (n === "t")
|
|
30
30
|
i[h] = function(...a) {
|
|
31
|
-
return t[u].apply(this,
|
|
31
|
+
return t[u].apply(this, s(a, e, this)), this;
|
|
32
32
|
};
|
|
33
33
|
else if (n === "a")
|
|
34
34
|
i[h] = function(...a) {
|
|
35
|
-
return t[u].apply(this,
|
|
35
|
+
return t[u].apply(this, s(a, e, this)), a;
|
|
36
36
|
};
|
|
37
37
|
else if (n >= 0)
|
|
38
38
|
i[h] = function(...a) {
|
|
39
|
-
return t[u].apply(this,
|
|
39
|
+
return t[u].apply(this, s(a, e, this)), a[n];
|
|
40
40
|
};
|
|
41
41
|
else if (n < 0)
|
|
42
42
|
i[h] = function(...a) {
|
|
43
|
-
return t[u].apply(this,
|
|
43
|
+
return t[u].apply(this, s(a, e, this)), a[a.length + n];
|
|
44
44
|
};
|
|
45
45
|
else
|
|
46
46
|
throw Error("unreachable");
|
|
@@ -50,34 +50,34 @@ function l(t, e, n, ...r) {
|
|
|
50
50
|
function $(t, ...e) {
|
|
51
51
|
const n = {};
|
|
52
52
|
for (const r of e) {
|
|
53
|
-
const [i,
|
|
54
|
-
n[
|
|
55
|
-
return [...t[i].apply(this,
|
|
53
|
+
const [i, s] = Array.isArray(r) ? r : [r, "$" + r];
|
|
54
|
+
n[s] = function(...o) {
|
|
55
|
+
return [...t[i].apply(this, o)];
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
return n;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function b(t = { array: !1 }) {
|
|
61
61
|
return function(e = {}, ...n) {
|
|
62
|
-
const r = (i,
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
66
|
-
if (
|
|
67
|
-
return t.array ? i.concat(...
|
|
68
|
-
if (
|
|
69
|
-
for (const h in
|
|
70
|
-
i[h] = r(i[h],
|
|
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
71
|
return i;
|
|
72
72
|
} else
|
|
73
|
-
return
|
|
73
|
+
return s;
|
|
74
74
|
};
|
|
75
75
|
for (const i of n)
|
|
76
76
|
e = r(e, i);
|
|
77
77
|
return e;
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
const x =
|
|
80
|
+
const x = b({ array: !1 }), S = b({ array: !0 });
|
|
81
81
|
c(Object, {
|
|
82
82
|
...g(),
|
|
83
83
|
isObject: function(t) {
|
|
@@ -86,110 +86,110 @@ c(Object, {
|
|
|
86
86
|
merge$: function(...t) {
|
|
87
87
|
return x(this, ...t);
|
|
88
88
|
},
|
|
89
|
-
concat
|
|
90
|
-
return
|
|
89
|
+
concat: function(...t) {
|
|
90
|
+
return S(this, ...t);
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
c(Object.prototype, {
|
|
94
|
-
clone
|
|
94
|
+
$clone: function() {
|
|
95
95
|
return JSON.parse(JSON.stringify(this));
|
|
96
96
|
},
|
|
97
|
-
length
|
|
97
|
+
$length: function() {
|
|
98
98
|
return Object.keys(this).length;
|
|
99
99
|
},
|
|
100
|
-
...
|
|
101
|
-
...
|
|
102
|
-
merge
|
|
100
|
+
...f(Object, 0, "", "entries", "keys", "values", "assign"),
|
|
101
|
+
...f(JSON, 0, "", "stringify"),
|
|
102
|
+
$merge: function(...t) {
|
|
103
103
|
return x(this, ...t);
|
|
104
104
|
},
|
|
105
|
-
concat
|
|
106
|
-
return
|
|
105
|
+
$concat: function(...t) {
|
|
106
|
+
return S(this, ...t);
|
|
107
107
|
},
|
|
108
|
-
empty
|
|
108
|
+
$empty: function() {
|
|
109
109
|
return Object.keys(this).length == 0;
|
|
110
110
|
},
|
|
111
|
-
in
|
|
111
|
+
$in: function(t) {
|
|
112
112
|
return t in this;
|
|
113
113
|
},
|
|
114
|
-
pick
|
|
114
|
+
$pick: function(...t) {
|
|
115
115
|
const e = {};
|
|
116
116
|
for (const n of t)
|
|
117
117
|
e[n] = this[n];
|
|
118
118
|
return e;
|
|
119
119
|
},
|
|
120
|
-
omit
|
|
120
|
+
$omit: function(...t) {
|
|
121
121
|
const e = {}, n = new Set(t);
|
|
122
122
|
for (const r in this)
|
|
123
123
|
n.has(r) || (e[r] = this[r]);
|
|
124
124
|
return e;
|
|
125
125
|
},
|
|
126
|
-
attr
|
|
126
|
+
$attr: function(...t) {
|
|
127
127
|
if (typeof this != "object")
|
|
128
128
|
return this;
|
|
129
129
|
const [e, n, r, i] = t;
|
|
130
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
131
|
},
|
|
132
|
-
pipe
|
|
132
|
+
$pipe: function(t, ...e) {
|
|
133
133
|
return t(this, ...e);
|
|
134
134
|
},
|
|
135
|
-
handle
|
|
135
|
+
$handle: function(t, ...e) {
|
|
136
136
|
return t(this, ...e), this;
|
|
137
137
|
},
|
|
138
|
-
toArray
|
|
138
|
+
$toArray: function() {
|
|
139
139
|
return Array.isArray(this) ? this : [this];
|
|
140
140
|
},
|
|
141
|
-
...
|
|
142
|
-
debugger
|
|
141
|
+
...f(console, -1, "t", ["debug", "$debug"], ["log", "$log"], ["info", "$info"], ["warn", "$warn"], ["error", "$error"], ["dir", "$dir"]),
|
|
142
|
+
$debugger: function(...t) {
|
|
143
143
|
console.debug(this, ...t);
|
|
144
144
|
debugger;
|
|
145
145
|
return this;
|
|
146
146
|
},
|
|
147
147
|
// ====== Tree ======
|
|
148
|
-
getParents
|
|
148
|
+
$getParents: function(t = !1, e = -1, n = "parent") {
|
|
149
149
|
const r = t ? [this] : [];
|
|
150
150
|
let i = this[n];
|
|
151
151
|
for (; i && e-- != 0; )
|
|
152
152
|
r.push(i), i = i[n];
|
|
153
153
|
return r;
|
|
154
154
|
},
|
|
155
|
-
getChildrens
|
|
156
|
-
const r = [], i = (
|
|
157
|
-
if (
|
|
158
|
-
for (const h of
|
|
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
159
|
i(h, !0, u - 1);
|
|
160
160
|
};
|
|
161
161
|
return i(this, t, e), r;
|
|
162
162
|
},
|
|
163
|
-
tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
163
|
+
$tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
164
164
|
if (e && t(this))
|
|
165
165
|
return this;
|
|
166
166
|
if (n == 0 || !this[r] || this[r].length == 0)
|
|
167
167
|
return null;
|
|
168
168
|
for (const i of this[r]) {
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
return
|
|
169
|
+
const s = i.$tree$find(t, !0, n - 1, r);
|
|
170
|
+
if (s !== null)
|
|
171
|
+
return s;
|
|
172
172
|
}
|
|
173
173
|
return null;
|
|
174
174
|
},
|
|
175
|
-
tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
175
|
+
$tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
176
176
|
if (e && t(this), !(n == 0 || !this[r] || this[r].length == 0)) {
|
|
177
177
|
for (const i of this[r])
|
|
178
|
-
i
|
|
178
|
+
i.$tree$each(t, !0, n - 1, r);
|
|
179
179
|
return this;
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
|
-
tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
183
|
-
const
|
|
182
|
+
$tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
183
|
+
const s = e ? t(this) : this, o = [];
|
|
184
184
|
if (n == 0 || !this[r] || this[r].length == 0)
|
|
185
|
-
return
|
|
185
|
+
return s;
|
|
186
186
|
for (const u of this[r])
|
|
187
|
-
|
|
188
|
-
return
|
|
187
|
+
o.push(u.$tree$map(t, !0, n - 1, r, i));
|
|
188
|
+
return s[r] = o, s;
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
191
|
c(Number.prototype, {
|
|
192
|
-
...
|
|
192
|
+
...f(Math, 0, "", ["ceil", "ceil"], ["floor", "floor"], ["trunc", "trunc"], ["abs", "abs"], ["max", "max"], ["min", "min"]),
|
|
193
193
|
fixed: function(t = 0) {
|
|
194
194
|
return +this.toFixed(t);
|
|
195
195
|
},
|
|
@@ -216,10 +216,10 @@ c(Number.prototype, {
|
|
|
216
216
|
},
|
|
217
217
|
unit: function(t, e = 0) {
|
|
218
218
|
let n = this, r = "";
|
|
219
|
-
for (const [i,
|
|
220
|
-
if (r = i,
|
|
219
|
+
for (const [i, s] of Object.entries(t)) {
|
|
220
|
+
if (r = i, s === 0 || n < s)
|
|
221
221
|
break;
|
|
222
|
-
n = n /
|
|
222
|
+
n = n / s;
|
|
223
223
|
}
|
|
224
224
|
return e < 0 ? +n.toFixed(0 - e) + r : n.toFixed(e) + r;
|
|
225
225
|
},
|
|
@@ -231,7 +231,7 @@ c(Number.prototype, {
|
|
|
231
231
|
break;
|
|
232
232
|
} else
|
|
233
233
|
r.push([n % size, unit]), n = Math.floor(n / size);
|
|
234
|
-
return e ? r : r.reverse().map(([i,
|
|
234
|
+
return e ? r : r.reverse().map(([i, s]) => i + s).join("");
|
|
235
235
|
},
|
|
236
236
|
toDate: function() {
|
|
237
237
|
return Date.new(this);
|
|
@@ -245,20 +245,20 @@ c(BigInt.prototype, {
|
|
|
245
245
|
c(String.prototype, {
|
|
246
246
|
...g(),
|
|
247
247
|
...m(["length", "length$"]),
|
|
248
|
-
substring
|
|
248
|
+
$substring: function(t = 0, e = this.length) {
|
|
249
249
|
return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
|
|
250
250
|
},
|
|
251
|
-
substr
|
|
251
|
+
$substr: function(t = 0, e = this.length) {
|
|
252
252
|
return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
|
|
253
253
|
},
|
|
254
|
-
split
|
|
254
|
+
$split: function(t = ",", e = -1) {
|
|
255
255
|
const n = this ? this.split(t) : [];
|
|
256
|
-
return e === -1 ? n : n
|
|
256
|
+
return e === -1 ? n : n.$push(n.splice(e - 1).join(t));
|
|
257
257
|
},
|
|
258
|
-
split$number: function(t = ",") {
|
|
259
|
-
return this
|
|
258
|
+
$split$number: function(t = ",") {
|
|
259
|
+
return this.$split(t).map((e) => +e);
|
|
260
260
|
},
|
|
261
|
-
split$segment: function(t = 1) {
|
|
261
|
+
$split$segment: function(t = 1) {
|
|
262
262
|
const e = [];
|
|
263
263
|
for (let n = 0; n < this.length; n += t)
|
|
264
264
|
e.push(this.substring(n, n + t));
|
|
@@ -271,16 +271,16 @@ c(String.prototype, {
|
|
|
271
271
|
return e;
|
|
272
272
|
},
|
|
273
273
|
subOf: function(t, e, n = 0, r = 0) {
|
|
274
|
-
for (let
|
|
274
|
+
for (let o = 0; o < n && r != -1; o++, r++)
|
|
275
275
|
r = this.indexOf(t, r);
|
|
276
|
-
let i = this.indexOf(t, r),
|
|
277
|
-
return i == -1 ||
|
|
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
278
|
},
|
|
279
279
|
lastSubOf: function(t, e, n = 0, r = 1 / 0) {
|
|
280
|
-
for (let
|
|
280
|
+
for (let o = 0; o < n && r != -1; o++, r--)
|
|
281
281
|
r = this.lastIndexOf(t, r);
|
|
282
|
-
let i = this.lastIndexOf(t, r),
|
|
283
|
-
return i == -1 ||
|
|
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
284
|
},
|
|
285
285
|
camel2under: function() {
|
|
286
286
|
return this.substr(0, 1) + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
|
|
@@ -335,7 +335,7 @@ c(Array, {
|
|
|
335
335
|
...g(),
|
|
336
336
|
// ====== from pinojs ======
|
|
337
337
|
range: function(...t) {
|
|
338
|
-
let e = [], n = 0, r = 0, i = 1,
|
|
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
339
|
switch (t.length) {
|
|
340
340
|
case 1:
|
|
341
341
|
[r] = t;
|
|
@@ -351,38 +351,38 @@ c(Array, {
|
|
|
351
351
|
}
|
|
352
352
|
if (i == 0)
|
|
353
353
|
throw new Error("step cannot be 0!");
|
|
354
|
-
for (let u = 0, h = 0, a = Math.abs(r - n), p = Math.abs(i),
|
|
355
|
-
e.push(
|
|
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
356
|
return e;
|
|
357
357
|
}
|
|
358
358
|
});
|
|
359
359
|
c(Array.prototype, {
|
|
360
360
|
...m("length"),
|
|
361
361
|
...$(Array.prototype, "entries", "keys", "values"),
|
|
362
|
-
...
|
|
363
|
-
...
|
|
364
|
-
...
|
|
365
|
-
...
|
|
366
|
-
empty
|
|
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
367
|
return this.length == 0;
|
|
368
368
|
},
|
|
369
|
-
first
|
|
369
|
+
first: function(t = null) {
|
|
370
370
|
return this.length ? this[0] : t;
|
|
371
371
|
},
|
|
372
|
-
last
|
|
372
|
+
last: function(t = null) {
|
|
373
373
|
return this.length ? this[this.length - 1] : t;
|
|
374
374
|
},
|
|
375
|
-
find
|
|
375
|
+
$find: function(t, e = null) {
|
|
376
376
|
return this.find(t) ?? e;
|
|
377
377
|
},
|
|
378
|
-
equals
|
|
378
|
+
equals: function(t) {
|
|
379
379
|
return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
|
|
380
380
|
},
|
|
381
|
-
unique
|
|
381
|
+
unique: function(t = (e) => e) {
|
|
382
382
|
const e = /* @__PURE__ */ new Set();
|
|
383
383
|
return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
|
|
384
384
|
},
|
|
385
|
-
...
|
|
385
|
+
...f(Array.prototype, null, "t", ["forEach", "each"]),
|
|
386
386
|
each$async: async function(t) {
|
|
387
387
|
for (let e = 0; e < this.length; e++)
|
|
388
388
|
await t(this[e], e, this);
|
|
@@ -402,6 +402,19 @@ c(Array.prototype, {
|
|
|
402
402
|
}
|
|
403
403
|
return this;
|
|
404
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
|
+
},
|
|
405
418
|
// ====== convert ======
|
|
406
419
|
toMap: function(t = (e, n) => [n, e]) {
|
|
407
420
|
return new Map(this.map(t));
|
|
@@ -425,65 +438,62 @@ c(Array.prototype, {
|
|
|
425
438
|
},
|
|
426
439
|
// ====== Relational ======
|
|
427
440
|
assoc: function(t, e, n = {}) {
|
|
428
|
-
const r = this.unique$((
|
|
429
|
-
return this.each$((
|
|
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);
|
|
430
443
|
},
|
|
431
444
|
// ====== Tree ======
|
|
432
445
|
toTree: function(t = {}) {
|
|
433
|
-
const { id: e = "id", pid: n = "pid", level: r = "level", root: i = "root", parent:
|
|
434
|
-
c(
|
|
435
|
-
for (const
|
|
436
|
-
c(
|
|
437
|
-
return
|
|
438
|
-
},
|
|
439
|
-
tree2tree: function(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
tree$tree: function(t = {}, e = null, n = null) {
|
|
443
|
-
const { id: r = "id", pid: i = "pid", level: o = "level", root: s = "root", parent: u = "parent", children: h = "children", empty: a = null } = t;
|
|
444
|
-
e = e || { [r]: 0, [i]: -1, [o]: 0, [s]: null, [u]: null, [h]: this }, n = n || e;
|
|
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;
|
|
445
455
|
for (const p of this)
|
|
446
|
-
c(p, { [
|
|
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);
|
|
447
457
|
return e;
|
|
448
458
|
},
|
|
449
|
-
tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
459
|
+
$tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
450
460
|
for (const i of this) {
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
453
|
-
return
|
|
461
|
+
const s = i.$tree$find(t, e, n, r);
|
|
462
|
+
if (s !== null)
|
|
463
|
+
return s;
|
|
454
464
|
}
|
|
455
465
|
return null;
|
|
456
466
|
},
|
|
457
|
-
tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
467
|
+
$tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
458
468
|
for (const i of this)
|
|
459
|
-
i
|
|
469
|
+
i.$tree$each(t, e, n, r);
|
|
460
470
|
return this;
|
|
461
471
|
},
|
|
462
|
-
tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
463
|
-
return this.map((
|
|
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));
|
|
464
474
|
}
|
|
465
475
|
});
|
|
466
476
|
c(Map, {
|
|
467
477
|
...g()
|
|
468
478
|
});
|
|
469
479
|
c(Map.prototype, {
|
|
470
|
-
...m(["size", "length
|
|
480
|
+
...m(["size", "$length"]),
|
|
471
481
|
...$(Map.prototype, "entries", "keys", "values"),
|
|
472
|
-
...
|
|
473
|
-
...
|
|
474
|
-
...
|
|
475
|
-
...
|
|
476
|
-
getOrInsert
|
|
477
|
-
return this.has(t) ? this.get(t) : this
|
|
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);
|
|
478
488
|
},
|
|
479
|
-
getOrInsertComputed
|
|
480
|
-
return this.has(t) ? this.get(t) : this
|
|
489
|
+
$getOrInsertComputed: function(t, e) {
|
|
490
|
+
return this.has(t) ? this.get(t) : this.$set1(t, e(t));
|
|
481
491
|
},
|
|
482
|
-
get
|
|
483
|
-
return this.has(t) ? this.get(t) : this
|
|
492
|
+
$get: function(t, e = null) {
|
|
493
|
+
return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? e(t) : e);
|
|
484
494
|
},
|
|
485
|
-
get$async: async function(t, e = null) {
|
|
486
|
-
return this.has(t) ? this.get(t) : this
|
|
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);
|
|
487
497
|
},
|
|
488
498
|
toObject: function() {
|
|
489
499
|
return Object.fromEntries(this);
|
|
@@ -495,16 +505,28 @@ c(Map.prototype, {
|
|
|
495
505
|
return [...this];
|
|
496
506
|
}
|
|
497
507
|
});
|
|
498
|
-
typeof Map.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype
|
|
508
|
+
typeof Map.prototype.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed);
|
|
499
509
|
c(Set, {
|
|
500
510
|
...g()
|
|
501
511
|
});
|
|
502
512
|
c(Set.prototype, {
|
|
503
|
-
...m(["size", "length
|
|
513
|
+
...m(["size", "$length"]),
|
|
504
514
|
...$(Set.prototype, "entries", "keys", "values"),
|
|
505
|
-
...
|
|
506
|
-
...
|
|
507
|
-
...
|
|
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
|
+
},
|
|
508
530
|
toArray: function() {
|
|
509
531
|
return [...this];
|
|
510
532
|
},
|
|
@@ -512,6 +534,7 @@ c(Set.prototype, {
|
|
|
512
534
|
return [...this];
|
|
513
535
|
}
|
|
514
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);
|
|
515
538
|
c(Date, {
|
|
516
539
|
new: function(...t) {
|
|
517
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);
|
|
@@ -573,9 +596,9 @@ c(Date.prototype, {
|
|
|
573
596
|
getMonthDay: function() {
|
|
574
597
|
return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
|
|
575
598
|
},
|
|
576
|
-
expr: function({ y: t = 0, m: e = 0, d: n = 0, h: r = 0, i = 0, s
|
|
577
|
-
const
|
|
578
|
-
return new Date(this.getFullYear() + t, this.getMonth() + e, Math.min(
|
|
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);
|
|
579
602
|
},
|
|
580
603
|
begin: function(t = 3) {
|
|
581
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));
|
|
@@ -609,7 +632,7 @@ c(Promise, {
|
|
|
609
632
|
t = r, e = i;
|
|
610
633
|
}), t, e];
|
|
611
634
|
},
|
|
612
|
-
withResolvers
|
|
635
|
+
$withResolvers: function() {
|
|
613
636
|
let t = null, e = null;
|
|
614
637
|
return { promise: new this((r, i) => {
|
|
615
638
|
t = r, e = i;
|
|
@@ -621,9 +644,9 @@ c(Promise.prototype, {
|
|
|
621
644
|
return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
|
|
622
645
|
}
|
|
623
646
|
});
|
|
624
|
-
typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise
|
|
647
|
+
typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise.$withResolvers);
|
|
625
648
|
c(JSON, {
|
|
626
|
-
parse
|
|
649
|
+
$parse: function(t, e = null) {
|
|
627
650
|
try {
|
|
628
651
|
if (typeof t != "string")
|
|
629
652
|
throw new Error("not string");
|
|
@@ -648,27 +671,27 @@ c(Uint8Array, {
|
|
|
648
671
|
fromString: function(t) {
|
|
649
672
|
return new TextEncoder().encode(t);
|
|
650
673
|
},
|
|
651
|
-
fromHex
|
|
674
|
+
$fromHex: function(t) {
|
|
652
675
|
const e = [];
|
|
653
676
|
for (let n = 0; n < t.length; n += 2)
|
|
654
677
|
e.push(Number.parseInt(t.substring(n, n + 2), 16));
|
|
655
678
|
return new Uint8Array(e);
|
|
656
679
|
},
|
|
657
|
-
fromBase64
|
|
680
|
+
$fromBase64: function(t) {
|
|
658
681
|
const e = [], n = {}, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
659
|
-
for (let
|
|
660
|
-
n[r.charAt(
|
|
682
|
+
for (let s = 0; s < r.length; s++)
|
|
683
|
+
n[r.charAt(s)] = s;
|
|
661
684
|
const i = t.charAt(t.length - 1) != "=" ? t.length : t.charAt(t.length - 2) != "=" ? t.length - 1 : t.length - 2;
|
|
662
|
-
for (let
|
|
663
|
-
const
|
|
664
|
-
e.push((
|
|
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);
|
|
665
688
|
}
|
|
666
689
|
if (i % 4 == 3) {
|
|
667
|
-
const
|
|
668
|
-
e.push((
|
|
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);
|
|
669
692
|
} else if (i % 4 == 2) {
|
|
670
|
-
const
|
|
671
|
-
e.push((
|
|
693
|
+
const s = (n[t.charAt(i - 2)] << 18) + (n[t.charAt(i - 1)] << 12);
|
|
694
|
+
e.push((s & 16711680) >> 16);
|
|
672
695
|
}
|
|
673
696
|
return new Uint8Array(e);
|
|
674
697
|
}
|
|
@@ -678,24 +701,24 @@ c(Uint8Array.prototype, {
|
|
|
678
701
|
const n = Uint8Array.fromString(t);
|
|
679
702
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
680
703
|
},
|
|
681
|
-
setFromHex
|
|
704
|
+
$setFromHex(t, e = 0) {
|
|
682
705
|
const n = Uint8Array.fromHex(t);
|
|
683
706
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
684
707
|
},
|
|
685
|
-
setFromBase64
|
|
708
|
+
$setFromBase64(t, e = 0) {
|
|
686
709
|
const n = Uint8Array.fromBase64(t);
|
|
687
710
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
688
711
|
},
|
|
689
712
|
toString: function() {
|
|
690
713
|
return new TextDecoder().decode(this);
|
|
691
714
|
},
|
|
692
|
-
toHex
|
|
715
|
+
$toHex: function() {
|
|
693
716
|
let t = "";
|
|
694
717
|
for (let e = 0; e < this.length; e++)
|
|
695
718
|
t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
|
|
696
719
|
return t;
|
|
697
720
|
},
|
|
698
|
-
toBase64
|
|
721
|
+
$toBase64: function() {
|
|
699
722
|
let t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
700
723
|
for (let n = 2; n < this.length; n += 3) {
|
|
701
724
|
const r = (this[n - 2] << 16) + (this[n - 1] << 8) + this[n];
|
|
@@ -714,20 +737,21 @@ c(Uint8Array.prototype, {
|
|
|
714
737
|
return new Array(...this);
|
|
715
738
|
}
|
|
716
739
|
});
|
|
717
|
-
typeof Uint8Array.fromBase64 > "u" && (Uint8Array.fromHex = Uint8Array
|
|
718
|
-
|
|
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;
|
|
719
743
|
c(Math, {
|
|
720
744
|
randstr: function(t = 16, e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
|
|
721
745
|
if (t < e)
|
|
722
746
|
throw new Error("randstr: len < slen");
|
|
723
747
|
const i = [];
|
|
724
|
-
for (let
|
|
748
|
+
for (let s = 0; s < t; s++)
|
|
725
749
|
i.push(n.charAt(Math.random() * n.length | 0));
|
|
726
|
-
for (let
|
|
750
|
+
for (let s = /* @__PURE__ */ new Set(), o = 0, u = 0; u < e; u++) {
|
|
727
751
|
do
|
|
728
|
-
|
|
729
|
-
while (
|
|
730
|
-
|
|
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);
|
|
731
755
|
}
|
|
732
756
|
return i.join("");
|
|
733
757
|
},
|
|
@@ -735,13 +759,13 @@ c(Math, {
|
|
|
735
759
|
return Math.floor(Math.random() * (e - t) + t);
|
|
736
760
|
},
|
|
737
761
|
incrid: function() {
|
|
738
|
-
return ++
|
|
762
|
+
return ++D;
|
|
739
763
|
},
|
|
740
764
|
incrstr: function() {
|
|
741
765
|
return "" + Math.incrid();
|
|
742
766
|
},
|
|
743
767
|
uniqid: function(t = Date.now()) {
|
|
744
|
-
return t ===
|
|
768
|
+
return t === A ? t * 2048 + ++w % 2048 : (A = t) * 2048 + (w = 0) % 2048;
|
|
745
769
|
},
|
|
746
770
|
uniqstr: function() {
|
|
747
771
|
return "" + Math.uniqid();
|
|
@@ -751,12 +775,48 @@ c(Math, {
|
|
|
751
775
|
},
|
|
752
776
|
useTemplate: function(t) {
|
|
753
777
|
let e = null;
|
|
754
|
-
const n = { setup(i, { slots:
|
|
755
|
-
return e =
|
|
778
|
+
const n = { setup(i, { slots: s }) {
|
|
779
|
+
return e = s.default, () => {
|
|
756
780
|
};
|
|
757
|
-
}, name: t + "Template" }, r = { setup(i, { attrs:
|
|
758
|
-
return () => e?.(
|
|
781
|
+
}, name: t + "Template" }, r = { setup(i, { attrs: s }) {
|
|
782
|
+
return () => e?.(s);
|
|
759
783
|
}, name: t };
|
|
760
784
|
return { [n.name]: n, [r.name]: r };
|
|
761
785
|
}
|
|
762
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);
|
package/dist/esexts.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u){typeof define=="function"&&define.amd?define(u):u()})((function(){"use strict";function u(t,e){return Object.defineProperties(t,Object.fromEntries(Object.keys(e).map(n=>[n,{value:e[n],enumerable:!1,configurable:!0,writable:!0}])))}function g(){return{new:function(...t){return new this(...t)}}}function m(...t){const e={};for(const n of t){const[r,i]=Array.isArray(n)?n:[n,n+"$"];e[i]=function(){return this[r]}}return e}function l(t,e,n,...r){const i={},o=(s,h,c)=>(h!==null&&s.splice(h>=0?h:s.length+h+1,0,c),s);for(const s of r){const[h,c]=Array.isArray(s)?s:[s,s+"$"+n.toString().replaceAll("-","_")];if(n==="")i[c]=function(...a){return t[h].apply(this,o(a,e,this))};else if(n==="t")i[c]=function(...a){return t[h].apply(this,o(a,e,this)),this};else if(n==="a")i[c]=function(...a){return t[h].apply(this,o(a,e,this)),a};else if(n>=0)i[c]=function(...a){return t[h].apply(this,o(a,e,this)),a[n]};else if(n<0)i[c]=function(...a){return t[h].apply(this,o(a,e,this)),a[a.length+n]};else throw Error("unreachable")}return i}function $(t,...e){const n={};for(const r of e){const[i,o]=Array.isArray(r)?r:[r,r+"$"];n[o]=function(...s){return[...t[i].apply(this,s)]}}return n}function w(t={array:!1}){return function(e={},...n){const r=(i,o)=>{const s=Object.prototype.toString.call(i),h=Object.prototype.toString.call(o);if(s!==h)return o;if(s==="[object Array]")return t.array?i.concat(...o):o;if(s==="[object Object]"){for(const c in o)i[c]=r(i[c],o[c]);return i}else return o};for(const i of n)e=r(e,i);return e}}const b=w({array:!1}),A=w({array:!0});u(Object,{...g(),isObject:function(t){return Object.prototype.toString.call(t)==="[object Object]"},merge$:function(...t){return b(this,...t)},concat$:function(...t){return A(this,...t)}}),u(Object.prototype,{clone$:function(){return JSON.parse(JSON.stringify(this))},length$:function(){return Object.keys(this).length},...l(Object,0,"","entries","keys","values","assign"),...l(JSON,0,"","stringify"),merge$:function(...t){return b(this,...t)},concat$:function(...t){return A(this,...t)},empty$:function(){return Object.keys(this).length==0},in$:function(t){return t in this},pick$:function(...t){const e={};for(const n of t)e[n]=this[n];return e},omit$:function(...t){const e={},n=new Set(t);for(const r in this)n.has(r)||(e[r]=this[r]);return e},attr$:function(...t){if(typeof this!="object")return this;const[e,n,r,i]=t;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},pipe$:function(t,...e){return t(this,...e)},handle$:function(t,...e){return t(this,...e),this},toArray$:function(){return Array.isArray(this)?this:[this]},...l(console,-1,!1,["debug","debug$"],["log","log$"],["info","info$"],["warn","warn$"],["error","error$"],["dir","dir$"]),debugger$:function(...t){console.debug(this,...t);debugger;return this},getParents$:function(t=!1,e=-1,n="parent"){const r=t?[this]:[];let i=this[n];for(;i&&e--!=0;)r.push(i),i=i[n];return r},getChildrens$:function(t=!1,e=-1,n="children"){const r=[],i=(o,s,h)=>{if(s&&r.push(o),!(h==0||!o[n]||o[n].length==0))for(const c of o[n])i(c,!0,h-1)};return i(this,t,e),r},tree$find:function(t,e=!0,n=-1,r="children"){if(e&&t(this))return this;if(n==0||!this[r]||this[r].length==0)return null;for(const i of this[r]){const o=i.tree$find(t,!0,n-1,r);if(o!==null)return o}return null},tree$each:function(t,e=!0,n=-1,r="children"){if(e&&t(this),!(n==0||!this[r]||this[r].length==0)){for(const i of this[r])i.tree$each(t,!0,n-1,r);return this}},tree$map:function(t,e=!0,n=-1,r="children",i=null){const o=e?t(this):this,s=[];if(n==0||!this[r]||this[r].length==0)return o;for(const h of this[r])s.push(h.tree$map(t,!0,n-1,r,i));return o[r]=s,o}}),u(Number.prototype,{...l(Math,0,"",["ceil","ceil"],["floor","floor"],["trunc","trunc"],["abs","abs"],["max","max"],["min","min"]),fixed:function(t=0){return+this.toFixed(t)},round:function(t=0){return Math.round(this*10**t)/10**t},add:function(t,...e){return typeof t=="function"?t(this,...e):this+t},sub:function(t,...e){return typeof t=="function"?t(this,...e):this-t},mul:function(t,...e){return typeof t=="function"?t(this,...e):this*t},div:function(t,...e){return typeof t=="function"?t(this,...e):this/t},baseConvert:function(t=64){let e="",n=this,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(;n>0;)e=r.at(n%t)+e,n=Math.floor(n/t);return e||"0"},unit:function(t,e=0){let n=this,r="";for(const[i,o]of Object.entries(t)){if(r=i,o===0||n<o)break;n=n/o}return e<0?+n.toFixed(0-e)+r:n.toFixed(e)+r},units:function(t,e=!1){let n=this,r=[];for([unit,size]of Object.entries(t))if(size==0||n<size){r.push([n,unit]);break}else r.push([n%size,unit]),n=Math.floor(n/size);return e?r:r.reverse().map(([i,o])=>i+o).join("")},toDate:function(){return Date.new(this)}}),u(BigInt.prototype,{toJSON:function(){return this>=BigInt(Number.MIN_SAFE_INTEGER)&&this<=BigInt(Number.MAX_SAFE_INTEGER)?Number(this):this.toString()}}),u(String.prototype,{...g(),...m(["length","length$"]),substring$:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=e>=0?e:this.length+e,this.substring(t,e)},substr$:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},split$:function(t=",",e=-1){const n=this?this.split(t):[];return e===-1?n:n.push$t(n.splice(e-1).join(t))},split$number:function(t=","){return this.split$(t).map(e=>+e)},split$segment:function(t=1){const e=[];for(let n=0;n<this.length;n+=t)e.push(this.substring(n,n+t));return e},sprintf:function(...t){let[e,...n]=this.split(/%[sd]/);for(let r=0;r<n.length;r++)e+=t[r]+n[r];return e},subOf:function(t,e,n=0,r=0){for(let s=0;s<n&&r!=-1;s++,r++)r=this.indexOf(t,r);let i=this.indexOf(t,r),o=this.indexOf(e,i);return i==-1||o==-1?"":(i+=t.length,this.substring(i,o))},lastSubOf:function(t,e,n=0,r=1/0){for(let s=0;s<n&&r!=-1;s++,r--)r=this.lastIndexOf(t,r);let i=this.lastIndexOf(t,r),o=this.indexOf(e,i);return i==-1||o==-1?"":(i+=t.length,this.substring(i,o))},camel2under:function(){return this.substr(0,1)+this.substr(1).replace(/([A-Z])/g,(t,e)=>"_"+e.toLowerCase())},under2camel:function(){return this.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())},camel2pascal:function(){return this.substr(0,1).toUpperCase()+this.substr(1)},pascal2camel:function(){return this.substr(0,1).toLowerCase()+this.substr(1)},under2kebab:function(){return this.replace(/_/g,"-")},kebab2under:function(){return this.replace(/-/g,"_")},baseConvert:function(t=64){let e=0,n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(let r=0;r<this.length;r++)e=e*t+n.indexOf(this.at(r));return e},fixed:function(...t){return+(+this).toFixed(...t)},toDate:function(){return Date.new(this)},toUint8Array:function(){return new TextEncoder().encode(this)},hexencode:function(){return new TextEncoder().encode(this).toHex()},hexdecode:function(){return new TextDecoder().decode(Uint8Array.fromHex(this))},base64encode:function(){return new TextEncoder().encode(this).toBase64()},base64decode:function(){return new TextDecoder().decode(Uint8Array.fromBase64(this))}}),u(Array,{...g(),range:function(...t){let e=[],n=0,r=0,i=1,o=typeof t[t.length-1]=="boolean"?t.pop():!0,s=typeof t[t.length-1]=="function"?t.pop():(h,c,a)=>h;switch(t.length){case 1:[r]=t;break;case 2:[n,r]=t;break;case 3:[n,r,i]=t;break;default:throw new Error("the number of parameters is incorrect!")}if(i==0)throw new Error("step cannot be 0!");for(let h=0,c=0,a=Math.abs(r-n),p=Math.abs(i),d=n<=r?1:-1;c<a;c+=p)e.push(o?s(n+c*d,h++,e):s());return e}}),u(Array.prototype,{...m("length"),...$(Array.prototype,"entries","keys","values"),...l(Array.prototype,null,"","map"),...l(Array.prototype,null,"t","push","pop","shift","unshift","splice"),...l(Array.prototype,null,"a","push","unshift"),...l(Array.prototype,null,0,"push","unshift"),empty$:function(){return this.length==0},first$:function(t=null){return this.length?this[0]:t},last$:function(t=null){return this.length?this[this.length-1]:t},find$:function(t,e=null){return this.find(t)??e},equals$:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,n)=>e===t[n]))},unique$:function(t=e=>e){const e=new Set;return this.filter(n=>e.has(t(n))?!1:!!e.add(t(n)))},...l(Array.prototype,null,"t",["forEach","each$"]),each$async:async function(t){for(let e=0;e<this.length;e++)await t(this[e],e,this);return this},map$async:async function(t){const e=[];for(let n=0;n<this.length;n++)e.push(await t(this[n],n,this));return e},shuffle:function(t=!1){let e=this.length;for(;e;){const n=Math.random()*e--|0;[this[n],this[e]]=[this[e],this[n]]}return this},toMap:function(t=(e,n)=>[n,e]){return new Map(this.map(t))},toSet:function(t=e=>e){return new Set(this.map(t))},toUint8Array:function(){return new Uint8Array(this)},toBase64:function(){return this.toUint8Array().toBase64()},toHex:function(){return this.toUint8Array().toHex()},decode:function(){return this.toUint8Array().decode()},assoc:function(t,e,n={}){const r=this.unique$(o=>o[t]),i=r.length==0?{}:typeof n=="function"?n(r):n;return this.each$(o=>o[e]=i[o[t]]??null)},toTree:function(t={}){const{id:e="id",pid:n="pid",level:r="level",root:i="root",parent:o="parent",children:s="children",empty:h=null,hasRoot:c=!0}=t,a=this.reduce((f,y)=>f.attr$(y[e],y),{}),p=this.reduce((f,y)=>(f.attr$(y[n],[],!1).attr$(y[n]).push$t(y),f),{}),d=this.length&&c?this.find(f=>f[n]===0):{[e]:0,[n]:-1,[i]:null,[o]:null,[s]:p[0]};u(d,{[i]:d});for(const f of this)u(f,{[i]:d,[o]:a[f[n]]}),f[s]=p[f[e]]||h;return d.tree$each(f=>f[r]=f[o]?f[o][r]+1:0,-1,s),d},tree2tree:function(...t){return this.tree$tree(...t)},tree$tree:function(t={},e=null,n=null){const{id:r="id",pid:i="pid",level:o="level",root:s="root",parent:h="parent",children:c="children",empty:a=null}=t;e=e||{[r]:0,[i]:-1,[o]:0,[s]:null,[h]:null,[c]:this},n=n||e;for(const p of this)u(p,{[s]:e,[h]:n}),p[i]=n[r],p[o]=n[o]+1,p[c]=p[c]&&p[c].length?p[c]:a,p[c]?.tree$tree(t,e,p);return e},tree$find:function(t,e=!0,n=-1,r="children"){for(const i of this){const o=i.tree$find(t,e,n,r);if(o!==null)return o}return null},tree$each:function(t,e=!0,n=-1,r="children"){for(const i of this)i.tree$each(t,e,n,r);return this},tree$map:function(t,e=!0,n=-1,r="children",i=null){return this.map(o=>o.tree$map(t,e,n,r,i))}}),u(Map,{...g()}),u(Map.prototype,{...m(["size","length$"]),...$(Map.prototype,"entries","keys","values"),...l(Map.prototype,null,"t","set","delete"),...l(Map.prototype,null,"a","set","delete"),...l(Map.prototype,null,0,"set","delete"),...l(Map.prototype,null,1,"set","delete"),getOrInsert$:function(t,e=null){return this.has(t)?this.get(t):this.set$1(t,e)},getOrInsertComputed$:function(t,e){return this.has(t)?this.get(t):this.set$1(t,e(t))},get$:function(t,e=null){return this.has(t)?this.get(t):this.set$1(t,typeof e=="function"?e(t):e)},get$async:async function(t,e=null){return this.has(t)?this.get(t):this.set$1(t,typeof e=="function"?await e(t):e)},toObject:function(){return Object.fromEntries(this)},toArray:function(){return[...this]},toJSON:function(){return[...this]}}),typeof Map.getOrInsert>"u"&&(Map.prototype.getOrInsert=Map.prototype.getOrInsert$,Map.prototype.getOrInsertComputed=Map.prototype.getOrInsertComputed$),u(Set,{...g()}),u(Set.prototype,{...m(["size","length$"]),...$(Set.prototype,"entries","keys","values"),...l(Set.prototype,null,"t","add","delete"),...l(Set.prototype,null,"a","add","delete"),...l(Set.prototype,null,0,"add","delete"),toArray:function(){return[...this]},toJSON:function(){return[...this]}}),u(Date,{new:function(...t){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)},format:function(t="y-m-d h:i:s"){return new Date().format(t)},unix:function(){return this.now()/1e3|0},fromUnix:function(t){return new Date((t??0)*1e3)},expr:function(t={}){return new Date().expr(t)},toDayRange:function(){const t=new Date,e=t.getFullYear(),n=t.getMonth(),r=t.getDate(),i=new Date(e,n,r).getTime()/1e3|0;return[i,i+86400-1]},toWeekRange:function(){let t=new Date;for(;t.getDay()!=1;)t=new Date(t.getTime()-86400);const e=t.getFullYear(),n=t.getMonth(),r=t.getDate(),i=new Date(e,n,r).getTime()/1e3|0;return[i,i+86400*7-1]},toMonthRange:function(){const t=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;return[r,i]},toYearRange:function(){const e=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;return[n,r]}}),u(Date.prototype,{format:function(t="y-m-d h:i:s"){if(this.getTime()===0)return"-";const e={y:this.getFullYear(),m:this.getMonth()+1,d:this.getDate(),h:this.getHours(),i:this.getMinutes(),s:this.getSeconds(),l:this.getMilliseconds(),e:this.getMonthDay()};return t.replace(/([ymdhisle])/ig,(n,r)=>r>="A"&&r<="Z"?e[r.toLowerCase()]:e[r].toString().padStart(r==="l"?3:2,"0"))},unix:function(){return this.getTime()/1e3|0},isLeapYear:function(){return this.getFullYear()%4===0&&this.getFullYear()%400!==0},getMonthDay:function(){return[31,0,31,30,31,30,31,31,30,31,30,31][this.getMonth()]||(this.isLeapYear()?29:28)},expr:function({y:t=0,m:e=0,d:n=0,h:r=0,i=0,s:o=0}){const s=new Date(this.getFullYear()+t,this.getMonth()+e+1,0);return new Date(this.getFullYear()+t,this.getMonth()+e,Math.min(s.getDate(),this.getDate())+n,this.getHours()+r,this.getMinutes()+i,this.getSeconds()+o)},begin:function(t=3){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))},end:function(t=3){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))},week:function(t,e=1){let n=new Date(this.getTime());for(;n.getDay()!==t;)n=new Date(n.getTime()+864e5*e);return n},toJSON:function(){return this.getTime()}}),u(RegExp,{...g()}),u(RegExp.prototype,{toJSON:function(){return this.toString()}}),u(Promise,{...g(),channel:function(){let t=null,e=null;return[new this((r,i)=>{t=r,e=i}),t,e]},withResolvers$:function(){let t=null,e=null;return{promise:new this((r,i)=>{t=r,e=i}),resolve:t,reject:e}}}),u(Promise.prototype,{tryCatch:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))}}),typeof Promise.withResolvers>"u"&&(Promise.withResolvers=Promise.withResolvers$),u(JSON,{parse$:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch{return e}}}),typeof Iterator<"u"&&u(Iterator.prototype,{toArray:function(){return[...this]}}),u(ArrayBuffer.prototype,{toUint8Array:function(){return new Uint8Array(this)}}),u(Uint8Array,{...g(),fromString:function(t){return new TextEncoder().encode(t)},fromHex$:function(t){const e=[];for(let n=0;n<t.length;n+=2)e.push(Number.parseInt(t.substring(n,n+2),16));return new Uint8Array(e)},fromBase64$:function(t){const e=[],n={},r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let o=0;o<r.length;o++)n[r.charAt(o)]=o;const i=t.charAt(t.length-1)!="="?t.length:t.charAt(t.length-2)!="="?t.length-1:t.length-2;for(let o=3;o<i;o+=4){const s=(n[t.charAt(o-3)]<<18)+(n[t.charAt(o-2)]<<12)+(n[t.charAt(o-1)]<<6)+n[t.charAt(o)];e.push((s&16711680)>>16,(s&65280)>>8,s&255)}if(i%4==3){const o=(n[t.charAt(i-3)]<<18)+(n[t.charAt(i-2)]<<12)+(n[t.charAt(i-1)]<<6);e.push((o&16711680)>>16,(o&65280)>>8)}else if(i%4==2){const o=(n[t.charAt(i-2)]<<18)+(n[t.charAt(i-1)]<<12);e.push((o&16711680)>>16)}return new Uint8Array(e)}}),u(Uint8Array.prototype,{setFromString(t,e=0){const n=Uint8Array.fromString(t);return this.set(n,e),{read:n.length,written:n.length}},setFromHex$(t,e=0){const n=Uint8Array.fromHex(t);return this.set(n,e),{read:n.length,written:n.length}},setFromBase64$(t,e=0){const n=Uint8Array.fromBase64(t);return this.set(n,e),{read:n.length,written:n.length}},toString:function(){return new TextDecoder().decode(this)},toHex$:function(){let t="";for(let e=0;e<this.length;e++)t+=(this[e]<16?"0":"")+this[e].toString(16);return t},toBase64$:function(){let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let n=2;n<this.length;n+=3){const r=(this[n-2]<<16)+(this[n-1]<<8)+this[n];t+=e.charAt((r&16515072)>>18)+e.charAt((r&258048)>>12)+e.charAt((r&4032)>>6)+e.charAt(r&63)}if(this.length%3==2){const n=(this[this.length-2]<<16)+(this[this.length-1]<<8);t+=e.charAt((n&16515072)>>18)+e.charAt((n&258048)>>12)+e.charAt((n&4032)>>6)+"="}else if(this.length%3==1){const n=this[this.length-1]<<16;t+=e.charAt((n&16515072)>>18)+e.charAt((n&258048)>>12)+"=="}return t},toArray:function(){return new Array(...this)}}),typeof Uint8Array.fromBase64>"u"&&(Uint8Array.fromHex=Uint8Array.fromHex$,Uint8Array.fromBase64=Uint8Array.fromBase64$,Uint8Array.prototype.setFromHex=Uint8Array.prototype.setFromHex$,Uint8Array.prototype.setFromBase64=Uint8Array.prototype.setFromBase64$,Uint8Array.prototype.toHex=Uint8Array.prototype.toHex$,Uint8Array.prototype.toBase64=Uint8Array.prototype.toBase64$);let F=0,x=0,M=0;u(Math,{randstr:function(t=16,e=0,n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",r="~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/"){if(t<e)throw new Error("randstr: len < slen");const i=[];for(let o=0;o<t;o++)i.push(n.charAt(Math.random()*n.length|0));for(let o=new Set,s=0,h=0;h<e;h++){do s=Math.random()*t|0;while(o.has(s));o.set(s,!0),i[s]=r.charAt(Math.random()*r.length|0)}return i.join("")},randint:function(t=0,e=Number.MAX_SAFE_INTEGER){return Math.floor(Math.random()*(e-t)+t)},incrid:function(){return++F},incrstr:function(){return""+Math.incrid()},uniqid:function(t=Date.now()){return t===M?t*2048+ ++x%2048:(M=t)*2048+(x=0)%2048},uniqstr:function(){return""+Math.uniqid()},sleep:function(t){return new Promise(e=>setTimeout(e,t))},useTemplate:function(t){let e=null;const n={setup(i,{slots:o}){return e=o.default,()=>{}},name:t+"Template"},r={setup(i,{attrs:o}){return()=>e?.(o)},name:t};return{[n.name]:n,[r.name]:r}}})}));
|
|
1
|
+
(function(u){typeof define=="function"&&define.amd?define(u):u()})((function(){"use strict";function u(t,e){return Object.defineProperties(t,Object.fromEntries(Object.keys(e).map(n=>[n,{value:e[n],enumerable:!1,configurable:!0,writable:!0}])))}function g(){return{new:function(...t){return new this(...t)}}}function m(...t){const e={};for(const n of t){const[r,i]=Array.isArray(n)?n:[n,"$"+n];e[i]=function(){return this[r]}}return e}function a(t,e,n,...r){const i={},s=(o,h,c)=>(h!==null&&o.splice(h>=0?h:o.length+h+1,0,c),o);for(const o of r){const[h,c]=Array.isArray(o)?o:[o,"$"+o+n.toString().replaceAll("-","_")];if(n==="")i[c]=function(...f){return t[h].apply(this,s(f,e,this))};else if(n==="t")i[c]=function(...f){return t[h].apply(this,s(f,e,this)),this};else if(n==="a")i[c]=function(...f){return t[h].apply(this,s(f,e,this)),f};else if(n>=0)i[c]=function(...f){return t[h].apply(this,s(f,e,this)),f[n]};else if(n<0)i[c]=function(...f){return t[h].apply(this,s(f,e,this)),f[f.length+n]};else throw Error("unreachable")}return i}function $(t,...e){const n={};for(const r of e){const[i,s]=Array.isArray(r)?r:[r,"$"+r];n[s]=function(...o){return[...t[i].apply(this,o)]}}return n}function w(t={array:!1}){return function(e={},...n){const r=(i,s)=>{const o=Object.prototype.toString.call(i),h=Object.prototype.toString.call(s);if(o!==h)return s;if(o==="[object Array]")return t.array?i.concat(...s):s;if(o==="[object Object]"){for(const c in s)i[c]=r(i[c],s[c]);return i}else return s};for(const i of n)e=r(e,i);return e}}const A=w({array:!1}),b=w({array:!0});u(Object,{...g(),isObject:function(t){return Object.prototype.toString.call(t)==="[object Object]"},merge$:function(...t){return A(this,...t)},concat:function(...t){return b(this,...t)}}),u(Object.prototype,{$clone:function(){return JSON.parse(JSON.stringify(this))},$length:function(){return Object.keys(this).length},...a(Object,0,"","entries","keys","values","assign"),...a(JSON,0,"","stringify"),$merge:function(...t){return A(this,...t)},$concat:function(...t){return b(this,...t)},$empty:function(){return Object.keys(this).length==0},$in:function(t){return t in this},$pick:function(...t){const e={};for(const n of t)e[n]=this[n];return e},$omit:function(...t){const e={},n=new Set(t);for(const r in this)n.has(r)||(e[r]=this[r]);return e},$attr:function(...t){if(typeof this!="object")return this;const[e,n,r,i]=t;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},$pipe:function(t,...e){return t(this,...e)},$handle:function(t,...e){return t(this,...e),this},$toArray:function(){return Array.isArray(this)?this:[this]},...a(console,-1,"t",["debug","$debug"],["log","$log"],["info","$info"],["warn","$warn"],["error","$error"],["dir","$dir"]),$debugger:function(...t){console.debug(this,...t);debugger;return this},$getParents:function(t=!1,e=-1,n="parent"){const r=t?[this]:[];let i=this[n];for(;i&&e--!=0;)r.push(i),i=i[n];return r},$getChildrens:function(t=!1,e=-1,n="children"){const r=[],i=(s,o,h)=>{if(o&&r.push(s),!(h==0||!s[n]||s[n].length==0))for(const c of s[n])i(c,!0,h-1)};return i(this,t,e),r},$tree$find:function(t,e=!0,n=-1,r="children"){if(e&&t(this))return this;if(n==0||!this[r]||this[r].length==0)return null;for(const i of this[r]){const s=i.$tree$find(t,!0,n-1,r);if(s!==null)return s}return null},$tree$each:function(t,e=!0,n=-1,r="children"){if(e&&t(this),!(n==0||!this[r]||this[r].length==0)){for(const i of this[r])i.$tree$each(t,!0,n-1,r);return this}},$tree$map:function(t,e=!0,n=-1,r="children",i=null){const s=e?t(this):this,o=[];if(n==0||!this[r]||this[r].length==0)return s;for(const h of this[r])o.push(h.$tree$map(t,!0,n-1,r,i));return s[r]=o,s}}),u(Number.prototype,{...a(Math,0,"",["ceil","ceil"],["floor","floor"],["trunc","trunc"],["abs","abs"],["max","max"],["min","min"]),fixed:function(t=0){return+this.toFixed(t)},round:function(t=0){return Math.round(this*10**t)/10**t},add:function(t,...e){return typeof t=="function"?t(this,...e):this+t},sub:function(t,...e){return typeof t=="function"?t(this,...e):this-t},mul:function(t,...e){return typeof t=="function"?t(this,...e):this*t},div:function(t,...e){return typeof t=="function"?t(this,...e):this/t},baseConvert:function(t=64){let e="",n=this,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(;n>0;)e=r.at(n%t)+e,n=Math.floor(n/t);return e||"0"},unit:function(t,e=0){let n=this,r="";for(const[i,s]of Object.entries(t)){if(r=i,s===0||n<s)break;n=n/s}return e<0?+n.toFixed(0-e)+r:n.toFixed(e)+r},units:function(t,e=!1){let n=this,r=[];for([unit,size]of Object.entries(t))if(size==0||n<size){r.push([n,unit]);break}else r.push([n%size,unit]),n=Math.floor(n/size);return e?r:r.reverse().map(([i,s])=>i+s).join("")},toDate:function(){return Date.new(this)}}),u(BigInt.prototype,{toJSON:function(){return this>=BigInt(Number.MIN_SAFE_INTEGER)&&this<=BigInt(Number.MAX_SAFE_INTEGER)?Number(this):this.toString()}}),u(String.prototype,{...g(),...m(["length","length$"]),$substring:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=e>=0?e:this.length+e,this.substring(t,e)},$substr:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},$split:function(t=",",e=-1){const n=this?this.split(t):[];return e===-1?n:n.$push(n.splice(e-1).join(t))},$split$number:function(t=","){return this.$split(t).map(e=>+e)},$split$segment:function(t=1){const e=[];for(let n=0;n<this.length;n+=t)e.push(this.substring(n,n+t));return e},sprintf:function(...t){let[e,...n]=this.split(/%[sd]/);for(let r=0;r<n.length;r++)e+=t[r]+n[r];return e},subOf:function(t,e,n=0,r=0){for(let o=0;o<n&&r!=-1;o++,r++)r=this.indexOf(t,r);let i=this.indexOf(t,r),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},lastSubOf:function(t,e,n=0,r=1/0){for(let o=0;o<n&&r!=-1;o++,r--)r=this.lastIndexOf(t,r);let i=this.lastIndexOf(t,r),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},camel2under:function(){return this.substr(0,1)+this.substr(1).replace(/([A-Z])/g,(t,e)=>"_"+e.toLowerCase())},under2camel:function(){return this.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())},camel2pascal:function(){return this.substr(0,1).toUpperCase()+this.substr(1)},pascal2camel:function(){return this.substr(0,1).toLowerCase()+this.substr(1)},under2kebab:function(){return this.replace(/_/g,"-")},kebab2under:function(){return this.replace(/-/g,"_")},baseConvert:function(t=64){let e=0,n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(let r=0;r<this.length;r++)e=e*t+n.indexOf(this.at(r));return e},fixed:function(...t){return+(+this).toFixed(...t)},toDate:function(){return Date.new(this)},toUint8Array:function(){return new TextEncoder().encode(this)},hexencode:function(){return new TextEncoder().encode(this).toHex()},hexdecode:function(){return new TextDecoder().decode(Uint8Array.fromHex(this))},base64encode:function(){return new TextEncoder().encode(this).toBase64()},base64decode:function(){return new TextDecoder().decode(Uint8Array.fromBase64(this))}}),u(Array,{...g(),range:function(...t){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():(h,c,f)=>h;switch(t.length){case 1:[r]=t;break;case 2:[n,r]=t;break;case 3:[n,r,i]=t;break;default:throw new Error("the number of parameters is incorrect!")}if(i==0)throw new Error("step cannot be 0!");for(let h=0,c=0,f=Math.abs(r-n),p=Math.abs(i),d=n<=r?1:-1;c<f;c+=p)e.push(s?o(n+c*d,h++,e):o());return e}}),u(Array.prototype,{...m("length"),...$(Array.prototype,"entries","keys","values"),...a(Array.prototype,null,"","map"),...a(Array.prototype,null,"t",["push","$push"],["pop","$pop"],["shift","$shift"],["unshift","$unshift"],["splice","$splice"]),...a(Array.prototype,null,"a","push","unshift"),...a(Array.prototype,null,0,"push","unshift"),$empty:function(){return this.length==0},first:function(t=null){return this.length?this[0]:t},last:function(t=null){return this.length?this[this.length-1]:t},$find:function(t,e=null){return this.find(t)??e},equals:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,n)=>e===t[n]))},unique:function(t=e=>e){const e=new Set;return this.filter(n=>e.has(t(n))?!1:!!e.add(t(n)))},...a(Array.prototype,null,"t",["forEach","each"]),each$async:async function(t){for(let e=0;e<this.length;e++)await t(this[e],e,this);return this},map$async:async function(t){const e=[];for(let n=0;n<this.length;n++)e.push(await t(this[n],n,this));return e},shuffle:function(t=!1){let e=this.length;for(;e;){const n=Math.random()*e--|0;[this[n],this[e]]=[this[e],this[n]]}return this},union:function(t){return Set.new(this).union(Set.new(t)).toArray()},intersection:function(t){return Set.new(this).intersection(Set.new(t)).toArray()},difference:function(t){return Set.new(this).difference(Set.new(t)).toArray()},symmetricDifference:function(t){return Set.new(this).symmetricDifference(Set.new(t)).toArray()},toMap:function(t=(e,n)=>[n,e]){return new Map(this.map(t))},toSet:function(t=e=>e){return new Set(this.map(t))},toUint8Array:function(){return new Uint8Array(this)},toBase64:function(){return this.toUint8Array().toBase64()},toHex:function(){return this.toUint8Array().toHex()},decode:function(){return this.toUint8Array().decode()},assoc:function(t,e,n={}){const r=this.unique$(s=>s[t]),i=r.length==0?{}:typeof n=="function"?n(r):n;return this.each$(s=>s[e]=i[s[t]]??null)},toTree:function(t={}){const{id:e="id",pid:n="pid",level:r="level",root:i="root",parent:s="parent",children:o="children",empty:h=null,hasRoot:c=!0}=t,f=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]};u(d,{[i]:d});for(const l of this)u(l,{[i]:d,[s]:f[l[n]]}),l[o]=p[l[e]]||h;return d.$tree$each(l=>l[r]=l[s]?l[s][r]+1:0,-1,o),d},$tree2tree:function(t={},e=null,n=null){const{id:r="id",pid:i="pid",level:s="level",root:o="root",parent:h="parent",children:c="children",empty:f=null}=t;e=e||{[r]:0,[i]:-1,[s]:0,[o]:null,[h]:null,[c]:this},n=n||e;for(const p of this)u(p,{[o]:e,[h]:n}),p[i]=n[r],p[s]=n[s]+1,p[c]=p[c]&&p[c].length?p[c]:f,p[c]?.$tree2tree(t,e,p);return e},$tree$find:function(t,e=!0,n=-1,r="children"){for(const i of this){const s=i.$tree$find(t,e,n,r);if(s!==null)return s}return null},$tree$each:function(t,e=!0,n=-1,r="children"){for(const i of this)i.$tree$each(t,e,n,r);return this},$tree$map:function(t,e=!0,n=-1,r="children",i=null){return this.map(s=>s.$tree$map(t,e,n,r,i))}}),u(Map,{...g()}),u(Map.prototype,{...m(["size","$length"]),...$(Map.prototype,"entries","keys","values"),...a(Map.prototype,null,"t",["set","$set"],["delete","$delete"]),...a(Map.prototype,null,"a","set","delete"),...a(Map.prototype,null,0,"set","delete"),...a(Map.prototype,null,1,"set","delete"),$getOrInsert:function(t,e=null){return this.has(t)?this.get(t):this.$set1(t,e)},$getOrInsertComputed:function(t,e){return this.has(t)?this.get(t):this.$set1(t,e(t))},$get:function(t,e=null){return this.has(t)?this.get(t):this.$set1(t,typeof e=="function"?e(t):e)},$get$async:async function(t,e=null){return this.has(t)?this.get(t):this.$set1(t,typeof e=="function"?await e(t):e)},toObject:function(){return Object.fromEntries(this)},toArray:function(){return[...this]},toJSON:function(){return[...this]}}),typeof Map.prototype.getOrInsert>"u"&&(Map.prototype.getOrInsert=Map.prototype.$getOrInsert,Map.prototype.getOrInsertComputed=Map.prototype.$getOrInsertComputed),u(Set,{...g()}),u(Set.prototype,{...m(["size","$length"]),...$(Set.prototype,"entries","keys","values"),...a(Set.prototype,null,"t",["add","$add"],["delete","$delete"]),...a(Set.prototype,null,"a","add","delete"),...a(Set.prototype,null,0,"add","delete"),$union:function(t){return new Set([...this,...t])},$intersection:function(t){return new Set([...this].filter(e=>t.has(e)))},$difference:function(t){return new Set([...this].filter(e=>!t.has(e)))},$symmetricDifference:function(t){return new Set([...[...this].filter(e=>!t.has(e)),...[...t].filter(e=>!this.has(e))])},toArray:function(){return[...this]},toJSON:function(){return[...this]}}),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),u(Date,{new:function(...t){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)},format:function(t="y-m-d h:i:s"){return new Date().format(t)},unix:function(){return this.now()/1e3|0},fromUnix:function(t){return new Date((t??0)*1e3)},expr:function(t={}){return new Date().expr(t)},toDayRange:function(){const t=new Date,e=t.getFullYear(),n=t.getMonth(),r=t.getDate(),i=new Date(e,n,r).getTime()/1e3|0;return[i,i+86400-1]},toWeekRange:function(){let t=new Date;for(;t.getDay()!=1;)t=new Date(t.getTime()-86400);const e=t.getFullYear(),n=t.getMonth(),r=t.getDate(),i=new Date(e,n,r).getTime()/1e3|0;return[i,i+86400*7-1]},toMonthRange:function(){const t=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;return[r,i]},toYearRange:function(){const e=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;return[n,r]}}),u(Date.prototype,{format:function(t="y-m-d h:i:s"){if(this.getTime()===0)return"-";const e={y:this.getFullYear(),m:this.getMonth()+1,d:this.getDate(),h:this.getHours(),i:this.getMinutes(),s:this.getSeconds(),l:this.getMilliseconds(),e:this.getMonthDay()};return t.replace(/([ymdhisle])/ig,(n,r)=>r>="A"&&r<="Z"?e[r.toLowerCase()]:e[r].toString().padStart(r==="l"?3:2,"0"))},unix:function(){return this.getTime()/1e3|0},isLeapYear:function(){return this.getFullYear()%4===0&&this.getFullYear()%400!==0},getMonthDay:function(){return[31,0,31,30,31,30,31,31,30,31,30,31][this.getMonth()]||(this.isLeapYear()?29:28)},expr:function({y:t=0,m:e=0,d:n=0,h:r=0,i=0,s=0}){const o=new Date(this.getFullYear()+t,this.getMonth()+e+1,0);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)},begin:function(t=3){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))},end:function(t=3){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))},week:function(t,e=1){let n=new Date(this.getTime());for(;n.getDay()!==t;)n=new Date(n.getTime()+864e5*e);return n},toJSON:function(){return this.getTime()}}),u(RegExp,{...g()}),u(RegExp.prototype,{toJSON:function(){return this.toString()}}),u(Promise,{...g(),channel:function(){let t=null,e=null;return[new this((r,i)=>{t=r,e=i}),t,e]},$withResolvers:function(){let t=null,e=null;return{promise:new this((r,i)=>{t=r,e=i}),resolve:t,reject:e}}}),u(Promise.prototype,{tryCatch:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))}}),typeof Promise.withResolvers>"u"&&(Promise.withResolvers=Promise.$withResolvers),u(JSON,{$parse:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch{return e}}}),typeof Iterator<"u"&&u(Iterator.prototype,{toArray:function(){return[...this]}}),u(ArrayBuffer.prototype,{toUint8Array:function(){return new Uint8Array(this)}}),u(Uint8Array,{...g(),fromString:function(t){return new TextEncoder().encode(t)},$fromHex:function(t){const e=[];for(let n=0;n<t.length;n+=2)e.push(Number.parseInt(t.substring(n,n+2),16));return new Uint8Array(e)},$fromBase64:function(t){const e=[],n={},r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let s=0;s<r.length;s++)n[r.charAt(s)]=s;const i=t.charAt(t.length-1)!="="?t.length:t.charAt(t.length-2)!="="?t.length-1:t.length-2;for(let s=3;s<i;s+=4){const o=(n[t.charAt(s-3)]<<18)+(n[t.charAt(s-2)]<<12)+(n[t.charAt(s-1)]<<6)+n[t.charAt(s)];e.push((o&16711680)>>16,(o&65280)>>8,o&255)}if(i%4==3){const s=(n[t.charAt(i-3)]<<18)+(n[t.charAt(i-2)]<<12)+(n[t.charAt(i-1)]<<6);e.push((s&16711680)>>16,(s&65280)>>8)}else if(i%4==2){const s=(n[t.charAt(i-2)]<<18)+(n[t.charAt(i-1)]<<12);e.push((s&16711680)>>16)}return new Uint8Array(e)}}),u(Uint8Array.prototype,{setFromString(t,e=0){const n=Uint8Array.fromString(t);return this.set(n,e),{read:n.length,written:n.length}},$setFromHex(t,e=0){const n=Uint8Array.fromHex(t);return this.set(n,e),{read:n.length,written:n.length}},$setFromBase64(t,e=0){const n=Uint8Array.fromBase64(t);return this.set(n,e),{read:n.length,written:n.length}},toString:function(){return new TextDecoder().decode(this)},$toHex:function(){let t="";for(let e=0;e<this.length;e++)t+=(this[e]<16?"0":"")+this[e].toString(16);return t},$toBase64:function(){let t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let n=2;n<this.length;n+=3){const r=(this[n-2]<<16)+(this[n-1]<<8)+this[n];t+=e.charAt((r&16515072)>>18)+e.charAt((r&258048)>>12)+e.charAt((r&4032)>>6)+e.charAt(r&63)}if(this.length%3==2){const n=(this[this.length-2]<<16)+(this[this.length-1]<<8);t+=e.charAt((n&16515072)>>18)+e.charAt((n&258048)>>12)+e.charAt((n&4032)>>6)+"="}else if(this.length%3==1){const n=this[this.length-1]<<16;t+=e.charAt((n&16515072)>>18)+e.charAt((n&258048)>>12)+"=="}return t},toArray:function(){return new Array(...this)}}),typeof Uint8Array.fromBase64>"u"&&(Uint8Array.fromHex=Uint8Array.$fromHex,Uint8Array.fromBase64=Uint8Array.$fromBase64),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);let D=0,x=0,S=0;u(Math,{randstr:function(t=16,e=0,n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",r="~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/"){if(t<e)throw new Error("randstr: len < slen");const i=[];for(let s=0;s<t;s++)i.push(n.charAt(Math.random()*n.length|0));for(let s=new Set,o=0,h=0;h<e;h++){do o=Math.random()*t|0;while(s.has(o));s.set(o,!0),i[o]=r.charAt(Math.random()*r.length|0)}return i.join("")},randint:function(t=0,e=Number.MAX_SAFE_INTEGER){return Math.floor(Math.random()*(e-t)+t)},incrid:function(){return++D},incrstr:function(){return""+Math.incrid()},uniqid:function(t=Date.now()){return t===S?t*2048+ ++x%2048:(S=t)*2048+(x=0)%2048},uniqstr:function(){return""+Math.uniqid()},sleep:function(t){return new Promise(e=>setTimeout(e,t))},useTemplate:function(t){let e=null;const n={setup(i,{slots:s}){return e=s.default,()=>{}},name:t+"Template"},r={setup(i,{attrs:s}){return()=>e?.(s)},name:t};return{[n.name]:n,[r.name]:r}}});class M extends Map{constructor(e){super(),this.capacity=e}get(e){if(!super.has(e))return null;const n=super.get(e);return super.delete(e),super.set(e,n),n}getOrInsert(e,n){super.has(e)||super.set(e,n);const r=super.get(e);return super.delete(e),super.set(e,r),r}getOrInsertComputed(e,n){super.has(e)||super.set(e,n(e));const r=super.get(e);return super.delete(e),super.set(e,r),r}async getOrInsertComputedAsync(e,n){super.has(e)||super.set(e,await n(e));const r=super.get(e);return super.delete(e),super.set(e,r),r}set(e,n){super.has(e)&&super.delete(e),super.set(e,n),super.size>this.capacity&&super.delete(super.keys().next().value)}put(e,n){return this.set(e,n)}}u(M,{...g()}),typeof globalThis.LRU>"u"&&(globalThis.LRU=M)}));
|