esexts 2.0.2 → 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 +90 -81
- package/dist/esexts.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/esexts.js
CHANGED
|
@@ -11,7 +11,7 @@ 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
|
};
|
|
@@ -21,7 +21,7 @@ function m(...t) {
|
|
|
21
21
|
function l(t, e, n, ...r) {
|
|
22
22
|
const i = {}, o = (s, u, h) => (u !== null && s.splice(u >= 0 ? u : s.length + u + 1, 0, h), s);
|
|
23
23
|
for (const s of r) {
|
|
24
|
-
const [u, h] = Array.isArray(s) ? s : [s,
|
|
24
|
+
const [u, h] = Array.isArray(s) ? s : [s, "$" + s + n.toString().replaceAll("-", "_")];
|
|
25
25
|
if (n === "")
|
|
26
26
|
i[h] = function(...a) {
|
|
27
27
|
return t[u].apply(this, o(a, e, this));
|
|
@@ -50,7 +50,7 @@ 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, o] = Array.isArray(r) ? r : [r,
|
|
53
|
+
const [i, o] = Array.isArray(r) ? r : [r, "$" + r];
|
|
54
54
|
n[o] = function(...s) {
|
|
55
55
|
return [...t[i].apply(this, s)];
|
|
56
56
|
};
|
|
@@ -86,73 +86,73 @@ c(Object, {
|
|
|
86
86
|
merge$: function(...t) {
|
|
87
87
|
return x(this, ...t);
|
|
88
88
|
},
|
|
89
|
-
concat
|
|
89
|
+
concat: function(...t) {
|
|
90
90
|
return M(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
100
|
...l(Object, 0, "", "entries", "keys", "values", "assign"),
|
|
101
101
|
...l(JSON, 0, "", "stringify"),
|
|
102
|
-
merge
|
|
102
|
+
$merge: function(...t) {
|
|
103
103
|
return x(this, ...t);
|
|
104
104
|
},
|
|
105
|
-
concat
|
|
105
|
+
$concat: function(...t) {
|
|
106
106
|
return M(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
|
-
...l(console, -1,
|
|
142
|
-
debugger
|
|
141
|
+
...l(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
|
|
155
|
+
$getChildrens: function(t = !1, e = -1, n = "children") {
|
|
156
156
|
const r = [], i = (o, s, u) => {
|
|
157
157
|
if (s && r.push(o), !(u == 0 || !o[n] || o[n].length == 0))
|
|
158
158
|
for (const h of o[n])
|
|
@@ -160,31 +160,31 @@ c(Object.prototype, {
|
|
|
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 o = i
|
|
169
|
+
const o = i.$tree$find(t, !0, n - 1, r);
|
|
170
170
|
if (o !== null)
|
|
171
171
|
return o;
|
|
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) {
|
|
182
|
+
$tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
183
183
|
const o = e ? t(this) : this, s = [];
|
|
184
184
|
if (n == 0 || !this[r] || this[r].length == 0)
|
|
185
185
|
return o;
|
|
186
186
|
for (const u of this[r])
|
|
187
|
-
s.push(u
|
|
187
|
+
s.push(u.$tree$map(t, !0, n - 1, r, i));
|
|
188
188
|
return o[r] = s, o;
|
|
189
189
|
}
|
|
190
190
|
});
|
|
@@ -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));
|
|
@@ -351,8 +351,8 @@ 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(o ? s(n + h *
|
|
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());
|
|
356
356
|
return e;
|
|
357
357
|
}
|
|
358
358
|
});
|
|
@@ -360,29 +360,29 @@ c(Array.prototype, {
|
|
|
360
360
|
...m("length"),
|
|
361
361
|
...$(Array.prototype, "entries", "keys", "values"),
|
|
362
362
|
...l(Array.prototype, null, "", "map"),
|
|
363
|
-
...l(Array.prototype, null, "t", "push", "pop", "shift", "unshift", "splice"),
|
|
363
|
+
...l(Array.prototype, null, "t", ["push", "$push"], ["pop", "$pop"], ["shift", "$shift"], ["unshift", "$unshift"], ["splice", "$splice"]),
|
|
364
364
|
...l(Array.prototype, null, "a", "push", "unshift"),
|
|
365
365
|
...l(Array.prototype, null, 0, "push", "unshift"),
|
|
366
|
-
empty
|
|
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
|
-
...l(Array.prototype, null, "t", ["forEach", "each
|
|
385
|
+
...l(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,18 @@ c(Array.prototype, {
|
|
|
402
402
|
}
|
|
403
403
|
return this;
|
|
404
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));
|
|
416
|
+
},
|
|
405
417
|
// ====== convert ======
|
|
406
418
|
toMap: function(t = (e, n) => [n, e]) {
|
|
407
419
|
return new Map(this.map(t));
|
|
@@ -430,60 +442,57 @@ c(Array.prototype, {
|
|
|
430
442
|
},
|
|
431
443
|
// ====== Tree ======
|
|
432
444
|
toTree: function(t = {}) {
|
|
433
|
-
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,
|
|
434
|
-
c(
|
|
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 });
|
|
435
447
|
for (const f of this)
|
|
436
|
-
c(f, { [i]:
|
|
437
|
-
return
|
|
438
|
-
},
|
|
439
|
-
tree2tree: function(...t) {
|
|
440
|
-
return this.tree$tree(...t);
|
|
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;
|
|
441
450
|
},
|
|
442
|
-
|
|
451
|
+
$tree2tree: function(t = {}, e = null, n = null) {
|
|
443
452
|
const { id: r = "id", pid: i = "pid", level: o = "level", root: s = "root", parent: u = "parent", children: h = "children", empty: a = null } = t;
|
|
444
453
|
e = e || { [r]: 0, [i]: -1, [o]: 0, [s]: null, [u]: null, [h]: this }, n = n || e;
|
|
445
454
|
for (const p of this)
|
|
446
|
-
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]
|
|
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);
|
|
447
456
|
return e;
|
|
448
457
|
},
|
|
449
|
-
tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
458
|
+
$tree$find: function(t, e = !0, n = -1, r = "children") {
|
|
450
459
|
for (const i of this) {
|
|
451
|
-
const o = i
|
|
460
|
+
const o = i.$tree$find(t, e, n, r);
|
|
452
461
|
if (o !== null)
|
|
453
462
|
return o;
|
|
454
463
|
}
|
|
455
464
|
return null;
|
|
456
465
|
},
|
|
457
|
-
tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
466
|
+
$tree$each: function(t, e = !0, n = -1, r = "children") {
|
|
458
467
|
for (const i of this)
|
|
459
|
-
i
|
|
468
|
+
i.$tree$each(t, e, n, r);
|
|
460
469
|
return this;
|
|
461
470
|
},
|
|
462
|
-
tree$map: function(t, e = !0, n = -1, r = "children", i = null) {
|
|
463
|
-
return this.map((o) => o
|
|
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));
|
|
464
473
|
}
|
|
465
474
|
});
|
|
466
475
|
c(Map, {
|
|
467
476
|
...g()
|
|
468
477
|
});
|
|
469
478
|
c(Map.prototype, {
|
|
470
|
-
...m(["size", "length
|
|
479
|
+
...m(["size", "$length"]),
|
|
471
480
|
...$(Map.prototype, "entries", "keys", "values"),
|
|
472
|
-
...l(Map.prototype, null, "t", "set", "delete"),
|
|
481
|
+
...l(Map.prototype, null, "t", ["set", "$set"], ["delete", "$delete"]),
|
|
473
482
|
...l(Map.prototype, null, "a", "set", "delete"),
|
|
474
483
|
...l(Map.prototype, null, 0, "set", "delete"),
|
|
475
484
|
...l(Map.prototype, null, 1, "set", "delete"),
|
|
476
|
-
getOrInsert
|
|
477
|
-
return this.has(t) ? this.get(t) : this
|
|
485
|
+
$getOrInsert: function(t, e = null) {
|
|
486
|
+
return this.has(t) ? this.get(t) : this.$set1(t, e);
|
|
478
487
|
},
|
|
479
|
-
getOrInsertComputed
|
|
480
|
-
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));
|
|
481
490
|
},
|
|
482
|
-
get
|
|
483
|
-
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);
|
|
484
493
|
},
|
|
485
|
-
get$async: async function(t, e = null) {
|
|
486
|
-
return this.has(t) ? this.get(t) : this
|
|
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);
|
|
487
496
|
},
|
|
488
497
|
toObject: function() {
|
|
489
498
|
return Object.fromEntries(this);
|
|
@@ -495,14 +504,14 @@ c(Map.prototype, {
|
|
|
495
504
|
return [...this];
|
|
496
505
|
}
|
|
497
506
|
});
|
|
498
|
-
typeof Map.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype
|
|
507
|
+
typeof Map.getOrInsert > "u" && (Map.prototype.getOrInsert = Map.prototype.$getOrInsert, Map.prototype.getOrInsertComputed = Map.prototype.$getOrInsertComputed);
|
|
499
508
|
c(Set, {
|
|
500
509
|
...g()
|
|
501
510
|
});
|
|
502
511
|
c(Set.prototype, {
|
|
503
|
-
...m(["size", "length
|
|
512
|
+
...m(["size", "$length"]),
|
|
504
513
|
...$(Set.prototype, "entries", "keys", "values"),
|
|
505
|
-
...l(Set.prototype, null, "t", "add", "delete"),
|
|
514
|
+
...l(Set.prototype, null, "t", ["add", "$add"], ["delete", "$delete"]),
|
|
506
515
|
...l(Set.prototype, null, "a", "add", "delete"),
|
|
507
516
|
...l(Set.prototype, null, 0, "add", "delete"),
|
|
508
517
|
toArray: function() {
|
|
@@ -609,7 +618,7 @@ c(Promise, {
|
|
|
609
618
|
t = r, e = i;
|
|
610
619
|
}), t, e];
|
|
611
620
|
},
|
|
612
|
-
withResolvers
|
|
621
|
+
$withResolvers: function() {
|
|
613
622
|
let t = null, e = null;
|
|
614
623
|
return { promise: new this((r, i) => {
|
|
615
624
|
t = r, e = i;
|
|
@@ -621,9 +630,9 @@ c(Promise.prototype, {
|
|
|
621
630
|
return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
|
|
622
631
|
}
|
|
623
632
|
});
|
|
624
|
-
typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise
|
|
633
|
+
typeof Promise.withResolvers > "u" && (Promise.withResolvers = Promise.$withResolvers);
|
|
625
634
|
c(JSON, {
|
|
626
|
-
parse
|
|
635
|
+
$parse: function(t, e = null) {
|
|
627
636
|
try {
|
|
628
637
|
if (typeof t != "string")
|
|
629
638
|
throw new Error("not string");
|
|
@@ -648,13 +657,13 @@ c(Uint8Array, {
|
|
|
648
657
|
fromString: function(t) {
|
|
649
658
|
return new TextEncoder().encode(t);
|
|
650
659
|
},
|
|
651
|
-
fromHex
|
|
660
|
+
$fromHex: function(t) {
|
|
652
661
|
const e = [];
|
|
653
662
|
for (let n = 0; n < t.length; n += 2)
|
|
654
663
|
e.push(Number.parseInt(t.substring(n, n + 2), 16));
|
|
655
664
|
return new Uint8Array(e);
|
|
656
665
|
},
|
|
657
|
-
fromBase64
|
|
666
|
+
$fromBase64: function(t) {
|
|
658
667
|
const e = [], n = {}, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
659
668
|
for (let o = 0; o < r.length; o++)
|
|
660
669
|
n[r.charAt(o)] = o;
|
|
@@ -678,24 +687,24 @@ c(Uint8Array.prototype, {
|
|
|
678
687
|
const n = Uint8Array.fromString(t);
|
|
679
688
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
680
689
|
},
|
|
681
|
-
setFromHex
|
|
690
|
+
$setFromHex(t, e = 0) {
|
|
682
691
|
const n = Uint8Array.fromHex(t);
|
|
683
692
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
684
693
|
},
|
|
685
|
-
setFromBase64
|
|
694
|
+
$setFromBase64(t, e = 0) {
|
|
686
695
|
const n = Uint8Array.fromBase64(t);
|
|
687
696
|
return this.set(n, e), { read: n.length, written: n.length };
|
|
688
697
|
},
|
|
689
698
|
toString: function() {
|
|
690
699
|
return new TextDecoder().decode(this);
|
|
691
700
|
},
|
|
692
|
-
toHex
|
|
701
|
+
$toHex: function() {
|
|
693
702
|
let t = "";
|
|
694
703
|
for (let e = 0; e < this.length; e++)
|
|
695
704
|
t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
|
|
696
705
|
return t;
|
|
697
706
|
},
|
|
698
|
-
toBase64
|
|
707
|
+
$toBase64: function() {
|
|
699
708
|
let t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
700
709
|
for (let n = 2; n < this.length; n += 3) {
|
|
701
710
|
const r = (this[n - 2] << 16) + (this[n - 1] << 8) + this[n];
|
|
@@ -714,7 +723,7 @@ c(Uint8Array.prototype, {
|
|
|
714
723
|
return new Array(...this);
|
|
715
724
|
}
|
|
716
725
|
});
|
|
717
|
-
typeof Uint8Array.fromBase64 > "u" && (Uint8Array.fromHex = Uint8Array
|
|
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);
|
|
718
727
|
let F = 0, w = 0, b = 0;
|
|
719
728
|
c(Math, {
|
|
720
729
|
randstr: function(t = 16, e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", r = "~!@#$%^&*()_+`{}|[]\\:\";'<>,.?/") {
|
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 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}}})}));
|