jc-structure 0.1.18 → 0.1.19
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/jc-structure.js +200 -181
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +7 -5
- package/package.json +1 -1
- package/types/global.d.ts +41 -0
- package/types/string.extensions.d.ts +93 -0
- package/types/extend.d.ts +0 -57
package/dist/jc-structure.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class z {
|
|
2
2
|
items = {};
|
|
3
3
|
count = 0;
|
|
4
4
|
lowestCount = 0;
|
|
@@ -49,7 +49,7 @@ class V {
|
|
|
49
49
|
return this.isEmpty() ? "" : `Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
class
|
|
52
|
+
class q {
|
|
53
53
|
items = {};
|
|
54
54
|
count = 0;
|
|
55
55
|
constructor() {
|
|
@@ -100,7 +100,7 @@ class z {
|
|
|
100
100
|
return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
class
|
|
103
|
+
class j {
|
|
104
104
|
stack = [];
|
|
105
105
|
minStack = [];
|
|
106
106
|
push(t) {
|
|
@@ -186,15 +186,15 @@ class O extends y {
|
|
|
186
186
|
y.swap(this.heap, e, t), t = e, e = y.getParentIndex(t);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
class
|
|
189
|
+
class D extends O {
|
|
190
190
|
constructor(t = (e, s) => P(s, e)) {
|
|
191
191
|
super(t);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function N(r) {
|
|
195
195
|
return { value: r };
|
|
196
196
|
}
|
|
197
|
-
class
|
|
197
|
+
class U {
|
|
198
198
|
capacity;
|
|
199
199
|
length = 0;
|
|
200
200
|
head = null;
|
|
@@ -224,14 +224,14 @@ class j {
|
|
|
224
224
|
}
|
|
225
225
|
update(t, e) {
|
|
226
226
|
let s = this.lookup.get(t);
|
|
227
|
-
s ? (this.detach(s), this.prepend(s), s.value = e) : (s =
|
|
227
|
+
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = N(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
class
|
|
230
|
+
class b {
|
|
231
231
|
value;
|
|
232
232
|
next = void 0;
|
|
233
233
|
}
|
|
234
|
-
class
|
|
234
|
+
class $ {
|
|
235
235
|
count = 0;
|
|
236
236
|
head = void 0;
|
|
237
237
|
constructor() {
|
|
@@ -264,7 +264,7 @@ class U {
|
|
|
264
264
|
return this.getElementAt(t)?.value;
|
|
265
265
|
}
|
|
266
266
|
insert(t, e) {
|
|
267
|
-
let s = new
|
|
267
|
+
let s = new b();
|
|
268
268
|
if (s.value = t, e > this.count || e < 0)
|
|
269
269
|
throw new Error("index error");
|
|
270
270
|
this.count++;
|
|
@@ -276,7 +276,7 @@ class U {
|
|
|
276
276
|
i = this.getElementAt(e - 1), n = i.next, i.next = s, s.next = n;
|
|
277
277
|
}
|
|
278
278
|
push(t) {
|
|
279
|
-
let e = new
|
|
279
|
+
let e = new b();
|
|
280
280
|
if (e.value = t, this.count++, this.isEmpty()) {
|
|
281
281
|
this.head = e;
|
|
282
282
|
return;
|
|
@@ -310,7 +310,7 @@ class U {
|
|
|
310
310
|
return t = t.slice(0, -1), t;
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
class
|
|
313
|
+
class R {
|
|
314
314
|
key;
|
|
315
315
|
value;
|
|
316
316
|
constructor(t, e) {
|
|
@@ -320,7 +320,7 @@ class C {
|
|
|
320
320
|
function M(r, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
321
321
|
return r == null ? !(t.emptyString && r === "" || t.zeroNumber && r === 0) : !1;
|
|
322
322
|
}
|
|
323
|
-
class
|
|
323
|
+
class C {
|
|
324
324
|
table = [];
|
|
325
325
|
constructor() {
|
|
326
326
|
}
|
|
@@ -339,7 +339,7 @@ class R {
|
|
|
339
339
|
let s = this.getItemIndex(t);
|
|
340
340
|
this.table[s].value = e;
|
|
341
341
|
} else {
|
|
342
|
-
const s = new
|
|
342
|
+
const s = new R(t, e);
|
|
343
343
|
this.table.push(s);
|
|
344
344
|
}
|
|
345
345
|
}
|
|
@@ -390,12 +390,12 @@ class R {
|
|
|
390
390
|
return t = t.slice(0, -1), t;
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
class
|
|
393
|
+
class _ {
|
|
394
394
|
isDirected;
|
|
395
395
|
vertices;
|
|
396
396
|
adjList;
|
|
397
397
|
constructor(t = !1) {
|
|
398
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
398
|
+
this.isDirected = t, this.vertices = [], this.adjList = new C();
|
|
399
399
|
}
|
|
400
400
|
addVertex(t) {
|
|
401
401
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -475,10 +475,10 @@ class w {
|
|
|
475
475
|
return this.mul(-1);
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
|
-
class
|
|
478
|
+
class E {
|
|
479
479
|
_matrix;
|
|
480
480
|
static zero(t, e) {
|
|
481
|
-
return new
|
|
481
|
+
return new E(
|
|
482
482
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
483
483
|
);
|
|
484
484
|
}
|
|
@@ -519,7 +519,7 @@ class x {
|
|
|
519
519
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
520
520
|
}
|
|
521
521
|
mul(t) {
|
|
522
|
-
return new
|
|
522
|
+
return new E(this._matrix.map((e) => e.map((s) => s * t)));
|
|
523
523
|
}
|
|
524
524
|
div(t) {
|
|
525
525
|
return this.mul(1 / t);
|
|
@@ -527,7 +527,7 @@ class x {
|
|
|
527
527
|
add(t) {
|
|
528
528
|
if (this.row !== t.row || this.col !== t.col)
|
|
529
529
|
throw new Error("Matrix dimensions do not match");
|
|
530
|
-
return new
|
|
530
|
+
return new E(
|
|
531
531
|
this._matrix.map(
|
|
532
532
|
(e, s) => e.map((i, n) => i + t.getItem([s, n]))
|
|
533
533
|
)
|
|
@@ -545,14 +545,14 @@ class x {
|
|
|
545
545
|
mulVector(t) {
|
|
546
546
|
if (this.col !== t.dimension)
|
|
547
547
|
throw new Error("Matrix dimensions do not match");
|
|
548
|
-
return new
|
|
548
|
+
return new E(
|
|
549
549
|
this._matrix.map((e) => e.map((s, i) => s * t.getItem(i)))
|
|
550
550
|
);
|
|
551
551
|
}
|
|
552
552
|
mulMatrix(t) {
|
|
553
553
|
if (this.col !== t.row)
|
|
554
554
|
throw new Error("Matrix dimensions do not match");
|
|
555
|
-
const e =
|
|
555
|
+
const e = E.zero(this.row, t.col);
|
|
556
556
|
for (let s = 0; s < this.row; s++) {
|
|
557
557
|
const i = this.rowVector(s);
|
|
558
558
|
for (let n = 0; n < this.col; n++)
|
|
@@ -561,7 +561,7 @@ class x {
|
|
|
561
561
|
return e;
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
class
|
|
564
|
+
class o {
|
|
565
565
|
static distance(t, e) {
|
|
566
566
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
567
567
|
}
|
|
@@ -571,7 +571,7 @@ class u {
|
|
|
571
571
|
this.x = t, this.y = e;
|
|
572
572
|
}
|
|
573
573
|
distanceTo(t) {
|
|
574
|
-
return
|
|
574
|
+
return o.distance(this, t);
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
class g {
|
|
@@ -587,12 +587,12 @@ class g {
|
|
|
587
587
|
}
|
|
588
588
|
static getIntersection(t, e, s = g.EPSILON) {
|
|
589
589
|
if (g.isParallel(t, e)) return null;
|
|
590
|
-
const i = t.p1.x, n = t.p1.y, h = t.p2.x,
|
|
591
|
-
if (Math.abs(
|
|
592
|
-
const d = ((i -
|
|
590
|
+
const i = t.p1.x, n = t.p1.y, h = t.p2.x, u = t.p2.y, p = e.p1.x, f = e.p1.y, m = e.p2.x, a = e.p2.y, c = (i - h) * (f - a) - (n - u) * (p - m);
|
|
591
|
+
if (Math.abs(c) < s) return null;
|
|
592
|
+
const d = ((i - p) * (f - a) - (n - f) * (p - m)) / c, v = -((i - h) * (n - f) - (n - u) * (i - p)) / c;
|
|
593
593
|
if (d >= 0 && d <= 1 && v >= 0 && v <= 1) {
|
|
594
|
-
const k = i + d * (h - i),
|
|
595
|
-
return new
|
|
594
|
+
const k = i + d * (h - i), L = n + d * (u - n);
|
|
595
|
+
return new o(k, L);
|
|
596
596
|
}
|
|
597
597
|
return null;
|
|
598
598
|
}
|
|
@@ -600,12 +600,12 @@ class g {
|
|
|
600
600
|
return g.getIntersection(t, e) !== null;
|
|
601
601
|
}
|
|
602
602
|
static distanceToPoint(t, e, s = g.EPSILON) {
|
|
603
|
-
const i = e.x - t.p1.x, n = e.y - t.p1.y, h = t.p2.x - t.p1.x,
|
|
603
|
+
const i = e.x - t.p1.x, n = e.y - t.p1.y, h = t.p2.x - t.p1.x, u = t.p2.y - t.p1.y, p = i * h + n * u, f = h * h + u * u;
|
|
604
604
|
let m = -1;
|
|
605
|
-
f > s && (m =
|
|
606
|
-
let a,
|
|
607
|
-
m < 0 ? (a = t.p1.x,
|
|
608
|
-
const d = e.x - a, v = e.y -
|
|
605
|
+
f > s && (m = p / f);
|
|
606
|
+
let a, c;
|
|
607
|
+
m < 0 ? (a = t.p1.x, c = t.p1.y) : m > 1 ? (a = t.p2.x, c = t.p2.y) : (a = t.p1.x + m * h, c = t.p1.y + m * u);
|
|
608
|
+
const d = e.x - a, v = e.y - c;
|
|
609
609
|
return Math.hypot(d + v);
|
|
610
610
|
}
|
|
611
611
|
p1;
|
|
@@ -619,7 +619,7 @@ class g {
|
|
|
619
619
|
}
|
|
620
620
|
get midpoint() {
|
|
621
621
|
const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
|
|
622
|
-
return new
|
|
622
|
+
return new o(t, e);
|
|
623
623
|
}
|
|
624
624
|
get angle() {
|
|
625
625
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
@@ -631,9 +631,9 @@ class g {
|
|
|
631
631
|
// 获取线段的方向向量
|
|
632
632
|
get direction() {
|
|
633
633
|
const t = this.length;
|
|
634
|
-
if (t < g.EPSILON) return new
|
|
634
|
+
if (t < g.EPSILON) return new o(0, 0);
|
|
635
635
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
636
|
-
return new
|
|
636
|
+
return new o(e, s);
|
|
637
637
|
}
|
|
638
638
|
get start() {
|
|
639
639
|
return this.p1;
|
|
@@ -649,24 +649,24 @@ class A {
|
|
|
649
649
|
this.name = t;
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
|
-
class
|
|
652
|
+
class l extends A {
|
|
653
653
|
static isValid(t, e, s) {
|
|
654
654
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
655
655
|
}
|
|
656
656
|
static area(t, e, s) {
|
|
657
|
-
if (!
|
|
657
|
+
if (!l.isValid(t, e, s))
|
|
658
658
|
throw new Error("Invalid triangle");
|
|
659
659
|
const i = (t + e + s) / 2;
|
|
660
660
|
return Math.sqrt(i * (i - t) * (i - e) * (i - s));
|
|
661
661
|
}
|
|
662
662
|
static getType(t, e, s) {
|
|
663
|
-
if (!
|
|
663
|
+
if (!l.isValid(t, e, s))
|
|
664
664
|
throw new Error("Invalid triangle sides");
|
|
665
|
-
const i = [t, e, s].sort((
|
|
666
|
-
return Math.abs(n - h) <
|
|
665
|
+
const i = [t, e, s].sort((p, f) => p - f), [n, h, u] = i;
|
|
666
|
+
return Math.abs(n - h) < l.EPSILON && Math.abs(h - u) < l.EPSILON ? "equilateral" : Math.abs(n - h) < l.EPSILON || Math.abs(h - u) < l.EPSILON ? "isosceles" : "scalene";
|
|
667
667
|
}
|
|
668
668
|
static getAngles(t, e, s) {
|
|
669
|
-
if (!
|
|
669
|
+
if (!l.isValid(t, e, s))
|
|
670
670
|
throw new Error("Invalid triangle sides");
|
|
671
671
|
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)), h = Math.PI - i - n;
|
|
672
672
|
return [i, n, h];
|
|
@@ -686,64 +686,64 @@ class p extends A {
|
|
|
686
686
|
}
|
|
687
687
|
get side() {
|
|
688
688
|
return [
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
689
|
+
o.distance(this.p1, this.p2),
|
|
690
|
+
o.distance(this.p2, this.p3),
|
|
691
|
+
o.distance(this.p3, this.p1)
|
|
692
692
|
];
|
|
693
693
|
}
|
|
694
694
|
perimeter() {
|
|
695
|
-
return
|
|
695
|
+
return l.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
|
|
696
696
|
}
|
|
697
697
|
area() {
|
|
698
698
|
const [t, e, s] = this.side;
|
|
699
|
-
return
|
|
699
|
+
return l.area(t, e, s);
|
|
700
700
|
}
|
|
701
701
|
get type() {
|
|
702
702
|
const [t, e, s] = this.side;
|
|
703
|
-
return
|
|
703
|
+
return l.getType(t, e, s);
|
|
704
704
|
}
|
|
705
705
|
get angles() {
|
|
706
706
|
const [t, e, s] = this.side;
|
|
707
|
-
return
|
|
707
|
+
return l.getAngles(t, e, s);
|
|
708
708
|
}
|
|
709
709
|
get centroid() {
|
|
710
|
-
return new
|
|
710
|
+
return new o(
|
|
711
711
|
(this.p1.x + this.p2.x + this.p3.x) / 3,
|
|
712
712
|
(this.p1.y + this.p2.y + this.p3.y) / 3
|
|
713
713
|
);
|
|
714
714
|
}
|
|
715
715
|
get incenter() {
|
|
716
716
|
const [t, e, s] = this.side, i = this.perimeter() / 2, n = (t * this.p1.x + e * this.p2.x + s * this.p3.x) / i, h = (t * this.p1.y + e * this.p2.y + s * this.p3.y) / i;
|
|
717
|
-
return new
|
|
717
|
+
return new o(n, h);
|
|
718
718
|
}
|
|
719
719
|
get circumcenter() {
|
|
720
720
|
const t = 2 * (this.p1.x * (this.p2.y - this.p3.y) + this.p2.x * (this.p3.y - this.p1.y) + this.p3.x * (this.p1.y - this.p2.y));
|
|
721
|
-
if (Math.abs(t) <
|
|
721
|
+
if (Math.abs(t) < l.EPSILON)
|
|
722
722
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
723
723
|
const e = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p2.y - this.p3.y) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p3.y - this.p1.y) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p1.y - this.p2.y)) / t, s = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p3.x - this.p2.x) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p1.x - this.p3.x) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p2.x - this.p1.x)) / t;
|
|
724
|
-
return new
|
|
724
|
+
return new o(e, s);
|
|
725
725
|
}
|
|
726
726
|
containsPoint(t) {
|
|
727
|
-
const e =
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
), s =
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
), i =
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
727
|
+
const e = l.area(
|
|
728
|
+
o.distance(t, this.p1),
|
|
729
|
+
o.distance(t, this.p2),
|
|
730
|
+
o.distance(this.p1, this.p2)
|
|
731
|
+
), s = l.area(
|
|
732
|
+
o.distance(t, this.p2),
|
|
733
|
+
o.distance(t, this.p3),
|
|
734
|
+
o.distance(this.p2, this.p3)
|
|
735
|
+
), i = l.area(
|
|
736
|
+
o.distance(t, this.p3),
|
|
737
|
+
o.distance(t, this.p1),
|
|
738
|
+
o.distance(this.p3, this.p1)
|
|
739
739
|
);
|
|
740
|
-
return Math.abs(e + s + i - this.area()) <
|
|
740
|
+
return Math.abs(e + s + i - this.area()) < l.EPSILON;
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
|
-
function
|
|
743
|
+
function H(r) {
|
|
744
744
|
return new Promise((t) => setTimeout(t, r));
|
|
745
745
|
}
|
|
746
|
-
function
|
|
746
|
+
function F(r) {
|
|
747
747
|
const t = [], e = {
|
|
748
748
|
"(": ")",
|
|
749
749
|
"[": "]",
|
|
@@ -756,40 +756,22 @@ function H(r) {
|
|
|
756
756
|
return !1;
|
|
757
757
|
return t.length === 0;
|
|
758
758
|
}
|
|
759
|
-
function
|
|
759
|
+
function S(r) {
|
|
760
760
|
return r !== null && (typeof r == "object" || typeof r == "function");
|
|
761
761
|
}
|
|
762
762
|
class T {
|
|
763
763
|
map = /* @__PURE__ */ new Map();
|
|
764
764
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
765
765
|
set(t, e) {
|
|
766
|
-
|
|
766
|
+
S(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
767
767
|
}
|
|
768
768
|
get(t) {
|
|
769
|
-
return
|
|
769
|
+
return S(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
770
770
|
}
|
|
771
771
|
has(t) {
|
|
772
|
-
return
|
|
772
|
+
return S(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
-
function F(r) {
|
|
776
|
-
if (!r.length) return [];
|
|
777
|
-
const t = [[r[0]]];
|
|
778
|
-
for (let s = 1, i = r.length; s < i; s++) {
|
|
779
|
-
const n = r[s];
|
|
780
|
-
e(n);
|
|
781
|
-
}
|
|
782
|
-
function e(s) {
|
|
783
|
-
for (let i = t.length - 1; i >= 0; i--) {
|
|
784
|
-
const n = t[i], h = n[t[i].length - 1];
|
|
785
|
-
if (h < s) {
|
|
786
|
-
t[i + 1] = [...n, s];
|
|
787
|
-
break;
|
|
788
|
-
} else h > s && i === 0 && (t[i] = [s]);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
return t[t.length - 1];
|
|
792
|
-
}
|
|
793
775
|
class B {
|
|
794
776
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
795
777
|
["M", 1e3],
|
|
@@ -819,10 +801,10 @@ class B {
|
|
|
819
801
|
if (this.ROMAN_MAP.has(h))
|
|
820
802
|
s += this.ROMAN_MAP.get(h), i += 2;
|
|
821
803
|
else {
|
|
822
|
-
const
|
|
823
|
-
if (!
|
|
804
|
+
const u = t[i], p = this.ROMAN_MAP.get(u);
|
|
805
|
+
if (!p)
|
|
824
806
|
throw new Error(`Invalid Roman numeral sequence at position ${i}`);
|
|
825
|
-
s +=
|
|
807
|
+
s += p, i += 1;
|
|
826
808
|
}
|
|
827
809
|
}
|
|
828
810
|
if (this.toRoman(s) !== t)
|
|
@@ -878,19 +860,19 @@ class G {
|
|
|
878
860
|
return [];
|
|
879
861
|
if (e < 0 || !Number.isInteger(e))
|
|
880
862
|
throw new Error("Precision must be a non-negative integer");
|
|
881
|
-
const s = t.reduce((a,
|
|
863
|
+
const s = t.reduce((a, c) => a + c, 0);
|
|
882
864
|
if (s === 0)
|
|
883
865
|
return t.map(() => "0%");
|
|
884
|
-
const n = 100 * Math.pow(10, e), h = t.map((a) => a / s * n),
|
|
885
|
-
let f =
|
|
866
|
+
const n = 100 * Math.pow(10, e), h = t.map((a) => a / s * n), u = h.map((a) => Math.floor(a)), p = h.map((a, c) => a - u[c]);
|
|
867
|
+
let f = u.reduce((a, c) => a + c, 0), m = n - f;
|
|
886
868
|
for (; m > 0; ) {
|
|
887
|
-
let a = -1,
|
|
888
|
-
for (let d = 0; d <
|
|
889
|
-
|
|
869
|
+
let a = -1, c = -1;
|
|
870
|
+
for (let d = 0; d < p.length; d++)
|
|
871
|
+
p[d] > c && (c = p[d], a = d);
|
|
890
872
|
if (a === -1) break;
|
|
891
|
-
|
|
873
|
+
u[a]++, p[a] = 0, m--;
|
|
892
874
|
}
|
|
893
|
-
return
|
|
875
|
+
return u.map((a) => `${(a / n * 100).toFixed(e)}%`);
|
|
894
876
|
}
|
|
895
877
|
static fastSqrt(t) {
|
|
896
878
|
if (t < 0)
|
|
@@ -1014,7 +996,7 @@ class G {
|
|
|
1014
996
|
return t * (t + 1) * (2 * t + 1) * (3 * t * t + 3 * t - 1) / 30;
|
|
1015
997
|
}
|
|
1016
998
|
}
|
|
1017
|
-
class
|
|
999
|
+
class X {
|
|
1018
1000
|
static READ = 1;
|
|
1019
1001
|
static WRITE = 2;
|
|
1020
1002
|
static SHARE = 4;
|
|
@@ -1033,23 +1015,34 @@ class W {
|
|
|
1033
1015
|
return t ^ e;
|
|
1034
1016
|
}
|
|
1035
1017
|
}
|
|
1036
|
-
class
|
|
1037
|
-
static longestCommonPrefix(
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1018
|
+
class Q extends String {
|
|
1019
|
+
// static longestCommonPrefix(strs: string[]): string {
|
|
1020
|
+
// if (!strs.length) return "";
|
|
1021
|
+
// let prefix = strs[0];
|
|
1022
|
+
// for (let i = 1; i < strs.length; i++) {
|
|
1023
|
+
// while (!strs[i].startsWith(prefix)) {
|
|
1024
|
+
// prefix = prefix.slice(0, -1);
|
|
1025
|
+
// if (prefix === "") return "";
|
|
1026
|
+
// }
|
|
1027
|
+
// }
|
|
1028
|
+
// return prefix;
|
|
1029
|
+
// }
|
|
1030
|
+
// static uuid(a?: number | string): string {
|
|
1031
|
+
// return typeof a === "number"
|
|
1032
|
+
// ? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16)
|
|
1033
|
+
// : (1e7 + -1e3 + -4e3 + -8e3 + -1e11).toString().replace(/[018]/g, (c) => {
|
|
1034
|
+
// const num = parseInt(c, 10);
|
|
1035
|
+
// return this.uuid(num);
|
|
1036
|
+
// });
|
|
1037
|
+
// }
|
|
1038
|
+
static frequencyStatistics(t) {
|
|
1039
|
+
return [...t].reduce(
|
|
1040
|
+
(e, s) => (e[s] = (e[s] || 0) + 1, e),
|
|
1041
|
+
{}
|
|
1042
|
+
);
|
|
1050
1043
|
}
|
|
1051
1044
|
}
|
|
1052
|
-
class
|
|
1045
|
+
class W {
|
|
1053
1046
|
static isValidHex(t) {
|
|
1054
1047
|
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t);
|
|
1055
1048
|
}
|
|
@@ -1070,7 +1063,7 @@ function K(r) {
|
|
|
1070
1063
|
});
|
|
1071
1064
|
return r.prototype.constructor = e, e;
|
|
1072
1065
|
}
|
|
1073
|
-
const
|
|
1066
|
+
const x = {
|
|
1074
1067
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
1075
1068
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
1076
1069
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -1087,7 +1080,7 @@ class I {
|
|
|
1087
1080
|
listeners = {};
|
|
1088
1081
|
debugMode;
|
|
1089
1082
|
constructor(t = !1) {
|
|
1090
|
-
this.debugMode = t, Object.keys(
|
|
1083
|
+
this.debugMode = t, Object.keys(x).forEach(
|
|
1091
1084
|
(e) => {
|
|
1092
1085
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
1093
1086
|
}
|
|
@@ -1103,7 +1096,7 @@ class I {
|
|
|
1103
1096
|
* @param listener 监听函数
|
|
1104
1097
|
*/
|
|
1105
1098
|
on(t, e) {
|
|
1106
|
-
this.debugLog(`添加事件监听: ${
|
|
1099
|
+
this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
|
|
1107
1100
|
}
|
|
1108
1101
|
/**
|
|
1109
1102
|
* 触发事件
|
|
@@ -1111,11 +1104,11 @@ class I {
|
|
|
1111
1104
|
* @param params 事件参数
|
|
1112
1105
|
*/
|
|
1113
1106
|
emit(t, e) {
|
|
1114
|
-
this.debugLog(`触发事件: ${
|
|
1107
|
+
this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
|
|
1115
1108
|
try {
|
|
1116
1109
|
s(e);
|
|
1117
1110
|
} catch (i) {
|
|
1118
|
-
console.error(`事件 ${
|
|
1111
|
+
console.error(`事件 ${x[t]} 处理出错:`, i);
|
|
1119
1112
|
}
|
|
1120
1113
|
});
|
|
1121
1114
|
}
|
|
@@ -1125,7 +1118,7 @@ class I {
|
|
|
1125
1118
|
* @param listener 监听函数
|
|
1126
1119
|
*/
|
|
1127
1120
|
off(t, e) {
|
|
1128
|
-
this.debugLog(`移除事件监听: ${
|
|
1121
|
+
this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
|
|
1129
1122
|
}
|
|
1130
1123
|
/**
|
|
1131
1124
|
* 添加一次性事件监听器
|
|
@@ -1133,7 +1126,7 @@ class I {
|
|
|
1133
1126
|
* @param listener 监听函数
|
|
1134
1127
|
*/
|
|
1135
1128
|
once(t, e) {
|
|
1136
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
1129
|
+
this.debugLog(`添加一次性事件监听: ${x[t]}`);
|
|
1137
1130
|
const s = (i) => {
|
|
1138
1131
|
e(i), this.off(t, s);
|
|
1139
1132
|
};
|
|
@@ -1186,74 +1179,100 @@ String.prototype.sliceByPoint = function(r, t = this.pointLength()) {
|
|
|
1186
1179
|
e += this.pointAt(s);
|
|
1187
1180
|
return e;
|
|
1188
1181
|
};
|
|
1189
|
-
|
|
1190
|
-
return
|
|
1182
|
+
String.prototype.capitalize = function() {
|
|
1183
|
+
return this ? this.charAt(0).toUpperCase() + this.slice(1).toLowerCase() : this;
|
|
1191
1184
|
};
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
let t = null, e = this;
|
|
1195
|
-
for (; e; ) {
|
|
1196
|
-
const s = e.closest(r);
|
|
1197
|
-
if (!s)
|
|
1198
|
-
break;
|
|
1199
|
-
t = s, e = s.parentElement;
|
|
1200
|
-
}
|
|
1201
|
-
return t;
|
|
1185
|
+
String.prototype.reverse = function() {
|
|
1186
|
+
return this.split("").reverse().join("");
|
|
1202
1187
|
};
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1188
|
+
String.prototype.truncate = function(r, t = "...") {
|
|
1189
|
+
return this.length <= r ? this : this.slice(0, r - t.length) + t;
|
|
1190
|
+
};
|
|
1191
|
+
String.prototype.isPalindrome = function() {
|
|
1192
|
+
const r = this.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1193
|
+
return r === r.reverse();
|
|
1194
|
+
};
|
|
1195
|
+
String.prototype.count = function(r) {
|
|
1196
|
+
const t = r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1197
|
+
return (this.match(new RegExp(t, "g")) || []).length;
|
|
1198
|
+
};
|
|
1199
|
+
String.prototype.toCamelCase = function() {
|
|
1200
|
+
return this.replace(/_([a-z])/g, (r, t) => t.toUpperCase());
|
|
1201
|
+
};
|
|
1202
|
+
String.prototype.toSnakeCase = function() {
|
|
1203
|
+
return this.replace(/[A-Z]/g, (r) => `_${r.toLowerCase()}`);
|
|
1204
|
+
};
|
|
1205
|
+
String.prototype.format = function(...r) {
|
|
1206
|
+
return this.replace(/{(\d+)}/g, (t, e) => r[e] || "");
|
|
1207
|
+
};
|
|
1208
|
+
class V {
|
|
1209
|
+
static random(t = 8) {
|
|
1210
|
+
const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
1211
|
+
let s = "";
|
|
1212
|
+
for (let i = 0; i < t; i++)
|
|
1213
|
+
s += e.charAt(Math.floor(Math.random() * e.length));
|
|
1214
|
+
return s;
|
|
1215
|
+
}
|
|
1216
|
+
static template(t, e) {
|
|
1217
|
+
return t.replace(/\${(\w+)}/g, (s, i) => e[i] || "");
|
|
1218
|
+
}
|
|
1219
|
+
static escapeHtml(t) {
|
|
1220
|
+
const e = {
|
|
1221
|
+
"&": "&",
|
|
1222
|
+
"<": "<",
|
|
1223
|
+
">": ">",
|
|
1224
|
+
'"': """,
|
|
1225
|
+
"'": "'",
|
|
1226
|
+
" ": " ",
|
|
1227
|
+
"±": "±",
|
|
1228
|
+
"×": "×",
|
|
1229
|
+
"÷": "÷",
|
|
1230
|
+
"≠": "≠",
|
|
1231
|
+
"≤": "≤",
|
|
1232
|
+
"≥": "≥"
|
|
1233
|
+
}, s = new RegExp(
|
|
1234
|
+
`[${Object.keys(e).join("")}]`,
|
|
1235
|
+
"g"
|
|
1236
|
+
);
|
|
1237
|
+
return t.replace(s, (i) => e[i]);
|
|
1238
|
+
}
|
|
1239
|
+
static isEmail(t) {
|
|
1240
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t);
|
|
1241
|
+
}
|
|
1242
|
+
static isUrl(t) {
|
|
1243
|
+
try {
|
|
1244
|
+
return new URL(t), !0;
|
|
1245
|
+
} catch {
|
|
1246
|
+
return !1;
|
|
1220
1247
|
}
|
|
1221
1248
|
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
if (!this.nodeValue || !r || !t) return null;
|
|
1225
|
-
const s = r.split("."), i = s[0], n = s.slice(1).join(" "), h = this.textContent.indexOf(t);
|
|
1226
|
-
if (h < 0) return null;
|
|
1227
|
-
const o = document.createRange();
|
|
1228
|
-
o.setStart(this, h), o.setEnd(this, h + t.length);
|
|
1229
|
-
const c = document.createElement(i);
|
|
1230
|
-
return n && (c.className = n), o.surroundContents(c), c;
|
|
1231
|
-
};
|
|
1249
|
+
}
|
|
1250
|
+
Object.assign(String, V);
|
|
1232
1251
|
export {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1252
|
+
X as BitPerm,
|
|
1253
|
+
W as Color,
|
|
1254
|
+
C as Dictionary,
|
|
1236
1255
|
I as Emitter,
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
j as LRU,
|
|
1256
|
+
_ as Graph,
|
|
1257
|
+
U as LRU,
|
|
1240
1258
|
g as Line,
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1259
|
+
$ as LinkedList,
|
|
1260
|
+
E as Matrix,
|
|
1261
|
+
D as MaxHeap,
|
|
1244
1262
|
T as MemoizeMap,
|
|
1245
1263
|
O as MinHeap,
|
|
1246
|
-
|
|
1264
|
+
j as MinStack,
|
|
1247
1265
|
G as Num,
|
|
1248
|
-
|
|
1249
|
-
|
|
1266
|
+
o as Point,
|
|
1267
|
+
z as Queue,
|
|
1250
1268
|
B as Roman,
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1269
|
+
q as Stack,
|
|
1270
|
+
Q as Str,
|
|
1271
|
+
V as StringExtensions,
|
|
1272
|
+
l as Triangle,
|
|
1254
1273
|
w as Vector,
|
|
1255
1274
|
Z as binarySearchTemplate,
|
|
1256
|
-
|
|
1275
|
+
F as isValidBracket,
|
|
1257
1276
|
K as singleton,
|
|
1258
|
-
|
|
1277
|
+
H as sleep
|
|
1259
1278
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`;return t}}class y{_data;static zero(t){return new y(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new y(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new y(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new y(...e)}mul(t){return new y(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class I{_matrix;static zero(t,e){return new I(Array.from({length:t},()=>Array.from({length:e},()=>0)))}static rotate(t){const e=t.length;for(let s=0;s<(e+1)/2;s++)for(let i=s;i<e/2;i++){const n=t[e-1-i][s];t[e-1-i][s]=t[e-1-s][e-1-i],t[e-1-s][e-1-i]=t[i][e-1-s],t[i][e-1-s]=t[s][i],t[s][i]=n}return t}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new y(...this._matrix[t])}colVector(t){return new y(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new I(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new I(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new I(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=I.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class u{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return u.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=f.EPSILON){const i=f.sloped(t),n=f.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=f.EPSILON){if(f.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,h=t.p2.x,c=t.p2.y,l=e.p1.x,g=e.p1.y,w=e.p2.x,o=e.p2.y,d=(i-h)*(g-o)-(n-c)*(l-w);if(Math.abs(d)<s)return null;const m=((i-l)*(g-o)-(n-g)*(l-w))/d,S=-((i-h)*(n-g)-(n-c)*(i-l))/d;if(m>=0&&m<=1&&S>=0&&S<=1){const Z=i+m*(h-i),J=n+m*(c-n);return new u(Z,J)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=f.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,h=t.p2.x-t.p1.x,c=t.p2.y-t.p1.y,l=i*h+n*c,g=h*h+c*c;let w=-1;g>s&&(w=l/g);let o,d;w<0?(o=t.p1.x,d=t.p1.y):w>1?(o=t.p2.x,d=t.p2.y):(o=t.p1.x+w*h,d=t.p1.y+w*c);const m=e.x-o,S=e.y-d;return Math.hypot(m+S)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new u(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<f.EPSILON)return new u(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new u(e,s)}get start(){return this.p1}get end(){return this.p2}}class O{static EPSILON=1e-10;name;constructor(t){this.name=t}}class p extends O{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,g)=>l-g),[n,h,c]=i;return Math.abs(n-h)<p.EPSILON&&Math.abs(h-c)<p.EPSILON?"equilateral":Math.abs(n-h)<p.EPSILON||Math.abs(h-c)<p.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!p.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),h=Math.PI-i-n;return[i,n,h]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<O.EPSILON}get side(){return[u.distance(this.p1,this.p2),u.distance(this.p2,this.p3),u.distance(this.p3,this.p1)]}perimeter(){return p.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return p.area(t,e,s)}get type(){const[t,e,s]=this.side;return p.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return p.getAngles(t,e,s)}get centroid(){return new u((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,h=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new u(n,h)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<p.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new u(e,s)}containsPoint(t){const e=p.area(u.distance(t,this.p1),u.distance(t,this.p2),u.distance(this.p1,this.p2)),s=p.area(u.distance(t,this.p2),u.distance(t,this.p3),u.distance(this.p2,this.p3)),i=p.area(u.distance(t,this.p3),u.distance(t,this.p1),u.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<p.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function H(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function M(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class T{map=new Map;weakMap=new WeakMap;set(t,e){M(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return M(t)?this.weakMap.get(t):this.map.get(t)}has(t){return M(t)?this.weakMap.has(t):this.map.has(t)}}function _(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],h=n[t[i].length-1];if(h<s){t[i+1]=[...n,s];break}else h>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class B{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const h of t)if(!e.has(h))throw new Error(`Invalid Roman numeral character: ${h}`);let s=0,i=0;for(;i<t.length;){const h=t.slice(i,i+2);if(this.ROMAN_MAP.has(h))s+=this.ROMAN_MAP.get(h),i+=2;else{const c=t[i],l=this.ROMAN_MAP.get(c);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}class F{static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(t<2)return t;let e=0,s=1;for(let i=2;i<t;i++)[e,s]=[s,(e+s)%1000000007];return s}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((o,d)=>o+d,0);if(s===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),h=t.map(o=>o/s*n),c=h.map(o=>Math.floor(o)),l=h.map((o,d)=>o-c[d]);let g=c.reduce((o,d)=>o+d,0),w=n-g;for(;w>0;){let o=-1,d=-1;for(let m=0;m<l.length;m++)l[m]>d&&(d=l[m],o=m);if(o===-1)break;c[o]++,l[o]=0,w--}return c.map(o=>`${(o/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let s=new BigInt64Array(new Float32Array([t]).buffer)[0];s=0x1ff7a3bea91d9b1bn+(s>>1n);let i=new Float64Array(new BigInt64Array([s]).buffer)[0];return i=i*.5+e/i,i=i*.5+e/i,i=i*.5+e/i,i}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const i=t%10;e=e*10+i,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let i=0;for(let n=0;n<s;n++)i+=Math.pow(parseInt(e[n]),s);return i===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,i)=>s+Number(i)*Number(i),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static middle(t,e){return e-(e-t>>1)}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const i=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/i)+s[0]}static isRange(t,e,s){if(s==null&&(s=e,e=0),e>=s)throw new Error("The maximum value must be greater than the minimum value");return e<=t&&t<s}static clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}static random(t,e){if(e==null&&(e=t,t=0),t>=e)throw new Error("The maximum value must be greater than the minimum value");return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(this.random(t,e))}static round(t,e=0){if(!Number.isInteger(e))throw new Error("precision must be an integer");const s=Math.pow(10,e);return Math.round(t*s)/s}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static fastPower(t,e){if(t<0)throw new Error("a must be greater than 0");if(e<0||!Number.isInteger(e))throw new Error("n must be a non-negative integer");if(t===0)return 0;if(e===0)return 1;const s=this.fastPower(t,e>>1);return e%2===0?s*s:s*s*t}static consecutiveSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)/2}static consecutiveSquaresSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}}class G{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class Q{static longestCommonPrefix(t){if(!t.length)return"";let e=t[0];for(let s=1;s<t.length;s++)for(;!t[s].startsWith(e);)if(e=e.slice(0,-1),e==="")return"";return e}static uuid(t){return typeof t=="number"?(t^Math.random()*16>>t/4).toString(16):(9987e3+-1e11).toString().replace(/[018]/g,e=>{const s=parseInt(e,10);return this.uuid(s)})}}class W{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}function X(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const x={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class v{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(x).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return v.instance||(v.instance=new v(t)),v.instance}on(t,e){this.debugLog(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}function K(r,t,e){let s=-1,i=r.length,n;for(;i-s>1;)n=i-(i-s)>>1,e(r[n],t)?i=n:s=n;return i}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),h=this.textContent.indexOf(t);if(h<0)return null;const c=document.createRange();c.setStart(this,h),c.setEnd(this,h+t.length);const l=document.createElement(i);return n&&(l.className=n),c.surroundContents(l),l},a.BitPerm=G,a.Color=W,a.Dictionary=N,a.Emitter=v,a.Graph=U,a.LIS=_,a.LRU=j,a.Line=f,a.LinkedList=D,a.Matrix=I,a.MaxHeap=V,a.MemoizeMap=T,a.MinHeap=A,a.MinStack=R,a.Num=F,a.Point=u,a.Queue=b,a.Roman=B,a.Stack=C,a.Str=Q,a.Triangle=p,a.Vector=y,a.binarySearchTemplate=K,a.isValidBracket=H,a.singleton=X,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(h,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(h=typeof globalThis<"u"?globalThis:h||self,S(h["jc-structure"]={}))})(this,(function(h){"use strict";class S{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e)}for(const e of t)Array.isArray(e)?this.batchEnqueue(e):this.enqueueItem(e);return this}batchEnqueue(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.isValidItem(s)&&(this.items[this.count]=s,this.count++)}),this}enqueueItem(t){if(!this.isValidItem(t))throw new Error("Invalid item");return this.items[this.count]=t,this.count++,this}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class C{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;if(t.length===1){const e=t[0];return Array.isArray(e)?this.addItems(e):this.addItem(e)}for(const e of t)Array.isArray(e)?this.addItems(e):this.addItem(e);return this}addItem(t){if(!this.isValidItem(t))throw new Error("Invalid item: item cannot be null or undefined");return this.items[this.count]=t,this.count++,this}addItems(t){return t.filter(s=>this.isValidItem(s)).forEach(s=>{this.items[this.count]=s,this.count++}),this}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}class V{stack=[];minStack=[];push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t)}pop(){const t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}isEmpty(){return this.size()===0}size(){return this.stack.length}clear(){this.stack=[],this.minStack=[]}toString(){return this.isEmpty()?"":`MinStack(count: ${this.size()}):[${this.getMin()},...rest]`}}function A(r,t){return r===t?0:r<t?-1:1}class E{heap=[];compareFn;constructor(t=A){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class P extends E{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=E.getLeftIndex(e),i=E.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(E.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=E.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)E.swap(this.heap,e,t),t=e,e=E.getParentIndex(t)}}class z extends P{constructor(t=(e,s)=>A(s,e)){super(t)}}function j(r){return{value:r}}class q{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=j(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}class k{value;next=void 0}class D{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new k;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new k;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class U{key;value;constructor(t,e){this.key=t,this.value=e}}function L(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class O{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(L(t))throw new Error("key is required");if(L(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new U(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class ${isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new O}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
|
|
2
|
+
`;return t}}class y{_data;static zero(t){return new y(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new y(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new y(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new y(...e)}mul(t){return new y(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class I{_matrix;static zero(t,e){return new I(Array.from({length:t},()=>Array.from({length:e},()=>0)))}static rotate(t){const e=t.length;for(let s=0;s<(e+1)/2;s++)for(let i=s;i<e/2;i++){const n=t[e-1-i][s];t[e-1-i][s]=t[e-1-s][e-1-i],t[e-1-s][e-1-i]=t[i][e-1-s],t[i][e-1-s]=t[s][i],t[s][i]=n}return t}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new y(...this._matrix[t])}colVector(t){return new y(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new I(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new I(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new I(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=I.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class u{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return u.distance(this,t)}}class f{static EPSILON=1e-10;static sloped(t,e=f.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=f.EPSILON){const i=f.sloped(t),n=f.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=f.EPSILON){if(f.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,a=t.p2.x,l=t.p2.y,d=e.p1.x,g=e.p1.y,w=e.p2.x,o=e.p2.y,p=(i-a)*(g-o)-(n-l)*(d-w);if(Math.abs(p)<s)return null;const m=((i-d)*(g-o)-(n-g)*(d-w))/p,b=-((i-a)*(n-g)-(n-l)*(i-d))/p;if(m>=0&&m<=1&&b>=0&&b<=1){const Z=i+m*(a-i),J=n+m*(l-n);return new u(Z,J)}return null}static isIntersecting(t,e){return f.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=f.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,a=t.p2.x-t.p1.x,l=t.p2.y-t.p1.y,d=i*a+n*l,g=a*a+l*l;let w=-1;g>s&&(w=d/g);let o,p;w<0?(o=t.p1.x,p=t.p1.y):w>1?(o=t.p2.x,p=t.p2.y):(o=t.p1.x+w*a,p=t.p1.y+w*l);const m=e.x-o,b=e.y-p;return Math.hypot(m+b)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new u(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=f.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<f.EPSILON)return new u(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new u(e,s)}get start(){return this.p1}get end(){return this.p2}}class N{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends N{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((d,g)=>d-g),[n,a,l]=i;return Math.abs(n-a)<c.EPSILON&&Math.abs(a-l)<c.EPSILON?"equilateral":Math.abs(n-a)<c.EPSILON||Math.abs(a-l)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),a=Math.PI-i-n;return[i,n,a]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<N.EPSILON}get side(){return[u.distance(this.p1,this.p2),u.distance(this.p2,this.p3),u.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new u((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,a=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new u(n,a)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new u(e,s)}containsPoint(t){const e=c.area(u.distance(t,this.p1),u.distance(t,this.p2),u.distance(this.p1,this.p2)),s=c.area(u.distance(t,this.p2),u.distance(t,this.p3),u.distance(this.p2,this.p3)),i=c.area(u.distance(t,this.p3),u.distance(t,this.p1),u.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function _(r){return new Promise(t=>setTimeout(t,r))}function H(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function M(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class T{map=new Map;weakMap=new WeakMap;set(t,e){M(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return M(t)?this.weakMap.get(t):this.map.get(t)}has(t){return M(t)?this.weakMap.has(t):this.map.has(t)}}class B{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const a of t)if(!e.has(a))throw new Error(`Invalid Roman numeral character: ${a}`);let s=0,i=0;for(;i<t.length;){const a=t.slice(i,i+2);if(this.ROMAN_MAP.has(a))s+=this.ROMAN_MAP.get(a),i+=2;else{const l=t[i],d=this.ROMAN_MAP.get(l);if(!d)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=d,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}class F{static isValidPositiveInteger(t){return Number.isInteger(t)&&t>0&&t<=Number.MAX_SAFE_INTEGER}static isPowerOfTwo(t){return t>0&&(t&t-1)===0}static isOdd(t){return t%2===1||t%2===-1}static factorial(t){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");if(t<2)return 1;let e=1;for(let s=2;s<=t;s++)e*=s;return e}static fibonacci(t,e=1,s=1){if(!this.isValidPositiveInteger(t))throw new Error("Input must be a non-negative integer");return t<2?s:this.fibonacci(t-1,s,s+e)}static fibonacciIterative(t){if(t<2)return t;let e=0,s=1;for(let i=2;i<t;i++)[e,s]=[s,(e+s)%1000000007];return s}static getPercentWithPrecision(t,e=2){if(!Array.isArray(t)||t.length===0)return[];if(e<0||!Number.isInteger(e))throw new Error("Precision must be a non-negative integer");const s=t.reduce((o,p)=>o+p,0);if(s===0)return t.map(()=>"0%");const n=100*Math.pow(10,e),a=t.map(o=>o/s*n),l=a.map(o=>Math.floor(o)),d=a.map((o,p)=>o-l[p]);let g=l.reduce((o,p)=>o+p,0),w=n-g;for(;w>0;){let o=-1,p=-1;for(let m=0;m<d.length;m++)d[m]>p&&(p=d[m],o=m);if(o===-1)break;l[o]++,d[o]=0,w--}return l.map(o=>`${(o/n*100).toFixed(e)}%`)}static fastSqrt(t){if(t<0)throw new Error("n must be a non-negative number");const e=.5*t;let s=new BigInt64Array(new Float32Array([t]).buffer)[0];s=0x1ff7a3bea91d9b1bn+(s>>1n);let i=new Float64Array(new BigInt64Array([s]).buffer)[0];return i=i*.5+e/i,i=i*.5+e/i,i=i*.5+e/i,i}static gcd(t,e){return e===0?t:this.gcd(e,t%e)}static lcm(t,e){return t*e/this.gcd(t,e)}static isPrime(t){if(t<=1)return!1;for(let e=2;e<=Math.sqrt(t);e++)if(t%e===0)return!1;return!0}static isPalindrome(t){if(t<0||t%10===0&&t!==0)return!1;let e=0,s=t;for(;t>0;){const i=t%10;e=e*10+i,t=Math.floor(t/10)}return s===e}static isArmstrong(t){const e=t.toString(),s=e.length;let i=0;for(let n=0;n<s;n++)i+=Math.pow(parseInt(e[n]),s);return i===t}static isHappy(t){const e=new Set;for(;t!==1;){if(e.has(t))return!1;e.add(t),t=(t+"").split("").reduce((s,i)=>s+Number(i)*Number(i),0)}return!0}static isPerfect(t){let e=0;for(let s=1;s<t;s++)t%s===0&&(e+=s);return e===t}static middle(t,e){return e-(e-t>>1)}static scale(t,e,s){if(e[0]>=e[1]||s[0]>=s[1])throw new Error("Invalid range");t=this.clamp(t,e[0],e[1]);const i=e[1]-e[0];return(t-e[0])*((s[1]-s[0])/i)+s[0]}static isRange(t,e,s){if(s==null&&(s=e,e=0),e>=s)throw new Error("The maximum value must be greater than the minimum value");return e<=t&&t<s}static clamp(t,e,s){return s==null?Math.min(t,e):Math.min(Math.max(t,e),s)}static random(t,e){if(e==null&&(e=t,t=0),t>=e)throw new Error("The maximum value must be greater than the minimum value");return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(this.random(t,e))}static round(t,e=0){if(!Number.isInteger(e))throw new Error("precision must be an integer");const s=Math.pow(10,e);return Math.round(t*s)/s}static floatEqual(t,e,s=1e-6){return Math.abs(t-e)<s}static isSameSign(t,e){return t>=0&&e>=0||t<=0&&e<=0}static fastPower(t,e){if(t<0)throw new Error("a must be greater than 0");if(e<0||!Number.isInteger(e))throw new Error("n must be a non-negative integer");if(t===0)return 0;if(e===0)return 1;const s=this.fastPower(t,e>>1);return e%2===0?s*s:s*s*t}static consecutiveSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)/2}static consecutiveSquaresSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)/6}static consecutivecubesSum(t){if(!this.isValidPositiveInteger)throw new Error("n must be a positive integer");return t*(t+1)*(2*t+1)*(3*t*t+3*t-1)/30}}class G{static READ=1;static WRITE=2;static SHARE=4;static DELETE=8;static CREATE=16;static include(t,e){return(t&e)===e}static add(t,e){return t|e}static remove(t,e){return t&~e}static toggle(t,e){return t^e}}class Q extends String{static frequencyStatistics(t){return[...t].reduce((e,s)=>(e[s]=(e[s]||0)+1,e),{})}}class X{static isValidHex(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)}static isValidRGB(t){return/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.test(t)}}function W(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const x={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class v{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(x).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return v.instance||(v.instance=new v(t)),v.instance}on(t,e){this.debugLog(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}function K(r,t,e){let s=-1,i=r.length,n;for(;i-s>1;)n=i-(i-s)>>1,e(r[n],t)?i=n:s=n;return i}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},String.prototype.capitalize=function(){return this?this.charAt(0).toUpperCase()+this.slice(1).toLowerCase():this},String.prototype.reverse=function(){return this.split("").reverse().join("")},String.prototype.truncate=function(r,t="..."){return this.length<=r?this:this.slice(0,r-t.length)+t},String.prototype.isPalindrome=function(){const r=this.toLowerCase().replace(/[^a-z0-9]/g,"");return r===r.reverse()},String.prototype.count=function(r){const t=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return(this.match(new RegExp(t,"g"))||[]).length},String.prototype.toCamelCase=function(){return this.replace(/_([a-z])/g,(r,t)=>t.toUpperCase())},String.prototype.toSnakeCase=function(){return this.replace(/[A-Z]/g,r=>`_${r.toLowerCase()}`)},String.prototype.format=function(...r){return this.replace(/{(\d+)}/g,(t,e)=>r[e]||"")};class R{static random(t=8){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let s="";for(let i=0;i<t;i++)s+=e.charAt(Math.floor(Math.random()*e.length));return s}static template(t,e){return t.replace(/\${(\w+)}/g,(s,i)=>e[i]||"")}static escapeHtml(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"," ":" ","±":"±","×":"×","÷":"÷","≠":"≠","≤":"≤","≥":"≥"},s=new RegExp(`[${Object.keys(e).join("")}]`,"g");return t.replace(s,i=>e[i])}static isEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}static isUrl(t){try{return new URL(t),!0}catch{return!1}}}Object.assign(String,R),h.BitPerm=G,h.Color=X,h.Dictionary=O,h.Emitter=v,h.Graph=$,h.LRU=q,h.Line=f,h.LinkedList=D,h.Matrix=I,h.MaxHeap=z,h.MemoizeMap=T,h.MinHeap=P,h.MinStack=V,h.Num=F,h.Point=u,h.Queue=S,h.Roman=B,h.Stack=C,h.Str=Q,h.StringExtensions=R,h.Triangle=c,h.Vector=y,h.binarySearchTemplate=K,h.isValidBracket=H,h.singleton=W,h.sleep=_,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference path="./types/string.extensions.d.ts"/>
|
|
2
|
+
|
|
1
3
|
declare module "jc-structure" {
|
|
2
4
|
/**
|
|
3
5
|
* #### 数据结构接口
|
|
@@ -581,18 +583,18 @@ declare module "jc-structure" {
|
|
|
581
583
|
* #### 计算最长递增子序列(Longest Increasing Subsequence, LIS)
|
|
582
584
|
* @param nums
|
|
583
585
|
*/
|
|
584
|
-
export function LIS(nums: Array<number>): Array<number>;
|
|
586
|
+
// export function LIS(nums: Array<number>): Array<number>;
|
|
585
587
|
/**
|
|
586
588
|
* #### 睡眠函数
|
|
587
589
|
* @param ms 毫秒
|
|
588
590
|
*/
|
|
589
|
-
export function sleep(ms: number): Promise<void>;
|
|
591
|
+
// export function sleep(ms: number): Promise<void>;
|
|
590
592
|
|
|
591
593
|
/**
|
|
592
594
|
* #### 判断字符串是否是有效的成对括号
|
|
593
595
|
* @param str 含括号的字符串
|
|
594
596
|
*/
|
|
595
|
-
export function isValidBracket(str: string): boolean;
|
|
597
|
+
// export function isValidBracket(str: string): boolean;
|
|
596
598
|
|
|
597
599
|
interface NumConstructor {
|
|
598
600
|
new (value?: any): Number;
|
|
@@ -844,8 +846,8 @@ declare module "jc-structure" {
|
|
|
844
846
|
new (value?: any): String;
|
|
845
847
|
readonly prototype: String;
|
|
846
848
|
|
|
847
|
-
longestCommonPrefix(strs: string[]): string;
|
|
848
|
-
uuid(a?: number | string): string;
|
|
849
|
+
// longestCommonPrefix(strs: string[]): string;
|
|
850
|
+
// uuid(a?: number | string): string;
|
|
849
851
|
}
|
|
850
852
|
declare var Str: StrConstructor;
|
|
851
853
|
}
|
package/package.json
CHANGED
package/types/global.d.ts
CHANGED
|
@@ -32,3 +32,44 @@ interface CompareFn<T> {
|
|
|
32
32
|
interface Obj<V = any> {
|
|
33
33
|
[key: string]: V;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
interface RegExpConstructor {
|
|
37
|
+
/**
|
|
38
|
+
* #### 转义正则表达式中的特殊字符
|
|
39
|
+
* @param str 字符串
|
|
40
|
+
*/
|
|
41
|
+
escape(str: string): string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface Element {
|
|
45
|
+
/**
|
|
46
|
+
* #### 获取最深元素集合中的第一个元素
|
|
47
|
+
*/
|
|
48
|
+
readonly firstElement: Element | null;
|
|
49
|
+
/**
|
|
50
|
+
* #### 获取最深元素集合中的最后一个元素
|
|
51
|
+
*/
|
|
52
|
+
readonly lastElement: Element | null;
|
|
53
|
+
/**
|
|
54
|
+
* #### 最祖先的匹配元素
|
|
55
|
+
* @param this element
|
|
56
|
+
* @param selector 选择器
|
|
57
|
+
*/
|
|
58
|
+
farthest<E extends Element = Element>(this: E, selector: string): E | null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface Text {
|
|
62
|
+
/**
|
|
63
|
+
* #### 将文本节点包裹在指定标签中
|
|
64
|
+
* @param this Text 该文本节点
|
|
65
|
+
* @param selector 要包裹的元素标签,默认为:'strong'
|
|
66
|
+
* @param text 要包裹的文本,默认为:''
|
|
67
|
+
*/
|
|
68
|
+
surround(this: Text, selector?: string, text?: string): HTMLElement | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface Array<T> {
|
|
72
|
+
groupBy<K extends string | number | symbol>(
|
|
73
|
+
generateKey: string | ((item: T, index: number, arr: T[]) => K)
|
|
74
|
+
): Record<K, T[]>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
interface String {
|
|
2
|
+
/**
|
|
3
|
+
* #### 获取字符串码点长度,1个码点对应1个码元或2个码元,譬如 "👍" 长度为2,"a" 长度为1
|
|
4
|
+
* - 计算字符串的码点长度,考虑到 Unicode 字符的特殊性
|
|
5
|
+
* @returns {number} 字符串的码元长度
|
|
6
|
+
*/
|
|
7
|
+
pointLength(this: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* #### 根据码点索引获取对应的字符
|
|
10
|
+
* - 处理 Unicode 字符,确保正确获取码点对应的字符
|
|
11
|
+
* @param index 码点索引
|
|
12
|
+
*/
|
|
13
|
+
pointAt(this: string, index: number): string | undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* #### 根据码点索引切割字符串
|
|
17
|
+
* - 按照码点索引切割字符串,确保不会破坏 Unicode 字符
|
|
18
|
+
* @param start 开始索引
|
|
19
|
+
* @param end 结束索引
|
|
20
|
+
*/
|
|
21
|
+
sliceByPoint(this: string, start: number, end?: number): string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* #### 字符串首字母大写
|
|
25
|
+
*/
|
|
26
|
+
capitalize(): string;
|
|
27
|
+
/**
|
|
28
|
+
* #### 字符串反转
|
|
29
|
+
*/
|
|
30
|
+
reverse(): string;
|
|
31
|
+
/**
|
|
32
|
+
* #### 字符串截断,超出长度时,添加后缀‘...’
|
|
33
|
+
* @param this 字符串实例
|
|
34
|
+
* @param length 指定长度,包含了后缀的长度
|
|
35
|
+
* @param suffix 后缀,默认为‘...’
|
|
36
|
+
*/
|
|
37
|
+
truncate(this: string, length: number, suffix?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* #### 判断字符串是否为回文
|
|
40
|
+
*/
|
|
41
|
+
isPalindrome(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* #### 子字符串在字符串中出现的次数
|
|
44
|
+
* @param substring 子字符串
|
|
45
|
+
*/
|
|
46
|
+
count(substring: string): number;
|
|
47
|
+
/**
|
|
48
|
+
* #### 字符串转驼峰命名
|
|
49
|
+
*/
|
|
50
|
+
toCamelCase(): string;
|
|
51
|
+
/**
|
|
52
|
+
* #### 字符串转下划线命名
|
|
53
|
+
*/
|
|
54
|
+
toSnakeCase(): string;
|
|
55
|
+
/**
|
|
56
|
+
* #### 模板字符串语法,将字符串中的占位符替换为对应的值
|
|
57
|
+
* @param args 占位符对应的值
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* 'Hello, {name}!'.format({name: 'world'}) // 'Hello, world!'
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
format(...args: any[]): string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface StringConstructor {
|
|
67
|
+
/**
|
|
68
|
+
* #### 生成指定长度的随机字符串
|
|
69
|
+
* @param length 长度
|
|
70
|
+
*/
|
|
71
|
+
random(length?: number): string;
|
|
72
|
+
/**
|
|
73
|
+
* #### 模板字符串语法,将字符串中的占位符替换为对应的值
|
|
74
|
+
* @param template
|
|
75
|
+
* @param values
|
|
76
|
+
*/
|
|
77
|
+
template(template: string, values: Record<string, any>): string;
|
|
78
|
+
/**
|
|
79
|
+
* #### 安全转义 HTML 字符串,防止 XSS 攻击
|
|
80
|
+
* @param str
|
|
81
|
+
*/
|
|
82
|
+
escapeHtml(str: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* #### 是否是有效的邮箱地址
|
|
85
|
+
* @param str
|
|
86
|
+
*/
|
|
87
|
+
isEmail(str: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* #### 是否是URL地址
|
|
90
|
+
* @param str
|
|
91
|
+
*/
|
|
92
|
+
isUrl(str: string): boolean;
|
|
93
|
+
}
|
package/types/extend.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
interface String {
|
|
2
|
-
/**
|
|
3
|
-
* #### 获取字符串码点长度,1个码点对应1个码元或2个码元,譬如 "👍" 长度为2,"a" 长度为1
|
|
4
|
-
* - 计算字符串的码点长度,考虑到 Unicode 字符的特殊性
|
|
5
|
-
* @returns {number} 字符串的码元长度
|
|
6
|
-
*/
|
|
7
|
-
pointLength(this: string): number;
|
|
8
|
-
/**
|
|
9
|
-
* #### 根据码点索引获取对应的字符
|
|
10
|
-
* - 处理 Unicode 字符,确保正确获取码点对应的字符
|
|
11
|
-
* @param index 码点索引
|
|
12
|
-
*/
|
|
13
|
-
pointAt(this: string, index: number): string | undefined;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* #### 根据码点索引切割字符串
|
|
17
|
-
* - 按照码点索引切割字符串,确保不会破坏 Unicode 字符
|
|
18
|
-
* @param start 开始索引
|
|
19
|
-
* @param end 结束索引
|
|
20
|
-
*/
|
|
21
|
-
sliceByPoint(this: string, start: number, end?: number): string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface RegExpConstructor {
|
|
25
|
-
/**
|
|
26
|
-
* #### 转义正则表达式中的特殊字符
|
|
27
|
-
* @param str 字符串
|
|
28
|
-
*/
|
|
29
|
-
escape(str: string): string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface Element {
|
|
33
|
-
/**
|
|
34
|
-
* #### 获取最深元素集合中的第一个元素
|
|
35
|
-
*/
|
|
36
|
-
readonly firstElement: Element | null;
|
|
37
|
-
/**
|
|
38
|
-
* #### 获取最深元素集合中的最后一个元素
|
|
39
|
-
*/
|
|
40
|
-
readonly lastElement: Element | null;
|
|
41
|
-
/**
|
|
42
|
-
* #### 最祖先的匹配元素
|
|
43
|
-
* @param this element
|
|
44
|
-
* @param selector 选择器
|
|
45
|
-
*/
|
|
46
|
-
farthest<E extends Element = Element>(this: E, selector: string): E | null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface Text {
|
|
50
|
-
/**
|
|
51
|
-
* #### 将文本节点包裹在指定标签中
|
|
52
|
-
* @param this Text 该文本节点
|
|
53
|
-
* @param selector 要包裹的元素标签,默认为:'strong'
|
|
54
|
-
* @param text 要包裹的文本,默认为:''
|
|
55
|
-
*/
|
|
56
|
-
surround(this: Text, selector?: string, text?: string): HTMLElement | null;
|
|
57
|
-
}
|