esexts 1.2.5 → 1.2.7
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.es2018.js +1002 -0
- package/dist/esexts.es2018.umd.cjs +1 -0
- package/dist/esexts.js +442 -700
- package/dist/esexts.umd.cjs +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,1002 @@
|
|
|
1
|
+
const l = Object.defineProperties, r = { enumerable: !1, configurable: !0, writable: !0 };
|
|
2
|
+
function p(t = { array: !1 }) {
|
|
3
|
+
return function(e = {}, ...n) {
|
|
4
|
+
const u = (i, s) => {
|
|
5
|
+
const o = Object.prototype.toString.call(i), f = Object.prototype.toString.call(s);
|
|
6
|
+
if (o !== f)
|
|
7
|
+
return s;
|
|
8
|
+
if (o === "[object Array]")
|
|
9
|
+
return t.array ? i.concat(...s) : s;
|
|
10
|
+
if (o === "[object Object]") {
|
|
11
|
+
for (const c in s)
|
|
12
|
+
i[c] = u(i[c], s[c]);
|
|
13
|
+
return i;
|
|
14
|
+
} else
|
|
15
|
+
return s;
|
|
16
|
+
};
|
|
17
|
+
for (const i of n)
|
|
18
|
+
e = u(e, i);
|
|
19
|
+
return e;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const b = p({ array: !1 }), d = p({ array: !0 });
|
|
23
|
+
l(Object, {
|
|
24
|
+
isObject: {
|
|
25
|
+
value: function(t) {
|
|
26
|
+
return Object.prototype.toString.call(t) === "[object Object]";
|
|
27
|
+
},
|
|
28
|
+
...r
|
|
29
|
+
},
|
|
30
|
+
merge0: {
|
|
31
|
+
value: function(...t) {
|
|
32
|
+
return b(this, ...t);
|
|
33
|
+
},
|
|
34
|
+
...r
|
|
35
|
+
},
|
|
36
|
+
concat0: {
|
|
37
|
+
value: function(...t) {
|
|
38
|
+
return d(this, ...t);
|
|
39
|
+
},
|
|
40
|
+
...r
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
l(Object.prototype, {
|
|
44
|
+
clone0: {
|
|
45
|
+
value: function() {
|
|
46
|
+
return JSON.parse(JSON.stringify(this));
|
|
47
|
+
},
|
|
48
|
+
...r
|
|
49
|
+
},
|
|
50
|
+
length0: {
|
|
51
|
+
value: function() {
|
|
52
|
+
return Object.keys(this).length;
|
|
53
|
+
},
|
|
54
|
+
...r
|
|
55
|
+
},
|
|
56
|
+
entries0: {
|
|
57
|
+
value: function() {
|
|
58
|
+
return Object.entries(this);
|
|
59
|
+
},
|
|
60
|
+
...r
|
|
61
|
+
},
|
|
62
|
+
keys0: {
|
|
63
|
+
value: function() {
|
|
64
|
+
return Object.keys(this);
|
|
65
|
+
},
|
|
66
|
+
...r
|
|
67
|
+
},
|
|
68
|
+
values0: {
|
|
69
|
+
value: function() {
|
|
70
|
+
return Object.values(this);
|
|
71
|
+
},
|
|
72
|
+
...r
|
|
73
|
+
},
|
|
74
|
+
merge0: {
|
|
75
|
+
value: function(...t) {
|
|
76
|
+
return b(this, ...t);
|
|
77
|
+
},
|
|
78
|
+
...r
|
|
79
|
+
},
|
|
80
|
+
concat0: {
|
|
81
|
+
value: function(...t) {
|
|
82
|
+
return d(this, ...t);
|
|
83
|
+
},
|
|
84
|
+
...r
|
|
85
|
+
},
|
|
86
|
+
map0: {
|
|
87
|
+
value: function(t = (n, u, i) => [n, u], e = 0) {
|
|
88
|
+
return Object.entries(this).map(([n, u]) => t(n, u, e++));
|
|
89
|
+
},
|
|
90
|
+
...r
|
|
91
|
+
},
|
|
92
|
+
pick0: {
|
|
93
|
+
value: function(...t) {
|
|
94
|
+
const e = {};
|
|
95
|
+
for (const n of t)
|
|
96
|
+
e[n] = this[n];
|
|
97
|
+
return e;
|
|
98
|
+
},
|
|
99
|
+
...r
|
|
100
|
+
},
|
|
101
|
+
omit0: {
|
|
102
|
+
value: function(...t) {
|
|
103
|
+
const e = {}, n = new Set(t);
|
|
104
|
+
for (const u in this)
|
|
105
|
+
n.has(u) || (e[u] = this[u]);
|
|
106
|
+
return e;
|
|
107
|
+
},
|
|
108
|
+
...r
|
|
109
|
+
},
|
|
110
|
+
attr0: {
|
|
111
|
+
value: function(t, ...e) {
|
|
112
|
+
return typeof this != "object" ? this : typeof t == "function" ? t(this, ...e) : this[t];
|
|
113
|
+
},
|
|
114
|
+
...r
|
|
115
|
+
},
|
|
116
|
+
log0: {
|
|
117
|
+
value: function(...t) {
|
|
118
|
+
return console.log(...t, this), this;
|
|
119
|
+
},
|
|
120
|
+
...r
|
|
121
|
+
},
|
|
122
|
+
debug0: {
|
|
123
|
+
value: function(...t) {
|
|
124
|
+
return console.debug(...t, this), this;
|
|
125
|
+
},
|
|
126
|
+
...r
|
|
127
|
+
},
|
|
128
|
+
// ====== Tree ======
|
|
129
|
+
getParents0: {
|
|
130
|
+
value: function(t = !1, e = -1, n = "parent") {
|
|
131
|
+
const u = t ? [this] : [];
|
|
132
|
+
let i = this[n];
|
|
133
|
+
for (; i && e-- != 0; )
|
|
134
|
+
u.push(i), i = i[n];
|
|
135
|
+
return u;
|
|
136
|
+
},
|
|
137
|
+
...r
|
|
138
|
+
},
|
|
139
|
+
getChildrens0: {
|
|
140
|
+
value: function(t = !1, e = -1, n = "children") {
|
|
141
|
+
const u = [], i = (s, o, f) => {
|
|
142
|
+
if (o && u.push(s), !(f == 0 || !s[n] || s[n].length == 0))
|
|
143
|
+
for (const c of s[n])
|
|
144
|
+
i(c, !0, f - 1);
|
|
145
|
+
};
|
|
146
|
+
return i(this, t, e), u;
|
|
147
|
+
},
|
|
148
|
+
...r
|
|
149
|
+
},
|
|
150
|
+
treeFind0: {
|
|
151
|
+
value: function(t, e = !0, n = -1, u = "children") {
|
|
152
|
+
if (e && t(this))
|
|
153
|
+
return this;
|
|
154
|
+
if (n == 0 || !this[u] || this[u].length == 0)
|
|
155
|
+
return null;
|
|
156
|
+
for (const i of this[u]) {
|
|
157
|
+
const s = i.treeFind0(t, !0, n - 1, u);
|
|
158
|
+
if (s !== null)
|
|
159
|
+
return s;
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
},
|
|
163
|
+
...r
|
|
164
|
+
},
|
|
165
|
+
treeEach0: {
|
|
166
|
+
value: function(t, e = !0, n = -1, u = "children") {
|
|
167
|
+
if (e && t(this), !(n == 0 || !this[u] || this[u].length == 0)) {
|
|
168
|
+
for (const i of this[u])
|
|
169
|
+
i.treeEach0(t, !0, n - 1, u);
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
...r
|
|
174
|
+
},
|
|
175
|
+
treeMap0: {
|
|
176
|
+
value: function(t, e = !0, n = -1, u = "children", i = null) {
|
|
177
|
+
const s = e ? t(this) : this, o = [];
|
|
178
|
+
if (n == 0 || !this[u] || this[u].length == 0)
|
|
179
|
+
return s;
|
|
180
|
+
for (const f of this[u])
|
|
181
|
+
o.push(f.treeMap0(t, !0, n - 1, u, i));
|
|
182
|
+
return s[u] = o, s;
|
|
183
|
+
},
|
|
184
|
+
...r
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
l(Number.prototype, {
|
|
188
|
+
ceil: {
|
|
189
|
+
value: function() {
|
|
190
|
+
return Math.ceil(this);
|
|
191
|
+
},
|
|
192
|
+
...r
|
|
193
|
+
},
|
|
194
|
+
floor: {
|
|
195
|
+
value: function() {
|
|
196
|
+
return Math.floor(this);
|
|
197
|
+
},
|
|
198
|
+
...r
|
|
199
|
+
},
|
|
200
|
+
round: {
|
|
201
|
+
value: function(t = 0) {
|
|
202
|
+
return t == 0 ? Math.round(this) : Math.round(this * 10 ** t) / 10 ** t;
|
|
203
|
+
},
|
|
204
|
+
...r
|
|
205
|
+
},
|
|
206
|
+
trunc: {
|
|
207
|
+
value: function() {
|
|
208
|
+
return Math.trunc(this);
|
|
209
|
+
},
|
|
210
|
+
...r
|
|
211
|
+
},
|
|
212
|
+
abs: {
|
|
213
|
+
value: function() {
|
|
214
|
+
return Math.abs(this);
|
|
215
|
+
},
|
|
216
|
+
...r
|
|
217
|
+
},
|
|
218
|
+
max: {
|
|
219
|
+
value: function(...t) {
|
|
220
|
+
return Math.max(this, ...t);
|
|
221
|
+
},
|
|
222
|
+
...r
|
|
223
|
+
},
|
|
224
|
+
min: {
|
|
225
|
+
value: function(...t) {
|
|
226
|
+
return Math.min(this, ...t);
|
|
227
|
+
},
|
|
228
|
+
...r
|
|
229
|
+
},
|
|
230
|
+
baseConvert: {
|
|
231
|
+
value: function(t = 64) {
|
|
232
|
+
let e = "", n = this, u = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
|
|
233
|
+
for (; n > 0; )
|
|
234
|
+
e = u.at(n % t) + e, n = Math.floor(n / t);
|
|
235
|
+
return e || "0";
|
|
236
|
+
},
|
|
237
|
+
...r
|
|
238
|
+
},
|
|
239
|
+
toFixed0: {
|
|
240
|
+
value: function(...t) {
|
|
241
|
+
return +this.toFixed(...t);
|
|
242
|
+
},
|
|
243
|
+
...r
|
|
244
|
+
},
|
|
245
|
+
toDate: {
|
|
246
|
+
value: function() {
|
|
247
|
+
return Date.new(this);
|
|
248
|
+
},
|
|
249
|
+
...r
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
l(BigInt.prototype, {
|
|
253
|
+
toJSON: {
|
|
254
|
+
value: function() {
|
|
255
|
+
return this > /* @__PURE__ */ BigInt(9007199254740991) || this < -/* @__PURE__ */ BigInt(9007199254740991) ? this.toString() : Number(this);
|
|
256
|
+
},
|
|
257
|
+
...r
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
l(String.prototype, {
|
|
261
|
+
length0: {
|
|
262
|
+
value: function() {
|
|
263
|
+
return this.length;
|
|
264
|
+
},
|
|
265
|
+
...r
|
|
266
|
+
},
|
|
267
|
+
substring0: {
|
|
268
|
+
value: function(t = 0, e = this.length) {
|
|
269
|
+
return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
|
|
270
|
+
},
|
|
271
|
+
...r
|
|
272
|
+
},
|
|
273
|
+
substr0: {
|
|
274
|
+
value: function(t = 0, e = this.length) {
|
|
275
|
+
return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
|
|
276
|
+
},
|
|
277
|
+
...r
|
|
278
|
+
},
|
|
279
|
+
split0: {
|
|
280
|
+
value: function(t = ",", e = -1) {
|
|
281
|
+
const n = this ? this.split(t) : [];
|
|
282
|
+
return e === -1 ? n : n.push0(n.splice(e - 1).join(t));
|
|
283
|
+
},
|
|
284
|
+
...r
|
|
285
|
+
},
|
|
286
|
+
splitNumber: {
|
|
287
|
+
value: function(t = ",") {
|
|
288
|
+
return this.split0(t).map((e) => +e);
|
|
289
|
+
},
|
|
290
|
+
...r
|
|
291
|
+
},
|
|
292
|
+
splitSegment: {
|
|
293
|
+
value: function(t = 1) {
|
|
294
|
+
const e = [];
|
|
295
|
+
for (let n = 0; n < this.length; n += t)
|
|
296
|
+
e.push(this.substring(n, t));
|
|
297
|
+
return e;
|
|
298
|
+
},
|
|
299
|
+
...r
|
|
300
|
+
},
|
|
301
|
+
sprintf: {
|
|
302
|
+
value: function(...t) {
|
|
303
|
+
let [e, ...n] = this.split(/%[sd]/);
|
|
304
|
+
for (let u = 0; u < n.length; u++)
|
|
305
|
+
e += t[u] + n[u];
|
|
306
|
+
return e;
|
|
307
|
+
},
|
|
308
|
+
...r
|
|
309
|
+
},
|
|
310
|
+
subOf: {
|
|
311
|
+
value: function(t, e, n = 0, u = 0) {
|
|
312
|
+
for (let o = 0; o < n && u != -1; o++, u++)
|
|
313
|
+
u = this.indexOf(t, u);
|
|
314
|
+
let i = this.indexOf(t, u), s = this.indexOf(e, i);
|
|
315
|
+
return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
|
|
316
|
+
},
|
|
317
|
+
...r
|
|
318
|
+
},
|
|
319
|
+
lastSubOf: {
|
|
320
|
+
value: function(t, e, n = 0, u = 1 / 0) {
|
|
321
|
+
for (let o = 0; o < n && u != -1; o++, u--)
|
|
322
|
+
u = this.lastIndexOf(t, u);
|
|
323
|
+
let i = this.lastIndexOf(t, u), s = this.indexOf(e, i);
|
|
324
|
+
return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
|
|
325
|
+
},
|
|
326
|
+
...r
|
|
327
|
+
},
|
|
328
|
+
camel2under: {
|
|
329
|
+
value: function() {
|
|
330
|
+
return this.substr(0, 1).toLowerCase() + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
|
|
331
|
+
},
|
|
332
|
+
...r
|
|
333
|
+
},
|
|
334
|
+
under2camel: {
|
|
335
|
+
value: function() {
|
|
336
|
+
return this.replace(/_([a-z])/g, (t, e) => e.toUpperCase());
|
|
337
|
+
},
|
|
338
|
+
...r
|
|
339
|
+
},
|
|
340
|
+
camel2pascal: {
|
|
341
|
+
value: function() {
|
|
342
|
+
return this.substr(0, 1).toUpperCase() + this.substr(1);
|
|
343
|
+
},
|
|
344
|
+
...r
|
|
345
|
+
},
|
|
346
|
+
pascal2camel: {
|
|
347
|
+
value: function() {
|
|
348
|
+
return this.substr(0, 1).toLowerCase() + this.substr(1);
|
|
349
|
+
},
|
|
350
|
+
...r
|
|
351
|
+
},
|
|
352
|
+
under2kebab: {
|
|
353
|
+
value: function() {
|
|
354
|
+
return this.replace(/_/g, "-");
|
|
355
|
+
},
|
|
356
|
+
...r
|
|
357
|
+
},
|
|
358
|
+
kebab2under: {
|
|
359
|
+
value: function() {
|
|
360
|
+
return this.replace(/-/g, "_");
|
|
361
|
+
},
|
|
362
|
+
...r
|
|
363
|
+
},
|
|
364
|
+
baseConvert: {
|
|
365
|
+
value: function(t = 64) {
|
|
366
|
+
let e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
|
|
367
|
+
for (let u = 0; u < this.length; u++)
|
|
368
|
+
e = e * t + n.indexOf(this.at(u));
|
|
369
|
+
return e;
|
|
370
|
+
},
|
|
371
|
+
...r
|
|
372
|
+
},
|
|
373
|
+
toFixed0: {
|
|
374
|
+
value: function(...t) {
|
|
375
|
+
return +(+this).toFixed(...t);
|
|
376
|
+
},
|
|
377
|
+
...r
|
|
378
|
+
},
|
|
379
|
+
toDate: {
|
|
380
|
+
value: function() {
|
|
381
|
+
return Date.new(this);
|
|
382
|
+
},
|
|
383
|
+
...r
|
|
384
|
+
},
|
|
385
|
+
hex2bytes: {
|
|
386
|
+
value: function() {
|
|
387
|
+
const t = [];
|
|
388
|
+
for (let e = 0; e < this.length; e += 2)
|
|
389
|
+
t.push(Number.parseInt(this.substring(e, e + 2), 16));
|
|
390
|
+
return t;
|
|
391
|
+
},
|
|
392
|
+
...r
|
|
393
|
+
},
|
|
394
|
+
string2bytes: {
|
|
395
|
+
value: function() {
|
|
396
|
+
if (typeof TextEncoder != "undefined")
|
|
397
|
+
return Array.from(new TextEncoder().encode(this));
|
|
398
|
+
const t = [], e = encodeURIComponent(this);
|
|
399
|
+
for (let n = 0; n < e.length; )
|
|
400
|
+
t.push(e.charAt(n) == "%" ? Number.parseInt(e.substring(n + 1, n += 3), 16) : e.charCodeAt(n++));
|
|
401
|
+
return t;
|
|
402
|
+
},
|
|
403
|
+
...r
|
|
404
|
+
},
|
|
405
|
+
base64decode: {
|
|
406
|
+
value: function(t) {
|
|
407
|
+
const e = [], n = {}, u = t === !0 ? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
408
|
+
for (let s = 0; s < u.length; s++)
|
|
409
|
+
n[u.charAt(s)] = s;
|
|
410
|
+
const i = this.charAt(this.length - 1) != "=" ? this.length : this.charAt(this.length - 2) != "=" ? this.length - 1 : this.length - 2;
|
|
411
|
+
for (let s = 3; s < i; s += 4) {
|
|
412
|
+
const o = (n[this.charAt(s - 3)] << 18) + (n[this.charAt(s - 2)] << 12) + (n[this.charAt(s - 1)] << 6) + n[this.charAt(s)];
|
|
413
|
+
e.push((o & 16711680) >> 16, (o & 65280) >> 8, o & 255);
|
|
414
|
+
}
|
|
415
|
+
if (i % 4 == 3) {
|
|
416
|
+
const s = (n[this.charAt(i - 3)] << 18) + (n[this.charAt(i - 2)] << 12) + (n[this.charAt(i - 1)] << 6);
|
|
417
|
+
e.push((s & 16711680) >> 16, (s & 65280) >> 8);
|
|
418
|
+
} else if (i % 4 == 2) {
|
|
419
|
+
const s = (n[this.charAt(i - 2)] << 18) + (n[this.charAt(i - 1)] << 12);
|
|
420
|
+
e.push((s & 16711680) >> 16);
|
|
421
|
+
}
|
|
422
|
+
return e;
|
|
423
|
+
},
|
|
424
|
+
...r
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
typeof Iterator != "undefined" && l(Iterator.prototype, {
|
|
428
|
+
toArray: {
|
|
429
|
+
value: function() {
|
|
430
|
+
return Array.from(this);
|
|
431
|
+
},
|
|
432
|
+
...r
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
l(Array.prototype, {
|
|
436
|
+
length0: {
|
|
437
|
+
value: function() {
|
|
438
|
+
return this.length;
|
|
439
|
+
},
|
|
440
|
+
...r
|
|
441
|
+
},
|
|
442
|
+
entries0: {
|
|
443
|
+
value: function() {
|
|
444
|
+
return this.entries();
|
|
445
|
+
},
|
|
446
|
+
...r
|
|
447
|
+
},
|
|
448
|
+
push0: {
|
|
449
|
+
value: function(...t) {
|
|
450
|
+
return this.push(...t), this;
|
|
451
|
+
},
|
|
452
|
+
...r
|
|
453
|
+
},
|
|
454
|
+
push1: {
|
|
455
|
+
value: function(...t) {
|
|
456
|
+
return this.push(...t), t[0];
|
|
457
|
+
},
|
|
458
|
+
...r
|
|
459
|
+
},
|
|
460
|
+
push3: {
|
|
461
|
+
value: function(...t) {
|
|
462
|
+
return this.push(...t), t;
|
|
463
|
+
},
|
|
464
|
+
...r
|
|
465
|
+
},
|
|
466
|
+
pop0: {
|
|
467
|
+
value: function(...t) {
|
|
468
|
+
return this.pop(...t), this;
|
|
469
|
+
},
|
|
470
|
+
...r
|
|
471
|
+
},
|
|
472
|
+
pop1: {
|
|
473
|
+
value: function(...t) {
|
|
474
|
+
return this.pop(...t), t[0];
|
|
475
|
+
},
|
|
476
|
+
...r
|
|
477
|
+
},
|
|
478
|
+
pop3: {
|
|
479
|
+
value: function(...t) {
|
|
480
|
+
return this.pop(...t), t;
|
|
481
|
+
},
|
|
482
|
+
...r
|
|
483
|
+
},
|
|
484
|
+
unshift0: {
|
|
485
|
+
value: function(...t) {
|
|
486
|
+
return this.unshift(...t), this;
|
|
487
|
+
},
|
|
488
|
+
...r
|
|
489
|
+
},
|
|
490
|
+
unshift1: {
|
|
491
|
+
value: function(...t) {
|
|
492
|
+
return this.unshift(...t), t[0];
|
|
493
|
+
},
|
|
494
|
+
...r
|
|
495
|
+
},
|
|
496
|
+
unshift3: {
|
|
497
|
+
value: function(...t) {
|
|
498
|
+
return this.unshift(...t), t;
|
|
499
|
+
},
|
|
500
|
+
...r
|
|
501
|
+
},
|
|
502
|
+
shift0: {
|
|
503
|
+
value: function(...t) {
|
|
504
|
+
return this.shift(...t), this;
|
|
505
|
+
},
|
|
506
|
+
...r
|
|
507
|
+
},
|
|
508
|
+
shift1: {
|
|
509
|
+
value: function(...t) {
|
|
510
|
+
return this.shift(...t), t[0];
|
|
511
|
+
},
|
|
512
|
+
...r
|
|
513
|
+
},
|
|
514
|
+
shift3: {
|
|
515
|
+
value: function(...t) {
|
|
516
|
+
return this.shift(...t), t;
|
|
517
|
+
},
|
|
518
|
+
...r
|
|
519
|
+
},
|
|
520
|
+
first0: {
|
|
521
|
+
value: function(t = null) {
|
|
522
|
+
return this.length ? this[0] : t;
|
|
523
|
+
},
|
|
524
|
+
...r
|
|
525
|
+
},
|
|
526
|
+
last0: {
|
|
527
|
+
value: function(t = null) {
|
|
528
|
+
return this.length ? this[this.length - 1] : t;
|
|
529
|
+
},
|
|
530
|
+
...r
|
|
531
|
+
},
|
|
532
|
+
find0: {
|
|
533
|
+
value: function(t, e = null) {
|
|
534
|
+
var n;
|
|
535
|
+
return (n = this.find(t)) != null ? n : e;
|
|
536
|
+
},
|
|
537
|
+
...r
|
|
538
|
+
},
|
|
539
|
+
equals0: {
|
|
540
|
+
value: function(t) {
|
|
541
|
+
return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
|
|
542
|
+
},
|
|
543
|
+
...r
|
|
544
|
+
},
|
|
545
|
+
unique0: {
|
|
546
|
+
value: function(t = (e) => e) {
|
|
547
|
+
const e = /* @__PURE__ */ new Set();
|
|
548
|
+
return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
|
|
549
|
+
},
|
|
550
|
+
...r
|
|
551
|
+
},
|
|
552
|
+
each0: {
|
|
553
|
+
value: function(t) {
|
|
554
|
+
return this.forEach(t), this;
|
|
555
|
+
},
|
|
556
|
+
...r
|
|
557
|
+
},
|
|
558
|
+
toObject: {
|
|
559
|
+
value: function(t = (e, n) => [n, e]) {
|
|
560
|
+
return Object.fromEntries(this.map(t));
|
|
561
|
+
},
|
|
562
|
+
...r
|
|
563
|
+
},
|
|
564
|
+
toMap: {
|
|
565
|
+
value: function(t = (e, n) => [n, e]) {
|
|
566
|
+
return new Map(this.map(t));
|
|
567
|
+
},
|
|
568
|
+
...r
|
|
569
|
+
},
|
|
570
|
+
toSet: {
|
|
571
|
+
value: function() {
|
|
572
|
+
return new Set(this);
|
|
573
|
+
},
|
|
574
|
+
...r
|
|
575
|
+
},
|
|
576
|
+
toGroup: {
|
|
577
|
+
value: function(t = (e) => [e.id, e]) {
|
|
578
|
+
const e = {};
|
|
579
|
+
for (const n of this) {
|
|
580
|
+
const [u, i] = t(n);
|
|
581
|
+
u in e || (e[u] = []), e[u].push(i);
|
|
582
|
+
}
|
|
583
|
+
return e;
|
|
584
|
+
},
|
|
585
|
+
...r
|
|
586
|
+
},
|
|
587
|
+
toMerge: {
|
|
588
|
+
value: function(t = (u) => u.id, e = (u) => ({ ...u, children: u.children || [] }), n = (u, i) => u.children.push(i)) {
|
|
589
|
+
var i;
|
|
590
|
+
const u = [];
|
|
591
|
+
for (const s of this)
|
|
592
|
+
n((i = u.find((o) => t(o) == t(s))) != null ? i : u.push1(e(s)), s);
|
|
593
|
+
return u;
|
|
594
|
+
},
|
|
595
|
+
...r
|
|
596
|
+
},
|
|
597
|
+
bytes2hex: {
|
|
598
|
+
value: function() {
|
|
599
|
+
let t = "";
|
|
600
|
+
for (let e = 0; e < this.length; e++)
|
|
601
|
+
t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
|
|
602
|
+
return t;
|
|
603
|
+
},
|
|
604
|
+
...r
|
|
605
|
+
},
|
|
606
|
+
bytes2string: {
|
|
607
|
+
value: function() {
|
|
608
|
+
if (typeof TextDecoder != "undefined")
|
|
609
|
+
return new TextDecoder().decode(new Uint8Array(this));
|
|
610
|
+
let t = "";
|
|
611
|
+
for (let e = 0; e < this.length; e++)
|
|
612
|
+
t += "%" + (this[e] < 16 ? "0" : "") + this[e].toString(16);
|
|
613
|
+
return decodeURIComponent(t);
|
|
614
|
+
},
|
|
615
|
+
...r
|
|
616
|
+
},
|
|
617
|
+
base64encode: {
|
|
618
|
+
value: function(t = !1, e = !0) {
|
|
619
|
+
let n = "", u = t === !0 ? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
620
|
+
for (let i = 2; i < this.length; i += 3) {
|
|
621
|
+
const s = (this[i - 2] << 16) + (this[i - 1] << 8) + this[i];
|
|
622
|
+
n += u.charAt((s & 16515072) >> 18) + u.charAt((s & 258048) >> 12) + u.charAt((s & 4032) >> 6) + u.charAt(s & 63);
|
|
623
|
+
}
|
|
624
|
+
if (this.length % 3 == 2) {
|
|
625
|
+
const i = (this[this.length - 2] << 16) + (this[this.length - 1] << 8);
|
|
626
|
+
n += u.charAt((i & 16515072) >> 18) + u.charAt((i & 258048) >> 12) + u.charAt((i & 4032) >> 6) + (e === !1 ? "" : "=");
|
|
627
|
+
} else if (this.length % 3 == 1) {
|
|
628
|
+
const i = this[this.length - 1] << 16;
|
|
629
|
+
n += u.charAt((i & 16515072) >> 18) + u.charAt((i & 258048) >> 12) + (e === !1 ? "" : "==");
|
|
630
|
+
}
|
|
631
|
+
return n;
|
|
632
|
+
},
|
|
633
|
+
...r
|
|
634
|
+
},
|
|
635
|
+
toUint8Array: {
|
|
636
|
+
value: function() {
|
|
637
|
+
return new Uint8Array(this);
|
|
638
|
+
},
|
|
639
|
+
...r
|
|
640
|
+
},
|
|
641
|
+
// ====== Relational ======
|
|
642
|
+
assoc: {
|
|
643
|
+
value: function(t, e, n = {}) {
|
|
644
|
+
const u = this.unique0((s) => s[t]), i = u.length == 0 ? {} : typeof n == "function" ? n(u) : n;
|
|
645
|
+
return this.each0((s) => {
|
|
646
|
+
var o;
|
|
647
|
+
return s[e] = (o = i[s[t]]) != null ? o : null;
|
|
648
|
+
});
|
|
649
|
+
},
|
|
650
|
+
...r
|
|
651
|
+
},
|
|
652
|
+
// ====== Tree ======
|
|
653
|
+
toTree: {
|
|
654
|
+
value: function(t = {}) {
|
|
655
|
+
const { id: e = "id", pid: n = "pid", level: u = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: f = null, hasRoot: c = !0 } = t, v = this.toObject((h) => [h[e], h]), g = this.toGroup((h) => [h[n], h]), a = this.length && c ? this.find((h) => h[n] === 0) : { [e]: 0, [n]: -1, [i]: null, [s]: null, [o]: g[0] };
|
|
656
|
+
l(a, { [i]: { value: a, enumerable: !1, configurable: !0, writable: !0 } });
|
|
657
|
+
for (const h of this)
|
|
658
|
+
l(h, {
|
|
659
|
+
[i]: { value: a, enumerable: !1, configurable: !0, writable: !0 },
|
|
660
|
+
[s]: { value: v[h[n]], enumerable: !1, configurable: !0, writable: !0 }
|
|
661
|
+
}), h[o] = g[h[e]] || f;
|
|
662
|
+
return a.treeEach0((h) => h[u] = h[s] ? h[s][u] + 1 : 0, -1, o), a;
|
|
663
|
+
},
|
|
664
|
+
...r
|
|
665
|
+
},
|
|
666
|
+
tree2tree: {
|
|
667
|
+
value: function(t = {}, e = null, n = null) {
|
|
668
|
+
var g;
|
|
669
|
+
const { id: u = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: f = "parent", children: c = "children", empty: v = null } = t;
|
|
670
|
+
e = e || { [u]: 0, [i]: -1, [s]: 0, [o]: null, [f]: null, [c]: this }, n = n || e;
|
|
671
|
+
for (const a of this)
|
|
672
|
+
l(a, {
|
|
673
|
+
[o]: { value: e, enumerable: !1, configurable: !0, writable: !0 },
|
|
674
|
+
[f]: { value: n, enumerable: !1, configurable: !0, writable: !0 }
|
|
675
|
+
}), a[i] = n[u], a[s] = n[s] + 1, a[c] = a[c] && a[c].length ? a[c] : v, (g = a[c]) == null || g.tree2tree(t, e, a);
|
|
676
|
+
return e;
|
|
677
|
+
},
|
|
678
|
+
...r
|
|
679
|
+
},
|
|
680
|
+
treeFind0: {
|
|
681
|
+
value: function(t, e = !0, n = -1, u = "children") {
|
|
682
|
+
for (const i of this) {
|
|
683
|
+
const s = i.treeFind0(t, e, n, u);
|
|
684
|
+
if (s !== null)
|
|
685
|
+
return s;
|
|
686
|
+
}
|
|
687
|
+
return null;
|
|
688
|
+
},
|
|
689
|
+
...r
|
|
690
|
+
},
|
|
691
|
+
treeEach0: {
|
|
692
|
+
value: function(t, e = !0, n = -1, u = "children") {
|
|
693
|
+
for (const i of this)
|
|
694
|
+
i.treeEach0(t, e, n, u);
|
|
695
|
+
return this;
|
|
696
|
+
},
|
|
697
|
+
...r
|
|
698
|
+
},
|
|
699
|
+
treeMap0: {
|
|
700
|
+
value: function(t, e = !0, n = -1, u = "children", i = null) {
|
|
701
|
+
return this.map((s) => s.treeMap0(t, e, n, u, i));
|
|
702
|
+
},
|
|
703
|
+
...r
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
l(ArrayBuffer.prototype, {
|
|
707
|
+
toUint8Array: {
|
|
708
|
+
value: function() {
|
|
709
|
+
return new Uint8Array(this);
|
|
710
|
+
},
|
|
711
|
+
...r
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
l(Uint8Array.prototype, {
|
|
715
|
+
bytes2hex: {
|
|
716
|
+
value: Array.prototype.bytes2hex,
|
|
717
|
+
...r
|
|
718
|
+
},
|
|
719
|
+
bytes2string: {
|
|
720
|
+
value: Array.prototype.bytes2string,
|
|
721
|
+
...r
|
|
722
|
+
},
|
|
723
|
+
base64encode: {
|
|
724
|
+
value: Array.prototype.base64encode,
|
|
725
|
+
...r
|
|
726
|
+
},
|
|
727
|
+
toArray: {
|
|
728
|
+
value: function() {
|
|
729
|
+
return new Array(...this);
|
|
730
|
+
},
|
|
731
|
+
...r
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
l(Map.prototype, {
|
|
735
|
+
length0: {
|
|
736
|
+
value: function() {
|
|
737
|
+
return this.size;
|
|
738
|
+
},
|
|
739
|
+
...r
|
|
740
|
+
},
|
|
741
|
+
entries0: {
|
|
742
|
+
value: function() {
|
|
743
|
+
return [...this.entries()];
|
|
744
|
+
},
|
|
745
|
+
...r
|
|
746
|
+
},
|
|
747
|
+
keys0: {
|
|
748
|
+
value: function() {
|
|
749
|
+
return [...this.keys()];
|
|
750
|
+
},
|
|
751
|
+
...r
|
|
752
|
+
},
|
|
753
|
+
values0: {
|
|
754
|
+
value: function() {
|
|
755
|
+
return [...this.values()];
|
|
756
|
+
},
|
|
757
|
+
...r
|
|
758
|
+
},
|
|
759
|
+
get0: {
|
|
760
|
+
value: function(t, e = null, ...n) {
|
|
761
|
+
if (this.has(t))
|
|
762
|
+
return this.get(t);
|
|
763
|
+
const u = typeof e != "function" ? e : e(t, ...n);
|
|
764
|
+
return this.set(t, u), u;
|
|
765
|
+
},
|
|
766
|
+
...r
|
|
767
|
+
},
|
|
768
|
+
get1: {
|
|
769
|
+
value: async function(t, e = null, ...n) {
|
|
770
|
+
if (this.has(t))
|
|
771
|
+
return this.get(t);
|
|
772
|
+
const u = typeof e != "function" ? e : await e(t, ...n);
|
|
773
|
+
return this.set(t, u), u;
|
|
774
|
+
},
|
|
775
|
+
...r
|
|
776
|
+
},
|
|
777
|
+
toObject: {
|
|
778
|
+
value: function() {
|
|
779
|
+
return Object.fromEntries(this);
|
|
780
|
+
},
|
|
781
|
+
...r
|
|
782
|
+
},
|
|
783
|
+
toJSON: {
|
|
784
|
+
value: function() {
|
|
785
|
+
return [...this];
|
|
786
|
+
},
|
|
787
|
+
...r
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
l(Set.prototype, {
|
|
791
|
+
length0: {
|
|
792
|
+
value: function() {
|
|
793
|
+
return this.size;
|
|
794
|
+
},
|
|
795
|
+
...r
|
|
796
|
+
},
|
|
797
|
+
entries0: {
|
|
798
|
+
value: function() {
|
|
799
|
+
return this.entries();
|
|
800
|
+
},
|
|
801
|
+
...r
|
|
802
|
+
},
|
|
803
|
+
toArray: {
|
|
804
|
+
value: function() {
|
|
805
|
+
return [...this];
|
|
806
|
+
},
|
|
807
|
+
...r
|
|
808
|
+
},
|
|
809
|
+
toJSON: {
|
|
810
|
+
value: function() {
|
|
811
|
+
return [...this];
|
|
812
|
+
},
|
|
813
|
+
...r
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
l(Date, {
|
|
817
|
+
new: {
|
|
818
|
+
value: function(...t) {
|
|
819
|
+
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);
|
|
820
|
+
},
|
|
821
|
+
...r
|
|
822
|
+
},
|
|
823
|
+
format: {
|
|
824
|
+
value: function(t = "y-m-d h:i:s") {
|
|
825
|
+
return (/* @__PURE__ */ new Date()).format(t);
|
|
826
|
+
},
|
|
827
|
+
...r
|
|
828
|
+
},
|
|
829
|
+
unix: {
|
|
830
|
+
value: function() {
|
|
831
|
+
return this.now() / 1e3 | 0;
|
|
832
|
+
},
|
|
833
|
+
...r
|
|
834
|
+
},
|
|
835
|
+
fromUnix: {
|
|
836
|
+
value: function(t = 0) {
|
|
837
|
+
return this.new((t || 0) * 1e3);
|
|
838
|
+
},
|
|
839
|
+
...r
|
|
840
|
+
},
|
|
841
|
+
expr: {
|
|
842
|
+
value: function(t = {}) {
|
|
843
|
+
return (/* @__PURE__ */ new Date()).expr(t);
|
|
844
|
+
},
|
|
845
|
+
...r
|
|
846
|
+
},
|
|
847
|
+
toDayRange: {
|
|
848
|
+
value: function() {
|
|
849
|
+
const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), u = t.getDate(), i = new Date(e, n, u).getTime() / 1e3 | 0;
|
|
850
|
+
return [i, i + 86400 - 1];
|
|
851
|
+
},
|
|
852
|
+
...r
|
|
853
|
+
},
|
|
854
|
+
toWeekRange: {
|
|
855
|
+
value: function() {
|
|
856
|
+
let t = /* @__PURE__ */ new Date();
|
|
857
|
+
for (; t.getDay() != 1; )
|
|
858
|
+
t = new Date(t.getTime() - 86400);
|
|
859
|
+
const e = t.getFullYear(), n = t.getMonth(), u = t.getDate(), i = new Date(e, n, u).getTime() / 1e3 | 0;
|
|
860
|
+
return [i, i + 86400 * 7 - 1];
|
|
861
|
+
},
|
|
862
|
+
...r
|
|
863
|
+
},
|
|
864
|
+
toMonthRange: {
|
|
865
|
+
value: function() {
|
|
866
|
+
const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), u = new Date(e, n, 1).getTime() / 1e3 | 0, i = new Date(e, n + 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
|
|
867
|
+
return [u, i];
|
|
868
|
+
},
|
|
869
|
+
...r
|
|
870
|
+
},
|
|
871
|
+
toYearRange: {
|
|
872
|
+
value: function() {
|
|
873
|
+
const e = (/* @__PURE__ */ new Date()).getFullYear(), n = new Date(e, 1, 1).getTime() / 1e3 | 0, u = new Date(e + 1, 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
|
|
874
|
+
return [n, u];
|
|
875
|
+
},
|
|
876
|
+
...r
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
l(Date.prototype, {
|
|
880
|
+
format: {
|
|
881
|
+
value: function(t = "y-m-d h:i:s") {
|
|
882
|
+
if (this.getTime() === 0)
|
|
883
|
+
return "-";
|
|
884
|
+
const e = {
|
|
885
|
+
y: this.getFullYear(),
|
|
886
|
+
m: this.getMonth() + 1,
|
|
887
|
+
d: this.getDate(),
|
|
888
|
+
h: this.getHours(),
|
|
889
|
+
i: this.getMinutes(),
|
|
890
|
+
s: this.getSeconds(),
|
|
891
|
+
l: this.getMilliseconds(),
|
|
892
|
+
e: this.getMonthDay()
|
|
893
|
+
};
|
|
894
|
+
return t.replace(/([ymdhisle])/ig, (n, u) => u >= "A" && u <= "Z" ? e[u.toLowerCase()] : e[u].toString().padStart(u === "l" ? 3 : 2, "0"));
|
|
895
|
+
},
|
|
896
|
+
...r
|
|
897
|
+
},
|
|
898
|
+
unix: {
|
|
899
|
+
value: function() {
|
|
900
|
+
return this.getTime() / 1e3 | 0;
|
|
901
|
+
},
|
|
902
|
+
...r
|
|
903
|
+
},
|
|
904
|
+
isLeapYear: {
|
|
905
|
+
value: function() {
|
|
906
|
+
return this.getFullYear() % 4 === 0 && this.getFullYear() % 400 !== 0;
|
|
907
|
+
},
|
|
908
|
+
...r
|
|
909
|
+
},
|
|
910
|
+
getMonthDay: {
|
|
911
|
+
value: function() {
|
|
912
|
+
return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
|
|
913
|
+
},
|
|
914
|
+
...r
|
|
915
|
+
},
|
|
916
|
+
expr: {
|
|
917
|
+
value: function({ y: t = 0, m: e = 0, d: n = 0, h: u = 0, i = 0, s = 0 }) {
|
|
918
|
+
const o = new Date(this.getFullYear() + t, this.getMonth() + e + 1, 0);
|
|
919
|
+
return new Date(this.getFullYear() + t, this.getMonth() + e, Math.min(o.getDate(), this.getDate()) + n, this.getHours() + u, this.getMinutes() + i, this.getSeconds() + s);
|
|
920
|
+
},
|
|
921
|
+
...r
|
|
922
|
+
},
|
|
923
|
+
begin: {
|
|
924
|
+
value: function(t = 3) {
|
|
925
|
+
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));
|
|
926
|
+
},
|
|
927
|
+
...r
|
|
928
|
+
},
|
|
929
|
+
end: {
|
|
930
|
+
value: function(t = 3) {
|
|
931
|
+
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));
|
|
932
|
+
},
|
|
933
|
+
...r
|
|
934
|
+
},
|
|
935
|
+
week: {
|
|
936
|
+
value: function(t, e = 1) {
|
|
937
|
+
let n = new Date(this.getTime());
|
|
938
|
+
for (; n.getDay() !== t; )
|
|
939
|
+
n = new Date(n.getTime() + 864e5 * e);
|
|
940
|
+
return n;
|
|
941
|
+
},
|
|
942
|
+
...r
|
|
943
|
+
},
|
|
944
|
+
toJSON: {
|
|
945
|
+
value: function() {
|
|
946
|
+
return this.getTime();
|
|
947
|
+
},
|
|
948
|
+
...r
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
l(RegExp.prototype, {
|
|
952
|
+
toJSON: {
|
|
953
|
+
value: function() {
|
|
954
|
+
return this.toString();
|
|
955
|
+
},
|
|
956
|
+
...r
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
l(Promise.prototype, {
|
|
960
|
+
tryCatch: {
|
|
961
|
+
value: function() {
|
|
962
|
+
return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
|
|
963
|
+
},
|
|
964
|
+
...r
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
typeof Promise.withResolvers == "undefined" && l(Promise, {
|
|
968
|
+
withResolvers: {
|
|
969
|
+
value: function() {
|
|
970
|
+
let t = null, e = null;
|
|
971
|
+
return { promise: new this((u, i) => {
|
|
972
|
+
t = u, e = i;
|
|
973
|
+
}), resolve: t, reject: e };
|
|
974
|
+
},
|
|
975
|
+
...r
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
l(Promise, {
|
|
979
|
+
channel: {
|
|
980
|
+
value: function() {
|
|
981
|
+
let t = null, e = null;
|
|
982
|
+
return [new this((u, i) => {
|
|
983
|
+
t = u, e = i;
|
|
984
|
+
}), t, e];
|
|
985
|
+
},
|
|
986
|
+
...r
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
l(JSON, {
|
|
990
|
+
parse0: {
|
|
991
|
+
value: function(t, e = null) {
|
|
992
|
+
try {
|
|
993
|
+
if (typeof t != "string")
|
|
994
|
+
throw new Error("not string");
|
|
995
|
+
return JSON.parse(t);
|
|
996
|
+
} catch (n) {
|
|
997
|
+
return e;
|
|
998
|
+
}
|
|
999
|
+
},
|
|
1000
|
+
...r
|
|
1001
|
+
}
|
|
1002
|
+
});
|