esexts 2.0.1 → 2.0.3
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 +278 -230
- package/dist/esexts.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/esexts.js
CHANGED
|
@@ -1,192 +1,198 @@
|
|
|
1
1
|
function c(t, e) {
|
|
2
2
|
return Object.defineProperties(t, Object.fromEntries(Object.keys(e).map((n) => [n, { value: e[n], enumerable: !1, configurable: !0, writable: !0 }])));
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function g() {
|
|
5
5
|
return {
|
|
6
6
|
new: function(...t) {
|
|
7
7
|
return new this(...t);
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function m(...t) {
|
|
12
12
|
const e = {};
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
for (const n of t) {
|
|
14
|
+
const [r, i] = Array.isArray(n) ? n : [n, "$" + n];
|
|
15
|
+
e[i] = function() {
|
|
16
|
+
return this[r];
|
|
16
17
|
};
|
|
18
|
+
}
|
|
17
19
|
return e;
|
|
18
20
|
}
|
|
19
|
-
function
|
|
20
|
-
const i = {},
|
|
21
|
-
for (const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
function l(t, e, n, ...r) {
|
|
22
|
+
const i = {}, o = (s, u, h) => (u !== null && s.splice(u >= 0 ? u : s.length + u + 1, 0, h), s);
|
|
23
|
+
for (const s of r) {
|
|
24
|
+
const [u, h] = Array.isArray(s) ? s : [s, "$" + s + n.toString().replaceAll("-", "_")];
|
|
25
|
+
if (n === "")
|
|
26
|
+
i[h] = function(...a) {
|
|
27
|
+
return t[u].apply(this, o(a, e, this));
|
|
25
28
|
};
|
|
26
|
-
else if (n ===
|
|
27
|
-
i[h] = function(...
|
|
28
|
-
return t[
|
|
29
|
+
else if (n === "t")
|
|
30
|
+
i[h] = function(...a) {
|
|
31
|
+
return t[u].apply(this, o(a, e, this)), this;
|
|
29
32
|
};
|
|
30
|
-
else if (n ===
|
|
31
|
-
i[h] = function(...
|
|
32
|
-
return t[
|
|
33
|
+
else if (n === "a")
|
|
34
|
+
i[h] = function(...a) {
|
|
35
|
+
return t[u].apply(this, o(a, e, this)), a;
|
|
33
36
|
};
|
|
34
37
|
else if (n >= 0)
|
|
35
|
-
i[h] = function(...
|
|
36
|
-
return t[
|
|
38
|
+
i[h] = function(...a) {
|
|
39
|
+
return t[u].apply(this, o(a, e, this)), a[n];
|
|
37
40
|
};
|
|
38
41
|
else if (n < 0)
|
|
39
|
-
i[h] = function(...
|
|
40
|
-
return t[
|
|
42
|
+
i[h] = function(...a) {
|
|
43
|
+
return t[u].apply(this, o(a, e, this)), a[a.length + n];
|
|
41
44
|
};
|
|
42
45
|
else
|
|
43
46
|
throw Error("unreachable");
|
|
47
|
+
}
|
|
44
48
|
return i;
|
|
45
49
|
}
|
|
46
|
-
function
|
|
50
|
+
function $(t, ...e) {
|
|
47
51
|
const n = {};
|
|
48
|
-
for (const
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
for (const r of e) {
|
|
53
|
+
const [i, o] = Array.isArray(r) ? r : [r, "$" + r];
|
|
54
|
+
n[o] = function(...s) {
|
|
55
|
+
return [...t[i].apply(this, s)];
|
|
51
56
|
};
|
|
57
|
+
}
|
|
52
58
|
return n;
|
|
53
59
|
}
|
|
54
|
-
function
|
|
60
|
+
function A(t = { array: !1 }) {
|
|
55
61
|
return function(e = {}, ...n) {
|
|
56
|
-
const r = (i,
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
60
|
-
if (
|
|
61
|
-
return t.array ? i.concat(...
|
|
62
|
-
if (
|
|
63
|
-
for (const
|
|
64
|
-
i[
|
|
62
|
+
const r = (i, o) => {
|
|
63
|
+
const s = Object.prototype.toString.call(i), u = Object.prototype.toString.call(o);
|
|
64
|
+
if (s !== u)
|
|
65
|
+
return o;
|
|
66
|
+
if (s === "[object Array]")
|
|
67
|
+
return t.array ? i.concat(...o) : o;
|
|
68
|
+
if (s === "[object Object]") {
|
|
69
|
+
for (const h in o)
|
|
70
|
+
i[h] = r(i[h], o[h]);
|
|
65
71
|
return i;
|
|
66
72
|
} else
|
|
67
|
-
return
|
|
73
|
+
return o;
|
|
68
74
|
};
|
|
69
75
|
for (const i of n)
|
|
70
76
|
e = r(e, i);
|
|
71
77
|
return e;
|
|
72
78
|
};
|
|
73
79
|
}
|
|
74
|
-
const x =
|
|
80
|
+
const x = A({ array: !1 }), M = A({ array: !0 });
|
|
75
81
|
c(Object, {
|
|
76
|
-
...
|
|
82
|
+
...g(),
|
|
77
83
|
isObject: function(t) {
|
|
78
84
|
return Object.prototype.toString.call(t) === "[object Object]";
|
|
79
85
|
},
|
|
80
|
-
|
|
86
|
+
merge$: function(...t) {
|
|
81
87
|
return x(this, ...t);
|
|
82
88
|
},
|
|
83
|
-
|
|
84
|
-
return
|
|
89
|
+
concat: function(...t) {
|
|
90
|
+
return M(this, ...t);
|
|
85
91
|
}
|
|
86
92
|
});
|
|
87
93
|
c(Object.prototype, {
|
|
88
|
-
|
|
94
|
+
$clone: function() {
|
|
89
95
|
return JSON.parse(JSON.stringify(this));
|
|
90
96
|
},
|
|
91
|
-
|
|
97
|
+
$length: function() {
|
|
92
98
|
return Object.keys(this).length;
|
|
93
99
|
},
|
|
94
|
-
...
|
|
95
|
-
...
|
|
96
|
-
|
|
100
|
+
...l(Object, 0, "", "entries", "keys", "values", "assign"),
|
|
101
|
+
...l(JSON, 0, "", "stringify"),
|
|
102
|
+
$merge: function(...t) {
|
|
97
103
|
return x(this, ...t);
|
|
98
104
|
},
|
|
99
|
-
|
|
100
|
-
return
|
|
105
|
+
$concat: function(...t) {
|
|
106
|
+
return M(this, ...t);
|
|
101
107
|
},
|
|
102
|
-
|
|
103
|
-
return
|
|
108
|
+
$empty: function() {
|
|
109
|
+
return Object.keys(this).length == 0;
|
|
104
110
|
},
|
|
105
|
-
|
|
106
|
-
return
|
|
111
|
+
$in: function(t) {
|
|
112
|
+
return t in this;
|
|
107
113
|
},
|
|
108
|
-
|
|
114
|
+
$pick: function(...t) {
|
|
109
115
|
const e = {};
|
|
110
116
|
for (const n of t)
|
|
111
117
|
e[n] = this[n];
|
|
112
118
|
return e;
|
|
113
119
|
},
|
|
114
|
-
|
|
120
|
+
$omit: function(...t) {
|
|
115
121
|
const e = {}, n = new Set(t);
|
|
116
122
|
for (const r in this)
|
|
117
123
|
n.has(r) || (e[r] = this[r]);
|
|
118
124
|
return e;
|
|
119
125
|
},
|
|
120
|
-
|
|
121
|
-
return Object.keys(this).length == 0;
|
|
122
|
-
},
|
|
123
|
-
attr0: function(...t) {
|
|
126
|
+
$attr: function(...t) {
|
|
124
127
|
if (typeof this != "object")
|
|
125
128
|
return this;
|
|
126
129
|
const [e, n, r, i] = t;
|
|
127
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;
|
|
128
131
|
},
|
|
129
|
-
|
|
132
|
+
$pipe: function(t, ...e) {
|
|
130
133
|
return t(this, ...e);
|
|
131
134
|
},
|
|
132
|
-
|
|
135
|
+
$handle: function(t, ...e) {
|
|
133
136
|
return t(this, ...e), this;
|
|
134
137
|
},
|
|
135
|
-
|
|
138
|
+
$toArray: function() {
|
|
136
139
|
return Array.isArray(this) ? this : [this];
|
|
137
140
|
},
|
|
138
|
-
...
|
|
139
|
-
|
|
141
|
+
...l(console, -1, "t", ["debug", "$debug"], ["log", "$log"], ["info", "$info"], ["warn", "$warn"], ["error", "$error"], ["dir", "$dir"]),
|
|
142
|
+
$debugger: function(...t) {
|
|
140
143
|
console.debug(this, ...t);
|
|
141
144
|
debugger;
|
|
142
145
|
return this;
|
|
143
146
|
},
|
|
144
147
|
// ====== Tree ======
|
|
145
|
-
|
|
148
|
+
$getParents: function(t = !1, e = -1, n = "parent") {
|
|
146
149
|
const r = t ? [this] : [];
|
|
147
150
|
let i = this[n];
|
|
148
151
|
for (; i && e-- != 0; )
|
|
149
152
|
r.push(i), i = i[n];
|
|
150
153
|
return r;
|
|
151
154
|
},
|
|
152
|
-
|
|
153
|
-
const r = [], i = (
|
|
154
|
-
if (
|
|
155
|
-
for (const
|
|
156
|
-
i(
|
|
155
|
+
$getChildrens: function(t = !1, e = -1, n = "children") {
|
|
156
|
+
const r = [], i = (o, s, u) => {
|
|
157
|
+
if (s && r.push(o), !(u == 0 || !o[n] || o[n].length == 0))
|
|
158
|
+
for (const h of o[n])
|
|
159
|
+
i(h, !0, u - 1);
|
|
157
160
|
};
|
|
158
161
|
return i(this, t, e), r;
|
|
159
162
|
},
|
|
160
|
-
|
|
163
|
+
$tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
161
164
|
if (e && t(this))
|
|
162
165
|
return this;
|
|
163
166
|
if (n == 0 || !this[r] || this[r].length == 0)
|
|
164
167
|
return null;
|
|
165
168
|
for (const i of this[r]) {
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
169
|
+
const o = i.$tree$find(t, !0, n - 1, r);
|
|
170
|
+
if (o !== null)
|
|
171
|
+
return o;
|
|
169
172
|
}
|
|
170
173
|
return null;
|
|
171
174
|
},
|
|
172
|
-
|
|
175
|
+
$tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
173
176
|
if (e && t(this), !(n == 0 || !this[r] || this[r].length == 0)) {
|
|
174
177
|
for (const i of this[r])
|
|
175
|
-
i
|
|
178
|
+
i.$tree$each(t, !0, n - 1, r);
|
|
176
179
|
return this;
|
|
177
180
|
}
|
|
178
181
|
},
|
|
179
|
-
|
|
180
|
-
const
|
|
182
|
+
$tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
183
|
+
const o = e ? t(this) : this, s = [];
|
|
181
184
|
if (n == 0 || !this[r] || this[r].length == 0)
|
|
182
|
-
return
|
|
183
|
-
for (const
|
|
184
|
-
|
|
185
|
-
return
|
|
185
|
+
return o;
|
|
186
|
+
for (const u of this[r])
|
|
187
|
+
s.push(u.$tree$map(t, !0, n - 1, r, i));
|
|
188
|
+
return o[r] = s, o;
|
|
186
189
|
}
|
|
187
190
|
});
|
|
188
191
|
c(Number.prototype, {
|
|
189
|
-
...
|
|
192
|
+
...l(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
|
+
},
|
|
190
196
|
round: function(t = 0) {
|
|
191
197
|
return Math.round(this * 10 ** t) / 10 ** t;
|
|
192
198
|
},
|
|
@@ -210,10 +216,10 @@ c(Number.prototype, {
|
|
|
210
216
|
},
|
|
211
217
|
unit: function(t, e = 0) {
|
|
212
218
|
let n = this, r = "";
|
|
213
|
-
for (const [i,
|
|
214
|
-
if (r = i,
|
|
219
|
+
for (const [i, o] of Object.entries(t)) {
|
|
220
|
+
if (r = i, o === 0 || n < o)
|
|
215
221
|
break;
|
|
216
|
-
n = n /
|
|
222
|
+
n = n / o;
|
|
217
223
|
}
|
|
218
224
|
return e < 0 ? +n.toFixed(0 - e) + r : n.toFixed(e) + r;
|
|
219
225
|
},
|
|
@@ -225,10 +231,7 @@ c(Number.prototype, {
|
|
|
225
231
|
break;
|
|
226
232
|
} else
|
|
227
233
|
r.push([n % size, unit]), n = Math.floor(n / size);
|
|
228
|
-
return e ? r : r.reverse().map(([i,
|
|
229
|
-
},
|
|
230
|
-
toFixed0: function(t = 0) {
|
|
231
|
-
return +this.toFixed(t);
|
|
234
|
+
return e ? r : r.reverse().map(([i, o]) => i + o).join("");
|
|
232
235
|
},
|
|
233
236
|
toDate: function() {
|
|
234
237
|
return Date.new(this);
|
|
@@ -236,26 +239,26 @@ c(Number.prototype, {
|
|
|
236
239
|
});
|
|
237
240
|
c(BigInt.prototype, {
|
|
238
241
|
toJSON: function() {
|
|
239
|
-
return this
|
|
242
|
+
return this >= BigInt(Number.MIN_SAFE_INTEGER) && this <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(this) : this.toString();
|
|
240
243
|
}
|
|
241
244
|
});
|
|
242
245
|
c(String.prototype, {
|
|
243
|
-
...
|
|
244
|
-
...
|
|
245
|
-
|
|
246
|
+
...g(),
|
|
247
|
+
...m(["length", "length$"]),
|
|
248
|
+
$substring: function(t = 0, e = this.length) {
|
|
246
249
|
return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
|
|
247
250
|
},
|
|
248
|
-
|
|
251
|
+
$substr: function(t = 0, e = this.length) {
|
|
249
252
|
return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
|
|
250
253
|
},
|
|
251
|
-
|
|
254
|
+
$split: function(t = ",", e = -1) {
|
|
252
255
|
const n = this ? this.split(t) : [];
|
|
253
|
-
return e === -1 ? n : n
|
|
256
|
+
return e === -1 ? n : n.$push(n.splice(e - 1).join(t));
|
|
254
257
|
},
|
|
255
|
-
|
|
256
|
-
return this
|
|
258
|
+
$split$number: function(t = ",") {
|
|
259
|
+
return this.$split(t).map((e) => +e);
|
|
257
260
|
},
|
|
258
|
-
|
|
261
|
+
$split$segment: function(t = 1) {
|
|
259
262
|
const e = [];
|
|
260
263
|
for (let n = 0; n < this.length; n += t)
|
|
261
264
|
e.push(this.substring(n, n + t));
|
|
@@ -268,16 +271,16 @@ c(String.prototype, {
|
|
|
268
271
|
return e;
|
|
269
272
|
},
|
|
270
273
|
subOf: function(t, e, n = 0, r = 0) {
|
|
271
|
-
for (let
|
|
274
|
+
for (let s = 0; s < n && r != -1; s++, r++)
|
|
272
275
|
r = this.indexOf(t, r);
|
|
273
|
-
let i = this.indexOf(t, r),
|
|
274
|
-
return i == -1 ||
|
|
276
|
+
let i = this.indexOf(t, r), o = this.indexOf(e, i);
|
|
277
|
+
return i == -1 || o == -1 ? "" : (i += t.length, this.substring(i, o));
|
|
275
278
|
},
|
|
276
279
|
lastSubOf: function(t, e, n = 0, r = 1 / 0) {
|
|
277
|
-
for (let
|
|
280
|
+
for (let s = 0; s < n && r != -1; s++, r--)
|
|
278
281
|
r = this.lastIndexOf(t, r);
|
|
279
|
-
let i = this.lastIndexOf(t, r),
|
|
280
|
-
return i == -1 ||
|
|
282
|
+
let i = this.lastIndexOf(t, r), o = this.indexOf(e, i);
|
|
283
|
+
return i == -1 || o == -1 ? "" : (i += t.length, this.substring(i, o));
|
|
281
284
|
},
|
|
282
285
|
camel2under: function() {
|
|
283
286
|
return this.substr(0, 1) + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
|
|
@@ -303,27 +306,36 @@ c(String.prototype, {
|
|
|
303
306
|
e = e * t + n.indexOf(this.at(r));
|
|
304
307
|
return e;
|
|
305
308
|
},
|
|
306
|
-
|
|
309
|
+
fixed: function(...t) {
|
|
307
310
|
return +(+this).toFixed(...t);
|
|
308
311
|
},
|
|
309
312
|
toDate: function() {
|
|
310
313
|
return Date.new(this);
|
|
311
314
|
},
|
|
312
|
-
|
|
315
|
+
// ====== Uint8Array ======
|
|
316
|
+
toUint8Array: function() {
|
|
313
317
|
return new TextEncoder().encode(this);
|
|
314
318
|
},
|
|
315
|
-
|
|
316
|
-
|
|
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();
|
|
317
329
|
},
|
|
318
330
|
base64decode: function() {
|
|
319
|
-
return Uint8Array.fromBase64(this);
|
|
331
|
+
return new TextDecoder().decode(Uint8Array.fromBase64(this));
|
|
320
332
|
}
|
|
321
333
|
});
|
|
322
334
|
c(Array, {
|
|
323
|
-
...
|
|
335
|
+
...g(),
|
|
324
336
|
// ====== from pinojs ======
|
|
325
337
|
range: function(...t) {
|
|
326
|
-
let e = [], n = 0, r = 0, i = 1,
|
|
338
|
+
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() : (u, h, a) => u;
|
|
327
339
|
switch (t.length) {
|
|
328
340
|
case 1:
|
|
329
341
|
[r] = t;
|
|
@@ -339,127 +351,148 @@ c(Array, {
|
|
|
339
351
|
}
|
|
340
352
|
if (i == 0)
|
|
341
353
|
throw new Error("step cannot be 0!");
|
|
342
|
-
for (let
|
|
343
|
-
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(o ? s(n + h * d, u++, e) : s());
|
|
344
356
|
return e;
|
|
345
357
|
}
|
|
346
358
|
});
|
|
347
359
|
c(Array.prototype, {
|
|
348
|
-
...
|
|
349
|
-
|
|
350
|
-
...
|
|
351
|
-
...
|
|
352
|
-
...
|
|
353
|
-
...
|
|
354
|
-
|
|
360
|
+
...m("length"),
|
|
361
|
+
...$(Array.prototype, "entries", "keys", "values"),
|
|
362
|
+
...l(Array.prototype, null, "", "map"),
|
|
363
|
+
...l(Array.prototype, null, "t", ["push", "$push"], ["pop", "$pop"], ["shift", "$shift"], ["unshift", "$unshift"], ["splice", "$splice"]),
|
|
364
|
+
...l(Array.prototype, null, "a", "push", "unshift"),
|
|
365
|
+
...l(Array.prototype, null, 0, "push", "unshift"),
|
|
366
|
+
$empty: function() {
|
|
367
|
+
return this.length == 0;
|
|
368
|
+
},
|
|
369
|
+
first: function(t = null) {
|
|
355
370
|
return this.length ? this[0] : t;
|
|
356
371
|
},
|
|
357
|
-
|
|
372
|
+
last: function(t = null) {
|
|
358
373
|
return this.length ? this[this.length - 1] : t;
|
|
359
374
|
},
|
|
360
|
-
|
|
375
|
+
$find: function(t, e = null) {
|
|
361
376
|
return this.find(t) ?? e;
|
|
362
377
|
},
|
|
363
|
-
|
|
378
|
+
equals: function(t) {
|
|
364
379
|
return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
|
|
365
380
|
},
|
|
366
|
-
|
|
381
|
+
unique: function(t = (e) => e) {
|
|
367
382
|
const e = /* @__PURE__ */ new Set();
|
|
368
383
|
return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
|
|
369
384
|
},
|
|
370
|
-
...
|
|
371
|
-
|
|
385
|
+
...l(Array.prototype, null, "t", ["forEach", "each"]),
|
|
386
|
+
each$async: async function(t) {
|
|
372
387
|
for (let e = 0; e < this.length; e++)
|
|
373
388
|
await t(this[e], e, this);
|
|
374
389
|
return this;
|
|
375
390
|
},
|
|
376
|
-
|
|
391
|
+
map$async: async function(t) {
|
|
377
392
|
const e = [];
|
|
378
393
|
for (let n = 0; n < this.length; n++)
|
|
379
394
|
e.push(await t(this[n], n, this));
|
|
380
395
|
return e;
|
|
381
396
|
},
|
|
382
397
|
shuffle: function(t = !1) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
[e[r], e[n]] = [e[n], e[r]];
|
|
398
|
+
let e = this.length;
|
|
399
|
+
for (; e; ) {
|
|
400
|
+
const n = Math.random() * e-- | 0;
|
|
401
|
+
[this[n], this[e]] = [this[e], this[n]];
|
|
388
402
|
}
|
|
389
|
-
return
|
|
403
|
+
return this;
|
|
404
|
+
},
|
|
405
|
+
// ====== collection ======
|
|
406
|
+
intersect: function(t) {
|
|
407
|
+
const e = new Set(t);
|
|
408
|
+
return [...new Set(this)].filter((n) => e.has(n));
|
|
409
|
+
},
|
|
410
|
+
union: function(t) {
|
|
411
|
+
return [.../* @__PURE__ */ new Set([...this, ...t])];
|
|
412
|
+
},
|
|
413
|
+
diff: function(t) {
|
|
414
|
+
const e = new Set(t);
|
|
415
|
+
return [...new Set(this)].filter((n) => !e.has(n));
|
|
390
416
|
},
|
|
417
|
+
// ====== convert ======
|
|
391
418
|
toMap: function(t = (e, n) => [n, e]) {
|
|
392
419
|
return new Map(this.map(t));
|
|
393
420
|
},
|
|
394
421
|
toSet: function(t = (e) => e) {
|
|
395
422
|
return new Set(this.map(t));
|
|
396
423
|
},
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
bytes2hex: function() {
|
|
401
|
-
return this.toUint8Array().toHex();
|
|
424
|
+
// ====== Uint8Array ======
|
|
425
|
+
toUint8Array: function() {
|
|
426
|
+
return new Uint8Array(this);
|
|
402
427
|
},
|
|
403
|
-
|
|
428
|
+
toBase64: function() {
|
|
404
429
|
return this.toUint8Array().toBase64();
|
|
405
430
|
},
|
|
406
|
-
|
|
407
|
-
return
|
|
431
|
+
toHex: function() {
|
|
432
|
+
return this.toUint8Array().toHex();
|
|
433
|
+
},
|
|
434
|
+
// ====== TextDecoder ======
|
|
435
|
+
decode: function() {
|
|
436
|
+
return this.toUint8Array().decode();
|
|
408
437
|
},
|
|
409
438
|
// ====== Relational ======
|
|
410
439
|
assoc: function(t, e, n = {}) {
|
|
411
|
-
const r = this.
|
|
412
|
-
return this.
|
|
440
|
+
const r = this.unique$((o) => o[t]), i = r.length == 0 ? {} : typeof n == "function" ? n(r) : n;
|
|
441
|
+
return this.each$((o) => o[e] = i[o[t]] ?? null);
|
|
413
442
|
},
|
|
414
443
|
// ====== Tree ======
|
|
415
444
|
toTree: function(t = {}) {
|
|
416
|
-
const { id: e = "id", pid: n = "pid", level: r = "level", root: i = "root", parent:
|
|
417
|
-
c(
|
|
418
|
-
for (const l of this)
|
|
419
|
-
c(l, { [i]: g, [s]: d[l[n]] }), l[o] = f[l[e]] || h;
|
|
420
|
-
return g.treeEach0((l) => l[r] = l[s] ? l[s][r] + 1 : 0, -1, o), g;
|
|
421
|
-
},
|
|
422
|
-
tree2tree: function(t = {}, e = null, n = null) {
|
|
423
|
-
const { id: r = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: h = "parent", children: u = "children", empty: d = null } = t;
|
|
424
|
-
e = e || { [r]: 0, [i]: -1, [s]: 0, [o]: null, [h]: null, [u]: this }, n = n || e;
|
|
445
|
+
const { id: e = "id", pid: n = "pid", level: r = "level", root: i = "root", parent: o = "parent", children: s = "children", empty: u = null, hasRoot: h = !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(y), f), {}), d = this.length && h ? this.find((f) => f[n] === 0) : { [e]: 0, [n]: -1, [i]: null, [o]: null, [s]: p[0] };
|
|
446
|
+
c(d, { [i]: d });
|
|
425
447
|
for (const f of this)
|
|
426
|
-
c(f, { [
|
|
448
|
+
c(f, { [i]: d, [o]: a[f[n]] }), f[s] = p[f[e]] || u;
|
|
449
|
+
return d.$tree$each((f) => f[r] = f[o] ? f[o][r] + 1 : 0, -1, s), d;
|
|
450
|
+
},
|
|
451
|
+
$tree2tree: function(t = {}, e = null, n = null) {
|
|
452
|
+
const { id: r = "id", pid: i = "pid", level: o = "level", root: s = "root", parent: u = "parent", children: h = "children", empty: a = null } = t;
|
|
453
|
+
e = e || { [r]: 0, [i]: -1, [o]: 0, [s]: null, [u]: null, [h]: this }, n = n || e;
|
|
454
|
+
for (const p of this)
|
|
455
|
+
c(p, { [s]: e, [u]: n }), p[i] = n[r], p[o] = n[o] + 1, p[h] = p[h] && p[h].length ? p[h] : a, p[h]?.$tree2tree(t, e, p);
|
|
427
456
|
return e;
|
|
428
457
|
},
|
|
429
|
-
|
|
458
|
+
$tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
430
459
|
for (const i of this) {
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
433
|
-
return
|
|
460
|
+
const o = i.$tree$find(t, e, n, r);
|
|
461
|
+
if (o !== null)
|
|
462
|
+
return o;
|
|
434
463
|
}
|
|
435
464
|
return null;
|
|
436
465
|
},
|
|
437
|
-
|
|
466
|
+
$tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
438
467
|
for (const i of this)
|
|
439
|
-
i
|
|
468
|
+
i.$tree$each(t, e, n, r);
|
|
440
469
|
return this;
|
|
441
470
|
},
|
|
442
|
-
|
|
443
|
-
return this.map((
|
|
471
|
+
$tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
472
|
+
return this.map((o) => o.$tree$map(t, e, n, r, i));
|
|
444
473
|
}
|
|
445
474
|
});
|
|
446
475
|
c(Map, {
|
|
447
|
-
...
|
|
476
|
+
...g()
|
|
448
477
|
});
|
|
449
478
|
c(Map.prototype, {
|
|
450
|
-
...
|
|
451
|
-
|
|
452
|
-
...
|
|
453
|
-
...
|
|
454
|
-
...
|
|
455
|
-
|
|
456
|
-
|
|
479
|
+
...m(["size", "$length"]),
|
|
480
|
+
...$(Map.prototype, "entries", "keys", "values"),
|
|
481
|
+
...l(Map.prototype, null, "t", ["set", "$set"], ["delete", "$delete"]),
|
|
482
|
+
...l(Map.prototype, null, "a", "set", "delete"),
|
|
483
|
+
...l(Map.prototype, null, 0, "set", "delete"),
|
|
484
|
+
...l(Map.prototype, null, 1, "set", "delete"),
|
|
485
|
+
$getOrInsert: function(t, e = null) {
|
|
486
|
+
return this.has(t) ? this.get(t) : this.$set1(t, e);
|
|
457
487
|
},
|
|
458
|
-
|
|
459
|
-
return this.has(t) ? this.get(t) : this
|
|
488
|
+
$getOrInsertComputed: function(t, e) {
|
|
489
|
+
return this.has(t) ? this.get(t) : this.$set1(t, e(t));
|
|
460
490
|
},
|
|
461
|
-
|
|
462
|
-
return this.has(t) ? this.get(t) : this
|
|
491
|
+
$get: function(t, e = null) {
|
|
492
|
+
return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? e(t) : e);
|
|
493
|
+
},
|
|
494
|
+
$get$async: async function(t, e = null) {
|
|
495
|
+
return this.has(t) ? this.get(t) : this.$set1(t, typeof e == "function" ? await e(t) : e);
|
|
463
496
|
},
|
|
464
497
|
toObject: function() {
|
|
465
498
|
return Object.fromEntries(this);
|
|
@@ -471,15 +504,16 @@ c(Map.prototype, {
|
|
|
471
504
|
return [...this];
|
|
472
505
|
}
|
|
473
506
|
});
|
|
507
|
+
typeof Map.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed);
|
|
474
508
|
c(Set, {
|
|
475
|
-
...
|
|
509
|
+
...g()
|
|
476
510
|
});
|
|
477
511
|
c(Set.prototype, {
|
|
478
|
-
...
|
|
479
|
-
|
|
480
|
-
...
|
|
481
|
-
...
|
|
482
|
-
...
|
|
512
|
+
...m(["size", "$length"]),
|
|
513
|
+
...$(Set.prototype, "entries", "keys", "values"),
|
|
514
|
+
...l(Set.prototype, null, "t", ["add", "$add"], ["delete", "$delete"]),
|
|
515
|
+
...l(Set.prototype, null, "a", "add", "delete"),
|
|
516
|
+
...l(Set.prototype, null, 0, "add", "delete"),
|
|
483
517
|
toArray: function() {
|
|
484
518
|
return [...this];
|
|
485
519
|
},
|
|
@@ -497,8 +531,8 @@ c(Date, {
|
|
|
497
531
|
unix: function() {
|
|
498
532
|
return this.now() / 1e3 | 0;
|
|
499
533
|
},
|
|
500
|
-
fromUnix: function(t
|
|
501
|
-
return new Date((t
|
|
534
|
+
fromUnix: function(t) {
|
|
535
|
+
return new Date((t ?? 0) * 1e3);
|
|
502
536
|
},
|
|
503
537
|
expr: function(t = {}) {
|
|
504
538
|
return (/* @__PURE__ */ new Date()).expr(t);
|
|
@@ -548,9 +582,9 @@ c(Date.prototype, {
|
|
|
548
582
|
getMonthDay: function() {
|
|
549
583
|
return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
|
|
550
584
|
},
|
|
551
|
-
expr: function({ y: t = 0, m: e = 0, d: n = 0, h: r = 0, i = 0, s = 0 }) {
|
|
552
|
-
const
|
|
553
|
-
return new Date(this.getFullYear() + t, this.getMonth() + e, Math.min(
|
|
585
|
+
expr: function({ y: t = 0, m: e = 0, d: n = 0, h: r = 0, i = 0, s: o = 0 }) {
|
|
586
|
+
const s = new Date(this.getFullYear() + t, this.getMonth() + e + 1, 0);
|
|
587
|
+
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);
|
|
554
588
|
},
|
|
555
589
|
begin: function(t = 3) {
|
|
556
590
|
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));
|
|
@@ -569,7 +603,7 @@ c(Date.prototype, {
|
|
|
569
603
|
}
|
|
570
604
|
});
|
|
571
605
|
c(RegExp, {
|
|
572
|
-
...
|
|
606
|
+
...g()
|
|
573
607
|
});
|
|
574
608
|
c(RegExp.prototype, {
|
|
575
609
|
toJSON: function() {
|
|
@@ -577,12 +611,18 @@ c(RegExp.prototype, {
|
|
|
577
611
|
}
|
|
578
612
|
});
|
|
579
613
|
c(Promise, {
|
|
580
|
-
...
|
|
614
|
+
...g(),
|
|
581
615
|
channel: function() {
|
|
582
616
|
let t = null, e = null;
|
|
583
617
|
return [new this((r, i) => {
|
|
584
618
|
t = r, e = i;
|
|
585
619
|
}), t, e];
|
|
620
|
+
},
|
|
621
|
+
$withResolvers: function() {
|
|
622
|
+
let t = null, e = null;
|
|
623
|
+
return { promise: new this((r, i) => {
|
|
624
|
+
t = r, e = i;
|
|
625
|
+
}), resolve: t, reject: e };
|
|
586
626
|
}
|
|
587
627
|
});
|
|
588
628
|
c(Promise.prototype, {
|
|
@@ -590,8 +630,9 @@ c(Promise.prototype, {
|
|
|
590
630
|
return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
|
|
591
631
|
}
|
|
592
632
|
});
|
|
633
|
+
typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise.$withResolvers);
|
|
593
634
|
c(JSON, {
|
|
594
|
-
|
|
635
|
+
$parse: function(t, e = null) {
|
|
595
636
|
try {
|
|
596
637
|
if (typeof t != "string")
|
|
597
638
|
throw new Error("not string");
|
|
@@ -603,7 +644,7 @@ c(JSON, {
|
|
|
603
644
|
});
|
|
604
645
|
typeof Iterator < "u" && c(Iterator.prototype, {
|
|
605
646
|
toArray: function() {
|
|
606
|
-
return
|
|
647
|
+
return [...this];
|
|
607
648
|
}
|
|
608
649
|
});
|
|
609
650
|
c(ArrayBuffer.prototype, {
|
|
@@ -611,39 +652,59 @@ c(ArrayBuffer.prototype, {
|
|
|
611
652
|
return new Uint8Array(this);
|
|
612
653
|
}
|
|
613
654
|
});
|
|
614
|
-
|
|
615
|
-
|
|
655
|
+
c(Uint8Array, {
|
|
656
|
+
...g(),
|
|
657
|
+
fromString: function(t) {
|
|
658
|
+
return new TextEncoder().encode(t);
|
|
659
|
+
},
|
|
660
|
+
$fromHex: function(t) {
|
|
616
661
|
const e = [];
|
|
617
662
|
for (let n = 0; n < t.length; n += 2)
|
|
618
663
|
e.push(Number.parseInt(t.substring(n, n + 2), 16));
|
|
619
664
|
return new Uint8Array(e);
|
|
620
665
|
},
|
|
621
|
-
fromBase64: function(t) {
|
|
666
|
+
$fromBase64: function(t) {
|
|
622
667
|
const e = [], n = {}, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
623
|
-
for (let
|
|
624
|
-
n[r.charAt(
|
|
668
|
+
for (let o = 0; o < r.length; o++)
|
|
669
|
+
n[r.charAt(o)] = o;
|
|
625
670
|
const i = t.charAt(t.length - 1) != "=" ? t.length : t.charAt(t.length - 2) != "=" ? t.length - 1 : t.length - 2;
|
|
626
|
-
for (let
|
|
627
|
-
const
|
|
628
|
-
e.push((
|
|
671
|
+
for (let o = 3; o < i; o += 4) {
|
|
672
|
+
const s = (n[t.charAt(o - 3)] << 18) + (n[t.charAt(o - 2)] << 12) + (n[t.charAt(o - 1)] << 6) + n[t.charAt(o)];
|
|
673
|
+
e.push((s & 16711680) >> 16, (s & 65280) >> 8, s & 255);
|
|
629
674
|
}
|
|
630
675
|
if (i % 4 == 3) {
|
|
631
|
-
const
|
|
632
|
-
e.push((
|
|
676
|
+
const o = (n[t.charAt(i - 3)] << 18) + (n[t.charAt(i - 2)] << 12) + (n[t.charAt(i - 1)] << 6);
|
|
677
|
+
e.push((o & 16711680) >> 16, (o & 65280) >> 8);
|
|
633
678
|
} else if (i % 4 == 2) {
|
|
634
|
-
const
|
|
635
|
-
e.push((
|
|
679
|
+
const o = (n[t.charAt(i - 2)] << 18) + (n[t.charAt(i - 1)] << 12);
|
|
680
|
+
e.push((o & 16711680) >> 16);
|
|
636
681
|
}
|
|
637
682
|
return new Uint8Array(e);
|
|
638
683
|
}
|
|
639
|
-
})
|
|
640
|
-
|
|
684
|
+
});
|
|
685
|
+
c(Uint8Array.prototype, {
|
|
686
|
+
setFromString(t, e = 0) {
|
|
687
|
+
const n = Uint8Array.fromString(t);
|
|
688
|
+
return this.set(n, e), { read: n.length, written: n.length };
|
|
689
|
+
},
|
|
690
|
+
$setFromHex(t, e = 0) {
|
|
691
|
+
const n = Uint8Array.fromHex(t);
|
|
692
|
+
return this.set(n, e), { read: n.length, written: n.length };
|
|
693
|
+
},
|
|
694
|
+
$setFromBase64(t, e = 0) {
|
|
695
|
+
const n = Uint8Array.fromBase64(t);
|
|
696
|
+
return this.set(n, e), { read: n.length, written: n.length };
|
|
697
|
+
},
|
|
698
|
+
toString: function() {
|
|
699
|
+
return new TextDecoder().decode(this);
|
|
700
|
+
},
|
|
701
|
+
$toHex: function() {
|
|
641
702
|
let t = "";
|
|
642
703
|
for (let e = 0; e < this.length; e++)
|
|
643
704
|
t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
|
|
644
705
|
return t;
|
|
645
706
|
},
|
|
646
|
-
toBase64: function() {
|
|
707
|
+
$toBase64: function() {
|
|
647
708
|
let t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
648
709
|
for (let n = 2; n < this.length; n += 3) {
|
|
649
710
|
const r = (this[n - 2] << 16) + (this[n - 1] << 8) + this[n];
|
|
@@ -657,38 +718,25 @@ typeof Uint8Array.fromBase64 > "u" && (c(Uint8Array, {
|
|
|
657
718
|
t += e.charAt((n & 16515072) >> 18) + e.charAt((n & 258048) >> 12) + "==";
|
|
658
719
|
}
|
|
659
720
|
return t;
|
|
660
|
-
}
|
|
661
|
-
}));
|
|
662
|
-
c(Uint8Array, {
|
|
663
|
-
...p()
|
|
664
|
-
});
|
|
665
|
-
c(Uint8Array.prototype, {
|
|
666
|
-
bytes2string: function() {
|
|
667
|
-
return new TextDecoder().decode(this);
|
|
668
|
-
},
|
|
669
|
-
bytes2hex: function() {
|
|
670
|
-
return this.toHex();
|
|
671
|
-
},
|
|
672
|
-
base64encode: function() {
|
|
673
|
-
return this.toBase64();
|
|
674
721
|
},
|
|
675
722
|
toArray: function() {
|
|
676
723
|
return new Array(...this);
|
|
677
724
|
}
|
|
678
725
|
});
|
|
679
|
-
|
|
726
|
+
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);
|
|
727
|
+
let F = 0, w = 0, b = 0;
|
|
680
728
|
c(Math, {
|
|
681
729
|
randstr: function(t = 16, e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
|
|
682
730
|
if (t < e)
|
|
683
731
|
throw new Error("randstr: len < slen");
|
|
684
732
|
const i = [];
|
|
685
|
-
for (let
|
|
733
|
+
for (let o = 0; o < t; o++)
|
|
686
734
|
i.push(n.charAt(Math.random() * n.length | 0));
|
|
687
|
-
for (let
|
|
735
|
+
for (let o = /* @__PURE__ */ new Set(), s = 0, u = 0; u < e; u++) {
|
|
688
736
|
do
|
|
689
|
-
|
|
690
|
-
while (
|
|
691
|
-
|
|
737
|
+
s = Math.random() * t | 0;
|
|
738
|
+
while (o.has(s));
|
|
739
|
+
o.set(s, !0), i[s] = r.charAt(Math.random() * r.length | 0);
|
|
692
740
|
}
|
|
693
741
|
return i.join("");
|
|
694
742
|
},
|
|
@@ -696,13 +744,13 @@ c(Math, {
|
|
|
696
744
|
return Math.floor(Math.random() * (e - t) + t);
|
|
697
745
|
},
|
|
698
746
|
incrid: function() {
|
|
699
|
-
return ++
|
|
747
|
+
return ++F;
|
|
700
748
|
},
|
|
701
749
|
incrstr: function() {
|
|
702
750
|
return "" + Math.incrid();
|
|
703
751
|
},
|
|
704
752
|
uniqid: function(t = Date.now()) {
|
|
705
|
-
return t ===
|
|
753
|
+
return t === b ? t * 2048 + ++w % 2048 : (b = t) * 2048 + (w = 0) % 2048;
|
|
706
754
|
},
|
|
707
755
|
uniqstr: function() {
|
|
708
756
|
return "" + Math.uniqid();
|
|
@@ -712,11 +760,11 @@ c(Math, {
|
|
|
712
760
|
},
|
|
713
761
|
useTemplate: function(t) {
|
|
714
762
|
let e = null;
|
|
715
|
-
const n = { setup(i, { slots:
|
|
716
|
-
return e =
|
|
763
|
+
const n = { setup(i, { slots: o }) {
|
|
764
|
+
return e = o.default, () => {
|
|
717
765
|
};
|
|
718
|
-
}, name: t + "Template" }, r = { setup(i, { attrs:
|
|
719
|
-
return () => e?.(
|
|
766
|
+
}, name: t + "Template" }, r = { setup(i, { attrs: o }) {
|
|
767
|
+
return () => e?.(o);
|
|
720
768
|
}, name: t };
|
|
721
769
|
return { [n.name]: n, [r.name]: r };
|
|
722
770
|
}
|
package/dist/esexts.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h){typeof define=="function"&&define.amd?define(h):h()})((function(){"use strict";function h(t,e){return Object.defineProperties(t,Object.fromEntries(Object.keys(e).map(n=>[n,{value:e[n],enumerable:!1,configurable:!0,writable:!0}])))}function p(){return{new:function(...t){return new this(...t)}}}function b(...t){const e={};for(const[n,r]of t)e[r]=function(){return this[n]};return e}function l(t,e,n,...r){const i={},s=(o,c,u)=>(c!==null&&o.splice(c>=0?c:o.length+c+1,0,u),o);for(const[o,c]of r)if(n===null)i[c]=function(...u){return t[o].apply(this,s(u,e,this))};else if(n===!1)i[c]=function(...u){return t[o].apply(this,s(u,e,this)),this};else if(n===!0)i[c]=function(...u){return t[o].apply(this,s(u,e,this)),u};else if(n>=0)i[c]=function(...u){return t[o].apply(this,s(u,e,this)),u[n]};else if(n<0)i[c]=function(...u){return t[o].apply(this,s(u,e,this)),u[u.length+n]};else throw Error("unreachable");return i}function m(t,...e){const n={};for(const[r,i]of e)n[i]=function(...s){return[...t[r].apply(this,s)]};return n}function w(t={array:!1}){return function(e={},...n){const r=(i,s)=>{const o=Object.prototype.toString.call(i),c=Object.prototype.toString.call(s);if(o!==c)return s;if(o==="[object Array]")return t.array?i.concat(...s):s;if(o==="[object Object]"){for(const u in s)i[u]=r(i[u],s[u]);return i}else return s};for(const i of n)e=r(e,i);return e}}const A=w({array:!1}),M=w({array:!0});h(Object,{...p(),isObject:function(t){return Object.prototype.toString.call(t)==="[object Object]"},merge0:function(...t){return A(this,...t)},concat0:function(...t){return M(this,...t)}}),h(Object.prototype,{clone0:function(){return JSON.parse(JSON.stringify(this))},length0:function(){return Object.keys(this).length},...l(Object,0,null,["entries","entries0"],["keys","keys0"],["values","values0"],["assign","assign0"]),...l(JSON,0,null,["stringify","stringify0"]),merge0:function(...t){return A(this,...t)},concat0:function(...t){return M(this,...t)},in0:function(t){return t in this},map0:function(t=(n,r,i)=>[n,r],e=0){return Object.entries(this).map(([n,r])=>t(n,r,e++))},pick0:function(...t){const e={};for(const n of t)e[n]=this[n];return e},omit0:function(...t){const e={},n=new Set(t);for(const r in this)n.has(r)||(e[r]=this[r]);return e},empty0:function(...t){return Object.keys(this).length==0},attr0: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},pipe0:function(t,...e){return t(this,...e)},handle0:function(t,...e){return t(this,...e),this},toArray0:function(){return Array.isArray(this)?this:[this]},...l(console,-1,!1,["debug","debug0"],["log","log0"],["info","info0"],["warn","warn0"],["error","error0"],["dir","dir0"]),debugger0:function(...t){console.debug(this,...t);debugger;return this},getParents0: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},getChildrens0:function(t=!1,e=-1,n="children"){const r=[],i=(s,o,c)=>{if(o&&r.push(s),!(c==0||!s[n]||s[n].length==0))for(const u of s[n])i(u,!0,c-1)};return i(this,t,e),r},treeFind0: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.treeFind0(t,!0,n-1,r);if(s!==null)return s}return null},treeEach0: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.treeEach0(t,!0,n-1,r);return this}},treeMap0: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 c of this[r])o.push(c.treeMap0(t,!0,n-1,r,i));return s[r]=o,s}}),h(Number.prototype,{...l(Math,0,null,["ceil","ceil"],["floor","floor"],["trunc","trunc"],["abs","abs"],["max","max"],["min","min"]),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("")},toFixed0:function(t=0){return+this.toFixed(t)},toDate:function(){return Date.new(this)}}),h(BigInt.prototype,{toJSON:function(){return this<BigInt(Number.MIN_SAFE_INTEGER)||this>BigInt(Number.MAX_SAFE_INTEGER)?this.toString():Number(this)}}),h(String.prototype,{...p(),...b(["length","length0"]),substring0: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)},substr0:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},split0:function(t=",",e=-1){const n=this?this.split(t):[];return e===-1?n:n.push0(n.splice(e-1).join(t))},splitNumber:function(t=","){return this.split0(t).map(e=>+e)},splitSegment: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},toFixed0:function(...t){return+(+this).toFixed(...t)},toDate:function(){return Date.new(this)},string2bytes:function(){return new TextEncoder().encode(this)},hex2bytes:function(){return Uint8Array.fromHex(this)},base64decode:function(){return Uint8Array.fromBase64(this)}}),h(Array,{...p(),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():(c,u,d)=>c;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 c=0,u=0,d=Math.abs(r-n),f=Math.abs(i),g=n<=r?1:-1;u<d;u+=f)e.push(s?o(n+u*g,c++,e):o());return e}}),h(Array.prototype,{...b(["length","length0"]),...m(Array.prototype,["entries","entries0"],["keys","keys0"],["values","values0"]),...l(Array.prototype,null,!1,["push","push0"],["pop","pop0"],["shift","shift0"],["unshift","unshift0"]),...l(Array.prototype,null,0,["push","push1"],["unshift","unshift1"]),...l(Array.prototype,null,!0,["push","push3"],["unshift","unshift3"]),...l(Array.prototype,null,!0,["splice","splice0"]),first0:function(t=null){return this.length?this[0]:t},last0:function(t=null){return this.length?this[this.length-1]:t},find0:function(t,e=null){return this.find(t)??e},equals0:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,n)=>e===t[n]))},unique0: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,!1,["forEach","each0"]),eachAsync:async function(t){for(let e=0;e<this.length;e++)await t(this[e],e,this);return this},mapAsync: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){const e=t?e.clone0():e;let n=e.length;for(;n;){const r=Math.random()*n--|0;[e[r],e[n]]=[e[n],e[r]]}return e},toMap:function(t=(e,n)=>[n,e]){return new Map(this.map(t))},toSet:function(t=e=>e){return new Set(this.map(t))},bytes2string:function(){return this.toUint8Array().bytes2string()},bytes2hex:function(){return this.toUint8Array().toHex()},base64encode:function(){return this.toUint8Array().toBase64()},toUint8Array:function(){return new Uint8Array(this)},assoc:function(t,e,n={}){const r=this.unique0(s=>s[t]),i=r.length==0?{}:typeof n=="function"?n(r):n;return this.each0(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:c=null,hasRoot:u=!0}=t,d=this.reduce((a,y)=>a.attr0(y[e],y),{}),f=this.reduce((a,y)=>(a.attr0(y[n],[],!1).attr0(y[n]).push0(y),a),{}),g=this.length&&u?this.find(a=>a[n]===0):{[e]:0,[n]:-1,[i]:null,[s]:null,[o]:f[0]};h(g,{[i]:g});for(const a of this)h(a,{[i]:g,[s]:d[a[n]]}),a[o]=f[a[e]]||c;return g.treeEach0(a=>a[r]=a[s]?a[s][r]+1:0,-1,o),g},tree2tree:function(t={},e=null,n=null){const{id:r="id",pid:i="pid",level:s="level",root:o="root",parent:c="parent",children:u="children",empty:d=null}=t;e=e||{[r]:0,[i]:-1,[s]:0,[o]:null,[c]:null,[u]:this},n=n||e;for(const f of this)h(f,{[o]:e,[c]:n}),f[i]=n[r],f[s]=n[s]+1,f[u]=f[u]&&f[u].length?f[u]:d,f[u]?.tree2tree(t,e,f);return e},treeFind0:function(t,e=!0,n=-1,r="children"){for(const i of this){const s=i.treeFind0(t,e,n,r);if(s!==null)return s}return null},treeEach0:function(t,e=!0,n=-1,r="children"){for(const i of this)i.treeEach0(t,e,n,r);return this},treeMap0:function(t,e=!0,n=-1,r="children",i=null){return this.map(s=>s.treeMap0(t,e,n,r,i))}}),h(Map,{...p()}),h(Map.prototype,{...b(["size","length0"]),...m(Map.prototype,["entries","entries0"],["keys","keys0"],["values","values0"]),...l(Map.prototype,null,!1,["set","set0"],["delete","delete0"]),...l(Map.prototype,null,0,["set","set1"],["delete","delete1"]),...l(Map.prototype,null,!0,["set","set3"],["delete","delete3"]),get0:function(t,e=null){return this.has(t)?this.get(t):e},get1:function(t,e,...n){return this.has(t)?this.get(t):this.set3(t,e(t,...n))[1]},getAsync1:async function(t,e,...n){return this.has(t)?this.get(t):this.set3(t,await e(t,...n))[1]},toObject:function(){return Object.fromEntries(this)},toArray:function(){return[...this]},toJSON:function(){return[...this]}}),h(Set,{...p()}),h(Set.prototype,{...b(["size","length0"]),...m(Set.prototype,["entries","entries0"],["keys","keys0"],["values","values0"]),...l(Set.prototype,null,!1,["add","add0"],["delete","delete0"]),...l(Set.prototype,null,0,["add","add1"],["delete","delete1"]),...l(Set.prototype,null,!0,["add","add3"],["delete","delete3"]),toArray:function(){return[...this]},toJSON:function(){return[...this]}}),h(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=0){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]}}),h(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()}}),h(RegExp,{...p()}),h(RegExp.prototype,{toJSON:function(){return this.toString()}}),h(Promise,{...p(),channel:function(){let t=null,e=null;return[new this((r,i)=>{t=r,e=i}),t,e]}}),h(Promise.prototype,{tryCatch:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))}}),h(JSON,{parse0:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch{return e}}}),typeof Iterator<"u"&&h(Iterator.prototype,{toArray:function(){return Array.from(this)}}),h(ArrayBuffer.prototype,{toUint8Array:function(){return new Uint8Array(this)}}),typeof Uint8Array.fromBase64>"u"&&(h(Uint8Array,{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)}}),h(Uint8Array.prototype,{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}})),h(Uint8Array,{...p()}),h(Uint8Array.prototype,{bytes2string:function(){return new TextDecoder().decode(this)},bytes2hex:function(){return this.toHex()},base64encode:function(){return this.toBase64()},toArray:function(){return new Array(...this)}});let D=0,x=0,F=0;h(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,c=0;c<e;c++){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===F?t*2048+ ++x%2048:(F=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}}})}));
|
|
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,"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=(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(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","$push"],["pop","$pop"],["shift","$shift"],["unshift","$unshift"],["splice","$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},intersect:function(t){const e=new Set(t);return[...new Set(this)].filter(n=>e.has(n))},union:function(t){return[...new Set([...this,...t])]},diff:function(t){const e=new Set(t);return[...new Set(this)].filter(n=>!e.has(n))},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(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={},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]?.$tree2tree(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","$set"],["delete","$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.$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.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","$add"],["delete","$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}}})}));
|