@tktb-tess/util-fns 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,10 +26,21 @@ console.log(bailliePSW(4n)): // false
26
26
 
27
27
  ### CDN
28
28
 
29
- You can also use CDN such as jsDelivr.
29
+ You can also use it via CDN such as jsDelivr.
30
30
 
31
31
  ```html
32
- <script src="https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.9/dist/bundle.min.js"></script>
32
+ <!-- You can import it as a global variable -->
33
+ <script src="https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.9.3/dist/bundle.min.js"></script>
34
+ <script type="module">
35
+ const { modPow } = UtilFns;
36
+ // ...
37
+ </script>
38
+
39
+ <!-- or as an ES Module -->
40
+ <script type="module">
41
+ import { modPow } from 'https://cdn.jsdelivr.net/npm/@tktb-tess/util-fns@0.9.3/+esm';
42
+ // ...
43
+ </script>
33
44
  ```
34
45
 
35
46
 
package/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
1
+ const _ = new TextEncoder(), W = (n, t) => [n].includes(t), g = (n, t) => {
2
2
  if (typeof n != typeof t) return !1;
3
3
  const e = Object.prototype.toString.call(n), r = Object.prototype.toString.call(t);
4
4
  if (e !== r) return !1;
@@ -37,7 +37,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
37
37
  throw Error(`comparing these objects is unavailable: ${n}, ${t}`, {
38
38
  cause: [n, t]
39
39
  });
40
- }, G = () => {
40
+ }, X = () => {
41
41
  let n, t;
42
42
  return {
43
43
  promise: new Promise((r, s) => {
@@ -46,9 +46,9 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
46
46
  resolve: n,
47
47
  reject: t
48
48
  };
49
- }, H = (n) => new Promise((t) => {
49
+ }, Y = (n) => new Promise((t) => {
50
50
  setTimeout(() => t(), n);
51
- }), X = (n) => (...t) => () => n(...t), Z = (n) => {
51
+ }), H = (n) => (...t) => () => n(...t), Z = (n) => {
52
52
  const t = [];
53
53
  let e = [], r = "", s = !1;
54
54
  for (let o = 0; o < n.length; o++) {
@@ -58,7 +58,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
58
58
  }
59
59
  return e.push(r.trim()), t.push(e), t;
60
60
  }, Q = async (n, t) => {
61
- const e = v.encode(n), r = await crypto.subtle.digest(t, e);
61
+ const e = _.encode(n), r = await crypto.subtle.digest(t, e);
62
62
  return new Uint8Array(r);
63
63
  }, tt = () => !!globalThis.process && typeof process.version < "u" && typeof process.versions.node < "u", nt = (n) => encodeURIComponent(n).replace(
64
64
  /[!'()*]/g,
@@ -73,31 +73,31 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
73
73
  }, st = async (n, t) => {
74
74
  const r = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
75
75
  return new Response(r).bytes();
76
- }, ot = (n, t) => Math.floor(Math.random() * (t - n) + n), m = (n, t) => {
76
+ }, ot = (n, t) => Math.floor(Math.random() * (t - n) + n), p = (n, t) => {
77
77
  t < 0n && (t *= -1n);
78
78
  const e = n % t;
79
79
  return e < 0n ? e + t : e;
80
- }, E = (n, t = !1) => {
80
+ }, v = (n, t = !1) => {
81
81
  if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
82
82
  if (n <= 0) throw Error("`length` must be positive");
83
83
  const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
84
84
  let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
85
85
  return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
86
- }, _ = (n, t) => {
86
+ }, L = (n, t) => {
87
87
  if (n >= t) throw Error("rangeError");
88
88
  const e = t - n, r = e.toString(2).length, s = (() => {
89
89
  for (let i = 0; i < 1e5; i++) {
90
- const c = E(r);
91
- if (c >= p(2n, BigInt(r), e))
90
+ const c = v(r);
91
+ if (c >= m(2n, BigInt(r), e))
92
92
  return c % e;
93
93
  }
94
94
  throw Error("Failed to generate a random bigint");
95
95
  })();
96
96
  return n + s;
97
- }, p = (n, t, e) => {
97
+ }, m = (n, t, e) => {
98
98
  if (e < 1n) throw Error("`mod` must be positive");
99
99
  if (t < 0n) throw Error("`power` must not be negative");
100
- if (n = m(n, e), e === 1n) return 0n;
100
+ if (n = p(n, e), e === 1n) return 0n;
101
101
  if (n % e === 1n || n % e === 0n) return n;
102
102
  if (n === e - 1n) return t & 1n ? e - 1n : 1n;
103
103
  let r = 1n;
@@ -117,7 +117,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
117
117
  [e, o] = [o, e - a * o], [r, i] = [i, r - a * i], [s, c] = [c, l];
118
118
  }
119
119
  return c < 0n && (o *= -1n, i *= -1n, c *= -1n), { x: o, y: i, gcd: c };
120
- }, b = (n, t) => {
120
+ }, w = (n, t) => {
121
121
  if (n >= t) return 1n;
122
122
  const e = BigInt((t - 2n).toString(2).length), r = (t - n) / 2n;
123
123
  if (e * r < 63n) {
@@ -126,22 +126,22 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
126
126
  c *= a;
127
127
  return c;
128
128
  }
129
- const s = n + r | 1n, o = b(n, s), i = b(s, t);
129
+ const s = n + r | 1n, o = w(n, s), i = w(s, t);
130
130
  return o * i;
131
- }, C = (n) => {
131
+ }, P = (n) => {
132
132
  let t = 3n, e = 1n, r = 1n;
133
133
  const s = BigInt(n.toString(2).length) - 1n;
134
134
  for (let o = s - 1n; o > -1n; --o) {
135
135
  const i = (n >> o) + 1n | 1n;
136
- r *= b(t, i), t = i, e *= r;
136
+ r *= w(t, i), t = i, e *= r;
137
137
  }
138
138
  return e;
139
139
  }, it = (n) => {
140
140
  if (n < 0n) throw Error("'n' must be non-negative");
141
141
  if (n === 0n) return 1n;
142
142
  const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
143
- return C(n) << t;
144
- }, F = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, I = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), U = (n, t) => {
143
+ return P(n) << t;
144
+ }, C = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, I = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), U = (n, t) => {
145
145
  if (t < 1n || t % 2n === 0n)
146
146
  throw Error("`n` is invalid");
147
147
  for (; n < 0n; )
@@ -157,7 +157,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
157
157
  [n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
158
158
  }
159
159
  return t === 1n ? e : 0n;
160
- }, P = (n) => {
160
+ }, O = (n) => {
161
161
  if (n < 0n) return !1;
162
162
  if (n === 0n) return !0;
163
163
  let t = 1n, e = n;
@@ -166,14 +166,14 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
166
166
  r ** 2n < n ? t = r : e = r;
167
167
  }
168
168
  return n === t ** 2n || n === (t + 1n) ** 2n;
169
- }, O = (n) => {
169
+ }, F = (n) => {
170
170
  if (n <= 1n) return !1;
171
171
  if (n % 2n === 0n) return n === 2n;
172
172
  let t = n - 1n, e = 0n;
173
173
  for (; t % 2n === 0n; )
174
174
  t >>= 1n, e += 1n;
175
175
  const [r, s] = [t, e];
176
- let i = p(2n, r, n);
176
+ let i = m(2n, r, n);
177
177
  if (i === 1n) return !0;
178
178
  for (let c = 0n; c < s; c++) {
179
179
  if (i === n - 1n) return !0;
@@ -183,16 +183,16 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
183
183
  }, V = (n) => {
184
184
  let t = 5n, e = U(t, n);
185
185
  for (; e > 0n; ) {
186
- if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && P(n))
186
+ if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && O(n))
187
187
  return [0n, 0n];
188
188
  e = U(t, n);
189
189
  }
190
190
  return [t, e];
191
- }, w = (n, t) => (n & 1n) === 1n ? m(n + t >> 1n, t) : m(n >> 1n, t), $ = (n, t, e, r) => {
191
+ }, b = (n, t) => (n & 1n) === 1n ? p(n + t >> 1n, t) : p(n >> 1n, t), $ = (n, t, e, r) => {
192
192
  let s = 1n, o = e;
193
193
  const i = n.toString(2).slice(1);
194
194
  for (const c of i)
195
- [s, o] = [m(s * o, t), w(o * o + r * s * s, t)], c === "1" && ([s, o] = [w(e * s + o, t), w(r * s + e * o, t)]);
195
+ [s, o] = [p(s * o, t), b(o * o + r * s * s, t)], c === "1" && ([s, o] = [b(e * s + o, t), b(r * s + e * o, t)]);
196
196
  return [s, o];
197
197
  }, k = (n, t, e, r) => {
198
198
  if (n % 2n !== 1n) throw Error("`n` must be odd");
@@ -202,13 +202,13 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
202
202
  const [i, c] = $(s, n, e, t);
203
203
  let a = c;
204
204
  if (i === 0n) return !0;
205
- r = p(r, s, n);
205
+ r = m(r, s, n);
206
206
  for (let l = 0n; l < o; l++) {
207
207
  if (a === 0n) return !0;
208
- a = m(a * a - 2n * r, n), r = p(r, 2n, n);
208
+ a = p(a * a - 2n * r, n), r = m(r, 2n, n);
209
209
  }
210
210
  return !1;
211
- }, x = (n) => {
211
+ }, M = (n) => {
212
212
  if (n <= 1n) return !1;
213
213
  if (n % 2n === 0n) return n === 2n;
214
214
  const t = [
@@ -242,7 +242,7 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
242
242
  for (const o of t)
243
243
  if (n % o === 0n)
244
244
  return n === o;
245
- if (!O(n))
245
+ if (!F(n))
246
246
  return !1;
247
247
  const [e, r] = V(n);
248
248
  if (r === 0n) return !1;
@@ -252,16 +252,16 @@ const v = new TextEncoder(), Y = (n, t) => [n].includes(t), g = (n, t) => {
252
252
  if (t < 2n)
253
253
  throw Error("noPrimesFound");
254
254
  for (let r = 0; r < 1e5; r++) {
255
- const s = _(n, t);
256
- if (x(s)) return s;
255
+ const s = L(n, t);
256
+ if (M(s)) return s;
257
257
  }
258
258
  throw Error("noPrimesFound");
259
259
  }, at = (n, t = !1) => {
260
260
  if (n < 2)
261
261
  throw Error("noPrimesFound");
262
262
  for (let r = 0; r < 1e5; r++) {
263
- const s = E(n, t);
264
- if (x(s)) return s;
263
+ const s = v(n, t);
264
+ if (M(s)) return s;
265
265
  }
266
266
  throw Error("noPrimesFound");
267
267
  };
@@ -269,7 +269,6 @@ class u {
269
269
  #t;
270
270
  #n;
271
271
  static name = "Rational";
272
- [Symbol.toStringTag] = u.name;
273
272
  /**
274
273
  * fraction (rational) class
275
274
  * @param numerator
@@ -415,6 +414,9 @@ class u {
415
414
  return new u(BigInt(s), BigInt(o));
416
415
  }
417
416
  }
417
+ Object.defineProperty(u.prototype, Symbol.toStringTag, {
418
+ value: u.name
419
+ });
418
420
  const D = new TextEncoder(), q = new TextDecoder(), lt = (n, t) => {
419
421
  switch (t) {
420
422
  case "utf-8":
@@ -507,11 +509,10 @@ const D = new TextEncoder(), q = new TextDecoder(), lt = (n, t) => {
507
509
  }
508
510
  return BigInt.asIntN(7 * t, e);
509
511
  };
510
- class N {
512
+ class S {
511
513
  #t;
512
514
  #n;
513
515
  static name = "Queue";
514
- [Symbol.toStringTag] = N.name;
515
516
  /**
516
517
  * Queue
517
518
  * @param data
@@ -549,10 +550,12 @@ class N {
549
550
  return this.toArray().toString();
550
551
  }
551
552
  }
552
- class R extends Error {
553
+ Object.defineProperty(S.prototype, Symbol.toStringTag, {
554
+ value: S.name
555
+ });
556
+ class E extends Error {
553
557
  name;
554
558
  static name = "NamedError";
555
- [Symbol.toStringTag] = R.name;
556
559
  constructor(t, e, r) {
557
560
  super(e, { cause: r }), this.name = t;
558
561
  }
@@ -569,23 +572,25 @@ class R extends Error {
569
572
  };
570
573
  }
571
574
  }
572
- const S = (n) => {
575
+ Object.defineProperty(E.prototype, Symbol.toStringTag, {
576
+ value: E.name
577
+ });
578
+ const B = (n) => {
573
579
  if (n === 0) return 32;
574
580
  let t = 0;
575
581
  for (; n > 0 && !(n & 1); )
576
582
  ++t, n >>>= 1;
577
583
  return t;
578
- }, B = (n) => {
584
+ }, x = (n) => {
579
585
  if (n === 0n) return 64n;
580
586
  let t = 0n;
581
587
  for (; n > 0n && !(n & 1n); )
582
588
  ++t, n >>= 1n;
583
589
  return BigInt.asUintN(64, t);
584
590
  };
585
- class A {
591
+ class N {
586
592
  #t;
587
- static name = "FloatRand";
588
- [Symbol.toStringTag] = A.name;
593
+ static name = "FloatRng";
589
594
  constructor(t) {
590
595
  this.#t = t;
591
596
  }
@@ -624,16 +629,18 @@ class A {
624
629
  break t;
625
630
  }
626
631
  } else {
627
- o -= S(d);
632
+ o -= B(d);
628
633
  break t;
629
634
  }
630
635
  ++h;
631
636
  }
632
637
  } else
633
- o -= S(s);
638
+ o -= B(s);
634
639
  const i = r >>> 8 & 8388607;
635
640
  i === 0 && r >>> 31 && ++o;
636
- const { buffer: c, byteOffset: a, length: l } = Uint32Array.from([o << 23 | i]);
641
+ const { buffer: c, byteOffset: a, length: l } = Uint32Array.from([
642
+ o << 23 | i
643
+ ]);
637
644
  return new Float32Array(c, a, l)[0];
638
645
  }
639
646
  /**
@@ -670,8 +677,8 @@ class A {
670
677
  const d = (() => {
671
678
  switch (this.#t.bits) {
672
679
  case 32: {
673
- const y = BigInt(this.#t.getU32Rand() >>> 0), L = BigInt(this.#t.getU32Rand() >>> 0);
674
- return y << 32n | L;
680
+ const y = BigInt(this.#t.getU32Rand() >>> 0), T = BigInt(this.#t.getU32Rand() >>> 0);
681
+ return y << 32n | T;
675
682
  }
676
683
  case 64:
677
684
  return BigInt.asUintN(64, this.#t.getU64Rand());
@@ -683,16 +690,18 @@ class A {
683
690
  break t;
684
691
  }
685
692
  } else {
686
- o -= B(d);
693
+ o -= x(d);
687
694
  break t;
688
695
  }
689
696
  ++h;
690
697
  }
691
698
  } else
692
- o -= B(s);
699
+ o -= x(s);
693
700
  const i = BigInt.asUintN(52, r >> 11n);
694
701
  i === 0n && r >> 63n && ++o;
695
- const { buffer: c, byteOffset: a, length: l } = BigUint64Array.from([o << 52n | i]);
702
+ const { buffer: c, byteOffset: a, length: l } = BigUint64Array.from([
703
+ o << 52n | i
704
+ ]);
696
705
  return new Float64Array(c, a, l)[0];
697
706
  }
698
707
  /**
@@ -708,14 +717,16 @@ class A {
708
717
  throw Error("exceeded loop limit");
709
718
  }
710
719
  }
720
+ Object.defineProperty(N.prototype, Symbol.toStringTag, {
721
+ value: N.name
722
+ });
711
723
  const z = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], J = 0x5851f42d4c957f2dn;
712
- class M {
724
+ class R {
713
725
  /**
714
726
  * length = 2, `[state, increment]`
715
727
  */
716
728
  #t;
717
729
  static name = "PCGMinimal";
718
- [Symbol.toStringTag] = M.name;
719
730
  bits = 32;
720
731
  /**
721
732
  * @param seeds
@@ -740,7 +751,7 @@ class M {
740
751
  /** 32bit 乱数を返す (内部状態は変わらない) */
741
752
  get #e() {
742
753
  const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
743
- return F(r, e);
754
+ return C(r, e);
744
755
  }
745
756
  /**
746
757
  *
@@ -779,17 +790,19 @@ class M {
779
790
  yield typeof e == "number" ? this.getBoundedU32Rand(e) : this.getU32Rand();
780
791
  }
781
792
  }
782
- const W = [
793
+ Object.defineProperty(R.prototype, Symbol.toStringTag, {
794
+ value: R.name
795
+ });
796
+ const G = [
783
797
  0xbe562cb412e2260en,
784
798
  0x2e4284137d641affn,
785
799
  0x4e19b36ee933e27en,
786
800
  0x7581cf8c4f4d4f7dn
787
801
  ];
788
- class T {
802
+ class A {
789
803
  bits = 64;
790
804
  #t;
791
805
  static name = "XoshiroMinimal";
792
- [Symbol.toStringTag] = T.name;
793
806
  /**
794
807
  * @param seeds
795
808
  * `BigUint64Array` with length 4. \
@@ -804,7 +817,7 @@ class T {
804
817
  * const betterRng = new PCGMinimal(seed);
805
818
  */
806
819
  constructor(t) {
807
- t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#n(), this.#t[2] += t[2], this.#t[3] += t[3]) : this.#t = BigUint64Array.from(W);
820
+ t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#n(), this.#t[2] += t[2], this.#t[3] += t[3]) : this.#t = BigUint64Array.from(G);
808
821
  }
809
822
  #n() {
810
823
  const t = this.#t[1] << 17n;
@@ -856,14 +869,17 @@ class T {
856
869
  yield e === void 0 ? this.getU32Rand() : this.getBoundedU32Rand(e);
857
870
  }
858
871
  }
872
+ Object.defineProperty(A.prototype, Symbol.toStringTag, {
873
+ value: A.name
874
+ });
859
875
  export {
860
- A as FloatRng,
861
- R as NamedError,
862
- M as PCGMinimal,
863
- N as Queue,
876
+ N as FloatRng,
877
+ E as NamedError,
878
+ R as PCGMinimal,
879
+ S as Queue,
864
880
  u as Rational,
865
- T as XoshiroMinimal,
866
- x as bailliePSW,
881
+ A as XoshiroMinimal,
882
+ M as bailliePSW,
867
883
  rt as compress,
868
884
  ht as decodeLEB128,
869
885
  et as decodeRFC3986URIComponent,
@@ -874,23 +890,23 @@ export {
874
890
  it as factorial,
875
891
  lt as fromString,
876
892
  Q as getHash,
877
- E as getRandBIByBitLength,
878
- _ as getRandBIByRange,
893
+ v as getRandBIByBitLength,
894
+ L as getRandBIByRange,
879
895
  at as getRandPrimeByBitLength,
880
896
  ct as getRandPrimeByRange,
881
897
  ot as getRndInt,
882
898
  g as isDeepStrictEqual,
883
899
  tt as isNode,
884
- P as isSquare,
900
+ O as isSquare,
885
901
  U as jacobiSymbol,
886
- X as lazify,
887
- p as modPow,
902
+ H as lazify,
903
+ m as modPow,
888
904
  Z as parseCSV,
889
- G as promiseWithResolvers,
890
- m as residue,
891
- F as rot32,
905
+ X as promiseWithResolvers,
906
+ p as residue,
907
+ C as rot32,
892
908
  I as rot64,
893
- Y as sameValueZero,
894
- H as sleep,
909
+ W as sameValueZero,
910
+ Y as sleep,
895
911
  ut as toString
896
912
  };
@@ -1,2 +1,2 @@
1
- (function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(c=typeof globalThis<"u"?globalThis:c||self,p(c.TktbTessUtilFns={}))})(this,(function(c){"use strict";const p=new TextEncoder,x=(n,t)=>[n].includes(t),m=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let s=0;s<n.length;s++)if(!m(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],i=[...t.values()];return!!m(s,i)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],i=[...t.keys()];if(!m(s,i))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const s=n,i=t,o=Object.keys(s),a=Object.keys(i);for(const l of o){const u=a.find(g=>g===l);if(u===void 0)return!1;const[h,d]=[s[l],i[u]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},V=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},O=n=>new Promise(t=>{setTimeout(()=>t(),n)}),$=n=>(...t)=>()=>n(...t),k=n=>{const t=[];let e=[],r="",s=!1;for(let i=0;i<n.length;i++){const o=n[i];o==='"'&&(i===0||n[i-1]!=="\\")?s=!s:o===","&&!s?(e.push(r.trim()),r=""):o===`
2
- `&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},D=async(n,t)=>{const e=p.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},q=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",K=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),z=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},W=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},J=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},G=(n,t)=>Math.floor(Math.random()*(t-n)+n),y=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},w=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let s=Array.from(r,i=>i.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},v=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,s=(()=>{for(let o=0;o<1e5;o++){const a=w(r);if(a>=b(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+s},b=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=y(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},C=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,s]=[1n,0n,n],[i,o,a]=[0n,-1n,t];for(;;){const l=s/a,u=s-l*a;if(u===0n)break;[e,i]=[i,e-l*i],[r,o]=[o,r-l*o],[s,a]=[a,u]}return a<0n&&(i*=-1n,o*=-1n,a*=-1n),{x:i,y:o,gcd:a}},I=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let a=n;for(let l=n+2n;l<t;l+=2n)a*=l;return a}const s=n+r|1n,i=I(n,s),o=I(s,t);return i*o},H=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let i=s-1n;i>-1n;--i){const o=(n>>i)+1n|1n;r*=I(t,o),t=o,e*=r}return e},X=n=>{if(n<0n)throw Error("'n' must be non-negative");if(n===0n)return 1n;const t=n-BigInt(n.toString(2).match(/1/g)?.length??0);return H(n)<<t},j=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,S=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),B=(n,t)=>{if(t<1n||t%2n===0n)throw Error("`n` is invalid");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},_=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},Y=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,s]=[t,e];let o=b(2n,r,n);if(o===1n)return!0;for(let a=0n;a<s;a++){if(o===n-1n)return!0;o=o*o%n}return!1},Z=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&_(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?y(n+t>>1n,t):y(n>>1n,t),Q=(n,t,e,r)=>{let s=1n,i=e;const o=n.toString(2).slice(1);for(const a of o)[s,i]=[y(s*i,t),U(i*i+r*s*s,t)],a==="1"&&([s,i]=[U(e*s+i,t),U(r*s+e*i,t)]);return[s,i]},tt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,i=0n;for(;s%2n===0n;)s>>=1n,i+=1n;const[o,a]=Q(s,n,e,t);let l=a;if(o===0n)return!0;r=b(r,s,n);for(let u=0n;u<i;u++){if(l===0n)return!0;l=y(l*l-2n*r,n),r=b(r,2n,n)}return!1},E=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const i of t)if(n%i===0n)return n===i;if(!Y(n))return!1;const[e,r]=Z(n);if(r===0n)return!1;const s=(1n-e)/4n;return tt(n,e,1n,s)},nt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=v(n,t);if(E(s))return s}throw Error("noPrimesFound")},et=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const s=w(n,t);if(E(s))return s}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";[Symbol.toStringTag]=f.name;constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const s=BigInt(Math.floor(t)),i=t-Number(s);if(i===0)return new f(r?-s:s,1n);t=1/i;let[o,a]=[1n,s],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,u]=[u,h*u+l],d===0)return new f(r?-a:a,u);t=1/d}return new f(r?-o:o,l)}#e(){const{gcd:t}=C(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new f(-this.#t,this.#n)}inverse(){return new f(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new f(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new f(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new f(r,e)}toDecimal(){return Number(this.#t)/Number(this.#n)}toString(){return this.#t===0n&&this.#n===0n?"NaN":this.#t===0n?"0":this.#n===0n?this.#t<0n?"-Infinity":"Infinity":this.#n===1n?`${this.#t}`:`${this.#t}/${this.#n}`}valueOf(){return this.toDecimal()}toJSON(){return{type:"Rational",value:["0x"+this.#t.toString(16),"0x"+this.#n.toString(16)]}}static fromData(t){const e=BigInt(t.value[0]),r=BigInt(t.value[1]);return new f(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const s=r.at(1),i=r.at(2);if(!s||!i)throw Error("cannot parse");return new f(BigInt(s),BigInt(i))}}const rt=new TextEncoder,st=new TextDecoder,it=(n,t)=>{switch(t){case"utf-8":return rt.encode(n);case"base64":return Uint8Array.from(atob(n),e=>e.charCodeAt(0));case"base64url":{const e=n.length&3;return e>0&&(n=n+"=".repeat(4-e)),n=n.replaceAll("-","+").replaceAll("_","/"),Uint8Array.from(atob(n),r=>r.charCodeAt(0))}case"hex":{n.length&1&&(n="0"+n);const r=n.matchAll(/.{2}/g);return Uint8Array.from(r,s=>Number.parseInt(s[0],16))}case"oct":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),i=Array.from(r,o=>{const a=o[0];return Number.parseInt(a,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(i,o=>Number.parseInt(o[0],16))}case"bin":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),s=Array.from(r,i=>Number.parseInt(i[0],2));return Uint8Array.from(s)}default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ot=(n,t)=>{switch(t){case"utf-8":return st.decode(n);case"base64":{const e=Array.from(n,r=>String.fromCharCode(r)).join("");return btoa(e)}case"base64url":{const e=Array.from(n,s=>String.fromCharCode(s)).join("");return btoa(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}case"hex":return Array.from(n,r=>r.toString(16).padStart(2,"0")).join("").replace(/^0+/,"");case"oct":{let e=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const r=e.length%6;r&&(e="0".repeat(6-r)+e);const s=e.matchAll(/.{6}/g);return Array.from(s,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")}case"bin":return Array.from(n,r=>r.toString(2).padStart(8,"0")).join("").replace(/^0+/,"");default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ct=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,s=Math.floor(e/7)+1;return r?s-1:s},at=n=>{const t=ct(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const i=Number(n&127n)|128;e[s]=i,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},lt=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const s=BigInt(n[r]&127);e+=s<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class R{#t;#n;static name="Queue";[Symbol.toStringTag]=R.name;constructor(...t){this.#t=t,this.#n=[]}enqueue(...t){return this.#t.push(...t),this.#t.length+this.#n.length}dequeue(){if(this.#n.length===0)for(;this.#t.length>0;){const t=this.#t.pop();this.#n.push(t)}return this.#n.pop()}toArray(){return this.#n.slice().reverse().concat(this.#t)}toJSON(){return this.toArray()}toString(){return this.toArray().toString()}}class N extends Error{name;static name="NamedError";[Symbol.toStringTag]=N.name;constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const i=this.cause;return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?i:typeof i=="bigint"?i.toString():typeof i=="object"&&i!==null?i instanceof Set||i instanceof Map?Object.fromEntries(i):i:void 0})(),{name:e,message:r,stack:s}=this;return{name:e,message:r,stack:s,cause:t}}}const P=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},F=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class A{#t;static name="FloatRand";[Symbol.toStringTag]=A.name;constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const h=this.#t.getU64Rand()&0xffffffffn;return Number(h)}}})(),s=r&255;let i=126;if(s===0){i-=8;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const L=BigInt.asUintN(32,this.#t.getU64Rand());return Number(L)}}})();if(g===0){if(i-=32,i<0){i=0;break t}}else{i-=P(g);break t}++d}}else i-=P(s);const o=r>>>8&8388607;o===0&&r>>>31&&++i;const{buffer:a,byteOffset:l,length:u}=Uint32Array.from([i<<23|o]);return new Float32Array(a,l,u)[0]}getF32Rand(){for(let e=0;e<1e5;++e){const r=this.#n();if(r<1)return r}throw Error("exceeded loop limit")}#e(){const t=0n,e=1023n,r=(()=>{switch(this.#t.bits){case 32:{const h=BigInt(this.#t.getU32Rand()>>>0),d=BigInt(this.#t.getU32Rand()>>>0);return h<<32n|d}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),s=r&0x7ffn;let i=e-1n;if(s===0n){i-=11n;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:{const L=BigInt(this.#t.getU32Rand()>>>0),dt=BigInt(this.#t.getU32Rand()>>>0);return L<<32n|dt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(i-=64n,i<t){i=t;break t}}else{i-=F(g);break t}++d}}else i-=F(s);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++i;const{buffer:a,byteOffset:l,length:u}=BigUint64Array.from([i<<52n|o]);return new Float64Array(a,l,u)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}const ut=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],ft=0x5851f42d4c957f2dn;class T{#t;static name="PCGMinimal";[Symbol.toStringTag]=T.name;bits=32;constructor(t){t&&t.length>=2?(this.#t=new BigUint64Array(2),this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]+=t[0],this.#n()):this.#t=BigUint64Array.from(ut)}#n(){this.#t[0]=this.#t[0]*ft+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return j(r,e)}getU32Rand(){return this.#n(),this.#e}getBoundedU32Rand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,s=1e5;for(let i=0;i<s;++i){const o=this.getU32Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedU32Rand(e):this.getU32Rand()}}const ht=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class M{bits=64;#t;static name="XoshiroMinimal";[Symbol.toStringTag]=M.name;constructor(t){t&&t.length>=4?(this.#t=new BigUint64Array(4),this.#t[0]=t[0],this.#t[1]=t[1],this.#n(),this.#t[2]+=t[2],this.#t[3]+=t[3]):this.#t=BigUint64Array.from(ht)}#n(){const t=this.#t[1]<<17n;this.#t[2]^=this.#t[0],this.#t[3]^=this.#t[1],this.#t[1]^=this.#t[2],this.#t[0]^=this.#t[3],this.#t[2]^=t,this.#t[3]=S(this.#t[3],45n)}get value(){return S(this.#t[0]+this.#t[3],23n)+this.#t[0]}getU64Rand(){const t=this.value;return this.#n(),t}getU32Rand(){const t=BigInt.asUintN(32,this.getU64Rand());return Number(t)}getBoundedU64Rand(t){const e=1n<<64n;if(t>e)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=e%t,s=1e5;for(let i=0;i<s;++i){const o=this.getU64Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}getBoundedU32Rand(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedU64Rand(BigInt(t));return Number(r)}*genU64Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU64Rand():this.getBoundedU64Rand(e)}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU32Rand():this.getBoundedU32Rand(e)}}c.FloatRng=A,c.NamedError=N,c.PCGMinimal=T,c.Queue=R,c.Rational=f,c.XoshiroMinimal=M,c.bailliePSW=E,c.compress=W,c.decodeLEB128=lt,c.decodeRFC3986URIComponent=z,c.decompress=J,c.encodeLEB128=at,c.encodeRFC3986URIComponent=K,c.exEuclidean=C,c.factorial=X,c.fromString=it,c.getHash=D,c.getRandBIByBitLength=w,c.getRandBIByRange=v,c.getRandPrimeByBitLength=et,c.getRandPrimeByRange=nt,c.getRndInt=G,c.isDeepStrictEqual=m,c.isNode=q,c.isSquare=_,c.jacobiSymbol=B,c.lazify=$,c.modPow=b,c.parseCSV=k,c.promiseWithResolvers=V,c.residue=y,c.rot32=j,c.rot64=S,c.sameValueZero=x,c.sleep=O,c.toString=ot,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(c,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(c=typeof globalThis<"u"?globalThis:c||self,y(c.UtilFns={}))})(this,(function(c){"use strict";const y=new TextEncoder,O=(n,t)=>[n].includes(t),m=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||n==null)return n===t;if(typeof n=="number")return n!==n&&t!==t||n===t;if(typeof n=="function")return!1;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let i=0;i<n.length;i++)if(!m(n[i],t[i]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const i=[...n.values()],s=[...t.values()];return!!m(i,s)}if(n instanceof Map&&t instanceof Map){const i=[...n.keys()],s=[...t.keys()];if(!m(i,s))return!1;const o=[...n.values()],a=[...t.values()];return!!m(o,a)}if(e==="[object Object]"){const i=n,s=t,o=Object.keys(i),a=Object.keys(s);for(const l of o){const u=a.find(g=>g===l);if(u===void 0)return!1;const[h,d]=[i[l],s[u]];if(!m(h,d))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},x=()=>{let n,t;return{promise:new Promise((r,i)=>{n=r,t=i}),resolve:n,reject:t}},V=n=>new Promise(t=>{setTimeout(()=>t(),n)}),$=n=>(...t)=>()=>n(...t),k=n=>{const t=[];let e=[],r="",i=!1;for(let s=0;s<n.length;s++){const o=n[s];o==='"'&&(s===0||n[s-1]!=="\\")?i=!i:o===","&&!i?(e.push(r.trim()),r=""):o===`
2
+ `&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},D=async(n,t)=>{const e=y.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},q=()=>!!globalThis.process&&typeof process.version<"u"&&typeof process.versions.node<"u",K=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),z=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},W=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},G=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},J=(n,t)=>Math.floor(Math.random()*(t-n)+n),p=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},w=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^\d/,"1")),BigInt("0b"+i)},T=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const a=w(r);if(a>=b(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+i},b=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=p(n,e),e===1n)return 0n;if(n%e===1n||n%e===0n)return n;if(n===e-1n)return t&1n?e-1n:1n;let r=1n;for(;t>0n;)t&1n&&(r=r*n%e),n=n*n%e,t>>=1n;return r},j=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,i]=[1n,0n,n],[s,o,a]=[0n,-1n,t];for(;;){const l=i/a,u=i-l*a;if(u===0n)break;[e,s]=[s,e-l*s],[r,o]=[o,r-l*o],[i,a]=[a,u]}return a<0n&&(s*=-1n,o*=-1n,a*=-1n),{x:s,y:o,gcd:a}},I=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let a=n;for(let l=n+2n;l<t;l+=2n)a*=l;return a}const i=n+r|1n,s=I(n,i),o=I(i,t);return s*o},X=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=I(t,o),t=o,e*=r}return e},H=n=>{if(n<0n)throw Error("'n' must be non-negative");if(n===0n)return 1n;const t=n-BigInt(n.toString(2).match(/1/g)?.length??0);return X(n)<<t},_=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,S=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),B=(n,t)=>{if(t<1n||t%2n===0n)throw Error("`n` is invalid");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},P=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},Y=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,i]=[t,e];let o=b(2n,r,n);if(o===1n)return!0;for(let a=0n;a<i;a++){if(o===n-1n)return!0;o=o*o%n}return!1},Z=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?p(n+t>>1n,t):p(n>>1n,t),Q=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const a of o)[i,s]=[p(i*s,t),U(s*s+r*i*i,t)],a==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},tt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,a]=Q(i,n,e,t);let l=a;if(o===0n)return!0;r=b(r,i,n);for(let u=0n;u<s;u++){if(l===0n)return!0;l=p(l*l-2n*r,n),r=b(r,2n,n)}return!1},E=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const s of t)if(n%s===0n)return n===s;if(!Y(n))return!1;const[e,r]=Z(n);if(r===0n)return!1;const i=(1n-e)/4n;return tt(n,e,1n,i)},nt=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=T(n,t);if(E(i))return i}throw Error("noPrimesFound")},et=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=w(n,t);if(E(i))return i}throw Error("noPrimesFound")};class f{#t;#n;static name="Rational";constructor(t,e){e===0n?(this.#n=0n,this.#t=t===0n?0n:t>0n?1n:-1n):e>0n?(this.#t=t,this.#n=e):(this.#t=-t,this.#n=-e),this.#e()}static fromDecimal(t,e=5){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new f(r?-i:i,1n);t=1/s;let[o,a]=[1n,i],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([o,a]=[a,h*a+o],[l,u]=[u,h*u+l],d===0)return new f(r?-a:a,u);t=1/d}return new f(r?-o:o,l)}#e(){const{gcd:t}=j(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new f(-this.#t,this.#n)}inverse(){return new f(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new f(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new f(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new f(r,e)}toDecimal(){return Number(this.#t)/Number(this.#n)}toString(){return this.#t===0n&&this.#n===0n?"NaN":this.#t===0n?"0":this.#n===0n?this.#t<0n?"-Infinity":"Infinity":this.#n===1n?`${this.#t}`:`${this.#t}/${this.#n}`}valueOf(){return this.toDecimal()}toJSON(){return{type:"Rational",value:["0x"+this.#t.toString(16),"0x"+this.#n.toString(16)]}}static fromData(t){const e=BigInt(t.value[0]),r=BigInt(t.value[1]);return new f(e,r)}static parse(t){const r=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);if(!r)throw Error("cannot parse");const i=r.at(1),s=r.at(2);if(!i||!s)throw Error("cannot parse");return new f(BigInt(i),BigInt(s))}}Object.defineProperty(f.prototype,Symbol.toStringTag,{value:f.name});const rt=new TextEncoder,it=new TextDecoder,st=(n,t)=>{switch(t){case"utf-8":return rt.encode(n);case"base64":return Uint8Array.from(atob(n),e=>e.charCodeAt(0));case"base64url":{const e=n.length&3;return e>0&&(n=n+"=".repeat(4-e)),n=n.replaceAll("-","+").replaceAll("_","/"),Uint8Array.from(atob(n),r=>r.charCodeAt(0))}case"hex":{n.length&1&&(n="0"+n);const r=n.matchAll(/.{2}/g);return Uint8Array.from(r,i=>Number.parseInt(i[0],16))}case"oct":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),s=Array.from(r,o=>{const a=o[0];return Number.parseInt(a,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,o=>Number.parseInt(o[0],16))}case"bin":{const e=n.length&7;e&&(n="0".repeat(8-e)+n);const r=n.matchAll(/.{8}/g),i=Array.from(r,s=>Number.parseInt(s[0],2));return Uint8Array.from(i)}default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ot=(n,t)=>{switch(t){case"utf-8":return it.decode(n);case"base64":{const e=Array.from(n,r=>String.fromCharCode(r)).join("");return btoa(e)}case"base64url":{const e=Array.from(n,i=>String.fromCharCode(i)).join("");return btoa(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}case"hex":return Array.from(n,r=>r.toString(16).padStart(2,"0")).join("").replace(/^0+/,"");case"oct":{let e=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const r=e.length%6;r&&(e="0".repeat(6-r)+e);const i=e.matchAll(/.{6}/g);return Array.from(i,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")}case"bin":return Array.from(n,r=>r.toString(2).padStart(8,"0")).join("").replace(/^0+/,"");default:throw Error(`Invalid encoding: ${t}`,{cause:t})}},ct=n=>{const t=n<0n;t&&(n*=-1n);const e=n.toString(2).length,r=n===1n<<BigInt(e-1)&&!(e%7)&&t,i=Math.floor(e/7)+1;return r?i-1:i},at=n=>{const t=ct(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let i=0;i<t-1;++i){const s=Number(n&127n)|128;e[i]=s,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},lt=n=>{const t=n.length;let e=0n;for(let r=0;r<t;++r){const i=BigInt(n[r]&127);e+=i<<BigInt(7*r)}return BigInt.asIntN(7*t,e)};class R{#t;#n;static name="Queue";constructor(...t){this.#t=t,this.#n=[]}enqueue(...t){return this.#t.push(...t),this.#t.length+this.#n.length}dequeue(){if(this.#n.length===0)for(;this.#t.length>0;){const t=this.#t.pop();this.#n.push(t)}return this.#n.pop()}toArray(){return this.#n.slice().reverse().concat(this.#t)}toJSON(){return this.toArray()}toString(){return this.toArray().toString()}}Object.defineProperty(R.prototype,Symbol.toStringTag,{value:R.name});class N extends Error{name;static name="NamedError";constructor(t,e,r){super(e,{cause:r}),this.name=t}toJSON(){const t=(()=>{const s=this.cause;return typeof s=="string"||typeof s=="number"||typeof s=="boolean"?s:typeof s=="bigint"?s.toString():typeof s=="object"&&s!==null?s instanceof Set||s instanceof Map?Object.fromEntries(s):s:void 0})(),{name:e,message:r,stack:i}=this;return{name:e,message:r,stack:i,cause:t}}}Object.defineProperty(N.prototype,Symbol.toStringTag,{value:N.name});const C=n=>{if(n===0)return 32;let t=0;for(;n>0&&!(n&1);)++t,n>>>=1;return t},F=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)};class A{#t;static name="FloatRng";constructor(t){this.#t=t}#n(){const r=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const h=this.#t.getU64Rand()&0xffffffffn;return Number(h)}}})(),i=r&255;let s=126;if(i===0){s-=8;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:return this.#t.getU32Rand()>>>0;case 64:{const L=BigInt.asUintN(32,this.#t.getU64Rand());return Number(L)}}})();if(g===0){if(s-=32,s<0){s=0;break t}}else{s-=C(g);break t}++d}}else s-=C(i);const o=r>>>8&8388607;o===0&&r>>>31&&++s;const{buffer:a,byteOffset:l,length:u}=Uint32Array.from([s<<23|o]);return new Float32Array(a,l,u)[0]}getF32Rand(){for(let e=0;e<1e5;++e){const r=this.#n();if(r<1)return r}throw Error("exceeded loop limit")}#e(){const t=0n,e=1023n,r=(()=>{switch(this.#t.bits){case 32:{const h=BigInt(this.#t.getU32Rand()>>>0),d=BigInt(this.#t.getU32Rand()>>>0);return h<<32n|d}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})(),i=r&0x7ffn;let s=e-1n;if(i===0n){s-=11n;const h=1e5;let d=0;t:for(;;){if(d>h)throw Error("loop exceeded limit");const g=(()=>{switch(this.#t.bits){case 32:{const L=BigInt(this.#t.getU32Rand()>>>0),dt=BigInt(this.#t.getU32Rand()>>>0);return L<<32n|dt}case 64:return BigInt.asUintN(64,this.#t.getU64Rand())}})();if(g===0n){if(s-=64n,s<t){s=t;break t}}else{s-=F(g);break t}++d}}else s-=F(i);const o=BigInt.asUintN(52,r>>11n);o===0n&&r>>63n&&++s;const{buffer:a,byteOffset:l,length:u}=BigUint64Array.from([s<<52n|o]);return new Float64Array(a,l,u)[0]}getF64Rand(){for(let e=0;e<1e5;++e){const r=this.#e();if(r<1)return r}throw Error("exceeded loop limit")}}Object.defineProperty(A.prototype,Symbol.toStringTag,{value:A.name});const ut=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],ft=0x5851f42d4c957f2dn;class v{#t;static name="PCGMinimal";bits=32;constructor(t){t&&t.length>=2?(this.#t=new BigUint64Array(2),this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]+=t[0],this.#n()):this.#t=BigUint64Array.from(ut)}#n(){this.#t[0]=this.#t[0]*ft+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return _(r,e)}getU32Rand(){return this.#n(),this.#e}getBoundedU32Rand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");if(t<=0)throw Error("'bound' must be positive");const r=4294967296%t,i=1e5;for(let s=0;s<i;++s){const o=this.getU32Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedU32Rand(e):this.getU32Rand()}}Object.defineProperty(v.prototype,Symbol.toStringTag,{value:v.name});const ht=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class M{bits=64;#t;static name="XoshiroMinimal";constructor(t){t&&t.length>=4?(this.#t=new BigUint64Array(4),this.#t[0]=t[0],this.#t[1]=t[1],this.#n(),this.#t[2]+=t[2],this.#t[3]+=t[3]):this.#t=BigUint64Array.from(ht)}#n(){const t=this.#t[1]<<17n;this.#t[2]^=this.#t[0],this.#t[3]^=this.#t[1],this.#t[1]^=this.#t[2],this.#t[0]^=this.#t[3],this.#t[2]^=t,this.#t[3]=S(this.#t[3],45n)}get value(){return S(this.#t[0]+this.#t[3],23n)+this.#t[0]}getU64Rand(){const t=this.value;return this.#n(),t}getU32Rand(){const t=BigInt.asUintN(32,this.getU64Rand());return Number(t)}getBoundedU64Rand(t){const e=1n<<64n;if(t>e)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=e%t,i=1e5;for(let s=0;s<i;++s){const o=this.getU64Rand();if(o>=r)return o%t}throw Error("exceeded loop limit")}getBoundedU32Rand(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedU64Rand(BigInt(t));return Number(r)}*genU64Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU64Rand():this.getBoundedU64Rand(e)}*genU32Rands(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getU32Rand():this.getBoundedU32Rand(e)}}Object.defineProperty(M.prototype,Symbol.toStringTag,{value:M.name}),c.FloatRng=A,c.NamedError=N,c.PCGMinimal=v,c.Queue=R,c.Rational=f,c.XoshiroMinimal=M,c.bailliePSW=E,c.compress=W,c.decodeLEB128=lt,c.decodeRFC3986URIComponent=z,c.decompress=G,c.encodeLEB128=at,c.encodeRFC3986URIComponent=K,c.exEuclidean=j,c.factorial=H,c.fromString=st,c.getHash=D,c.getRandBIByBitLength=w,c.getRandBIByRange=T,c.getRandPrimeByBitLength=et,c.getRandPrimeByRange=nt,c.getRndInt=J,c.isDeepStrictEqual=m,c.isNode=q,c.isSquare=P,c.jacobiSymbol=B,c.lazify=$,c.modPow=b,c.parseCSV=k,c.promiseWithResolvers=x,c.residue=p,c.rot32=_,c.rot64=S,c.sameValueZero=O,c.sleep=V,c.toString=ot,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
@@ -6,7 +6,6 @@ export type RationalData = {
6
6
  export declare class Rational {
7
7
  #private;
8
8
  static readonly name = "Rational";
9
- readonly [Symbol.toStringTag] = "Rational";
10
9
  /**
11
10
  * fraction (rational) class
12
11
  * @param numerator
@@ -6,7 +6,6 @@ interface NamedError<EName extends string> {
6
6
  declare class NamedError<EName extends string> extends Error {
7
7
  readonly name: EName;
8
8
  static readonly name = "NamedError";
9
- readonly [Symbol.toStringTag] = "NamedError";
10
9
  constructor(name: EName, message: string, cause?: unknown);
11
10
  toJSON(): {
12
11
  name: EName;
@@ -7,7 +7,6 @@ import { RandomGenerator32 } from './random';
7
7
  export declare class PCGMinimal implements RandomGenerator32 {
8
8
  #private;
9
9
  static readonly name = "PCGMinimal";
10
- readonly [Symbol.toStringTag] = "PCGMinimal";
11
10
  readonly bits = 32;
12
11
  /**
13
12
  * @param seeds
package/dist/queue.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export declare class Queue<T> {
2
2
  #private;
3
3
  static readonly name = "Queue";
4
- readonly [Symbol.toStringTag] = "Queue";
5
4
  /**
6
5
  * Queue
7
6
  * @param data
package/dist/random.d.ts CHANGED
@@ -8,8 +8,7 @@ export interface RandomGenerator64 {
8
8
  }
9
9
  export declare class FloatRng<TRng extends RandomGenerator32 | RandomGenerator64> {
10
10
  #private;
11
- static readonly name = "FloatRand";
12
- readonly [Symbol.toStringTag] = "FloatRand";
11
+ static readonly name = "FloatRng";
13
12
  constructor(rng: TRng);
14
13
  /**
15
14
  * returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
@@ -8,7 +8,6 @@ export declare class XoshiroMinimal implements RandomGenerator64 {
8
8
  #private;
9
9
  readonly bits = 64;
10
10
  static readonly name = "XoshiroMinimal";
11
- readonly [Symbol.toStringTag] = "XoshiroMinimal";
12
11
  /**
13
12
  * @param seeds
14
13
  * `BigUint64Array` with length 4. \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
@@ -14,8 +14,7 @@
14
14
  "types": "./dist/main.d.ts",
15
15
  "exports": {
16
16
  "types": "./dist/main.d.ts",
17
- "import": "./dist/bundle.js",
18
- "require": null
17
+ "import": "./dist/bundle.js"
19
18
  },
20
19
  "engines": {
21
20
  "node": "^22",
@@ -35,7 +34,7 @@
35
34
  "vitest": "^3.2.4"
36
35
  },
37
36
  "volta": {
38
- "node": "22.19.0"
37
+ "node": "22.21.0"
39
38
  },
40
39
  "scripts": {
41
40
  "dev": "vite",