@tktb-tess/util-fns 0.8.4 → 0.8.5
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/bundle.js +122 -144
- package/dist/u8arr-ext.d.ts +0 -2
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -10,26 +10,26 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
10
10
|
return !1;
|
|
11
11
|
if (Array.isArray(n) && Array.isArray(t)) {
|
|
12
12
|
if (n.length !== t.length) return !1;
|
|
13
|
-
for (let
|
|
14
|
-
if (!d(n[
|
|
13
|
+
for (let s = 0; s < n.length; s++)
|
|
14
|
+
if (!d(n[s], t[s])) return !1;
|
|
15
15
|
return !0;
|
|
16
16
|
}
|
|
17
17
|
if (n instanceof Set && t instanceof Set) {
|
|
18
|
-
const
|
|
19
|
-
return !!d(
|
|
18
|
+
const s = [...n.values()], o = [...t.values()];
|
|
19
|
+
return !!d(s, o);
|
|
20
20
|
}
|
|
21
21
|
if (n instanceof Map && t instanceof Map) {
|
|
22
|
-
const
|
|
23
|
-
if (!d(
|
|
22
|
+
const s = [...n.keys()], o = [...t.keys()];
|
|
23
|
+
if (!d(s, o)) return !1;
|
|
24
24
|
const i = [...n.values()], c = [...t.values()];
|
|
25
25
|
return !!d(i, c);
|
|
26
26
|
}
|
|
27
27
|
if (e === "[object Object]") {
|
|
28
|
-
const
|
|
28
|
+
const s = n, o = t, i = Object.keys(s), c = Object.keys(o);
|
|
29
29
|
for (const a of i) {
|
|
30
30
|
const f = c.find((g) => g === a);
|
|
31
31
|
if (f === void 0) return !1;
|
|
32
|
-
const [h, u] = [
|
|
32
|
+
const [h, u] = [s[a], o[f]];
|
|
33
33
|
if (!d(h, u)) return !1;
|
|
34
34
|
}
|
|
35
35
|
return !0;
|
|
@@ -40,8 +40,8 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
40
40
|
}, z = () => {
|
|
41
41
|
let n, t;
|
|
42
42
|
return {
|
|
43
|
-
promise: new Promise((r,
|
|
44
|
-
n = r, t =
|
|
43
|
+
promise: new Promise((r, s) => {
|
|
44
|
+
n = r, t = s;
|
|
45
45
|
}),
|
|
46
46
|
resolve: n,
|
|
47
47
|
reject: t
|
|
@@ -50,11 +50,11 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
50
50
|
setTimeout(() => t(), n);
|
|
51
51
|
}), W = (n) => (...t) => () => n(...t), G = (n) => {
|
|
52
52
|
const t = [];
|
|
53
|
-
let e = [], r = "",
|
|
54
|
-
for (let
|
|
55
|
-
const i = n[
|
|
56
|
-
i === '"' && (
|
|
57
|
-
` && !
|
|
53
|
+
let e = [], r = "", s = !1;
|
|
54
|
+
for (let o = 0; o < n.length; o++) {
|
|
55
|
+
const i = n[o];
|
|
56
|
+
i === '"' && (o === 0 || n[o - 1] !== "\\") ? s = !s : i === "," && !s ? (e.push(r.trim()), r = "") : i === `
|
|
57
|
+
` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
|
|
58
58
|
}
|
|
59
59
|
return e.push(r.trim()), t.push(e), t;
|
|
60
60
|
}, H = async (n, t) => {
|
|
@@ -77,23 +77,23 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
77
77
|
t < 0n && (t *= -1n);
|
|
78
78
|
const e = n % t;
|
|
79
79
|
return e < 0n ? e + t : e;
|
|
80
|
-
},
|
|
80
|
+
}, E = (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
|
-
let
|
|
85
|
-
return t && (
|
|
84
|
+
let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
|
|
85
|
+
return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
|
|
86
86
|
}, j = (n, t) => {
|
|
87
87
|
if (n >= t) throw Error("rangeError");
|
|
88
|
-
const e = t - n, r = e.toString(2).length,
|
|
88
|
+
const e = t - n, r = e.toString(2).length, s = (() => {
|
|
89
89
|
for (let i = 0; i < 1e5; i++) {
|
|
90
|
-
const c =
|
|
90
|
+
const c = E(r);
|
|
91
91
|
if (c >= p(2n, BigInt(r), e))
|
|
92
92
|
return c % e;
|
|
93
93
|
}
|
|
94
94
|
throw Error("Failed to generate a random bigint");
|
|
95
95
|
})();
|
|
96
|
-
return n +
|
|
96
|
+
return n + s;
|
|
97
97
|
}, p = (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");
|
|
@@ -104,19 +104,19 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
104
104
|
for (; t > 0n; )
|
|
105
105
|
t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
|
|
106
106
|
return r;
|
|
107
|
-
},
|
|
107
|
+
}, _ = (n, t) => {
|
|
108
108
|
if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
|
|
109
109
|
if (n === 0n)
|
|
110
110
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
111
111
|
if (t === 0n)
|
|
112
112
|
return n > 0n ? { x: 1n, y: 0n, gcd: n } : { x: -1n, y: 0n, gcd: -n };
|
|
113
|
-
let [e, r,
|
|
113
|
+
let [e, r, s] = [1n, 0n, n], [o, i, c] = [0n, -1n, t];
|
|
114
114
|
for (; ; ) {
|
|
115
|
-
const a =
|
|
115
|
+
const a = s / c, f = s - a * c;
|
|
116
116
|
if (f === 0n) break;
|
|
117
|
-
[e,
|
|
117
|
+
[e, o] = [o, e - a * o], [r, i] = [i, r - a * i], [s, c] = [c, f];
|
|
118
118
|
}
|
|
119
|
-
return c < 0n && (
|
|
119
|
+
return c < 0n && (o *= -1n, i *= -1n, c *= -1n), { x: o, y: i, gcd: c };
|
|
120
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;
|
|
@@ -126,13 +126,13 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
126
126
|
c *= a;
|
|
127
127
|
return c;
|
|
128
128
|
}
|
|
129
|
-
const
|
|
130
|
-
return
|
|
131
|
-
},
|
|
129
|
+
const s = n + r | 1n, o = w(n, s), i = w(s, t);
|
|
130
|
+
return o * i;
|
|
131
|
+
}, v = (n) => {
|
|
132
132
|
let t = 3n, e = 1n, r = 1n;
|
|
133
|
-
const
|
|
134
|
-
for (let
|
|
135
|
-
const i = (n >>
|
|
133
|
+
const s = BigInt(n.toString(2).length) - 1n;
|
|
134
|
+
for (let o = s - 1n; o > -1n; --o) {
|
|
135
|
+
const i = (n >> o) + 1n | 1n;
|
|
136
136
|
r *= w(t, i), t = i, e *= r;
|
|
137
137
|
}
|
|
138
138
|
return e;
|
|
@@ -140,8 +140,8 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
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
|
|
144
|
-
}, rt = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)),
|
|
143
|
+
return v(n) << t;
|
|
144
|
+
}, rt = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)), C = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, b = (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 T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (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
|
-
},
|
|
160
|
+
}, F = (n) => {
|
|
161
161
|
if (n < 0n) return !1;
|
|
162
162
|
if (n === 0n) return !0;
|
|
163
163
|
let t = 1n, e = n;
|
|
@@ -166,16 +166,16 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
166
166
|
r ** 2n < n ? t = r : e = r;
|
|
167
167
|
}
|
|
168
168
|
return n === t ** 2n || n === (t + 1n) ** 2n;
|
|
169
|
-
},
|
|
169
|
+
}, L = (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
|
-
const [r,
|
|
175
|
+
const [r, s] = [t, e];
|
|
176
176
|
let i = p(2n, r, n);
|
|
177
177
|
if (i === 1n) return !0;
|
|
178
|
-
for (let c = 0n; c <
|
|
178
|
+
for (let c = 0n; c < s; c++) {
|
|
179
179
|
if (i === n - 1n) return !0;
|
|
180
180
|
i = i * i % n;
|
|
181
181
|
}
|
|
@@ -183,32 +183,32 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
183
183
|
}, P = (n) => {
|
|
184
184
|
let t = 5n, e = b(t, n);
|
|
185
185
|
for (; e > 0n; ) {
|
|
186
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
186
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && F(n))
|
|
187
187
|
return [0n, 0n];
|
|
188
188
|
e = b(t, n);
|
|
189
189
|
}
|
|
190
190
|
return [t, e];
|
|
191
191
|
}, y = (n, t) => (n & 1n) === 1n ? m(n + t >> 1n, t) : m(n >> 1n, t), V = (n, t, e, r) => {
|
|
192
|
-
let
|
|
192
|
+
let s = 1n, o = e;
|
|
193
193
|
const i = n.toString(2).slice(1);
|
|
194
194
|
for (const c of i)
|
|
195
|
-
[
|
|
196
|
-
return [
|
|
195
|
+
[s, o] = [m(s * o, t), y(o * o + r * s * s, t)], c === "1" && ([s, o] = [y(e * s + o, t), y(r * s + e * o, t)]);
|
|
196
|
+
return [s, o];
|
|
197
197
|
}, O = (n, t, e, r) => {
|
|
198
198
|
if (n % 2n !== 1n) throw Error("`n` must be odd");
|
|
199
|
-
let
|
|
200
|
-
for (;
|
|
201
|
-
|
|
202
|
-
const [i, c] = V(
|
|
199
|
+
let s = n + 1n, o = 0n;
|
|
200
|
+
for (; s % 2n === 0n; )
|
|
201
|
+
s >>= 1n, o += 1n;
|
|
202
|
+
const [i, c] = V(s, n, e, t);
|
|
203
203
|
let a = c;
|
|
204
204
|
if (i === 0n) return !0;
|
|
205
|
-
r = p(r,
|
|
206
|
-
for (let f = 0n; f <
|
|
205
|
+
r = p(r, s, n);
|
|
206
|
+
for (let f = 0n; f < o; f++) {
|
|
207
207
|
if (a === 0n) return !0;
|
|
208
208
|
a = m(a * a - 2n * r, n), r = p(r, 2n, n);
|
|
209
209
|
}
|
|
210
210
|
return !1;
|
|
211
|
-
},
|
|
211
|
+
}, x = (n) => {
|
|
212
212
|
if (n <= 1n) return !1;
|
|
213
213
|
if (n % 2n === 0n) return n === 2n;
|
|
214
214
|
const t = [
|
|
@@ -239,29 +239,29 @@ const T = new TextEncoder(), K = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
239
239
|
97n,
|
|
240
240
|
101n
|
|
241
241
|
];
|
|
242
|
-
for (const
|
|
243
|
-
if (n %
|
|
244
|
-
return n ===
|
|
245
|
-
if (!
|
|
242
|
+
for (const o of t)
|
|
243
|
+
if (n % o === 0n)
|
|
244
|
+
return n === o;
|
|
245
|
+
if (!L(n))
|
|
246
246
|
return !1;
|
|
247
247
|
const [e, r] = P(n);
|
|
248
248
|
if (r === 0n) return !1;
|
|
249
|
-
const
|
|
250
|
-
return O(n, e, 1n,
|
|
249
|
+
const s = (1n - e) / 4n;
|
|
250
|
+
return O(n, e, 1n, s);
|
|
251
251
|
}, st = (n, t) => {
|
|
252
252
|
if (t < 2n)
|
|
253
253
|
throw Error("noPrimesFound");
|
|
254
254
|
for (let r = 0; r < 1e5; r++) {
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
255
|
+
const s = j(n, t);
|
|
256
|
+
if (x(s)) return s;
|
|
257
257
|
}
|
|
258
258
|
throw Error("noPrimesFound");
|
|
259
259
|
}, ot = (n, t = !1) => {
|
|
260
260
|
if (n < 2)
|
|
261
261
|
throw Error("noPrimesFound");
|
|
262
262
|
for (let r = 0; r < 1e5; r++) {
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
263
|
+
const s = E(n, t);
|
|
264
|
+
if (x(s)) return s;
|
|
265
265
|
}
|
|
266
266
|
throw Error("noPrimesFound");
|
|
267
267
|
};
|
|
@@ -290,11 +290,11 @@ class l {
|
|
|
290
290
|
return new l(t > 0 ? 1n : -1n, 0n);
|
|
291
291
|
const r = t < 0;
|
|
292
292
|
r && (t *= -1);
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
return new l(r ? -
|
|
296
|
-
t = 1 /
|
|
297
|
-
let [i, c] = [1n,
|
|
293
|
+
const s = BigInt(Math.floor(t)), o = t - Number(s);
|
|
294
|
+
if (o === 0)
|
|
295
|
+
return new l(r ? -s : s, 1n);
|
|
296
|
+
t = 1 / o;
|
|
297
|
+
let [i, c] = [1n, s], [a, f] = [0n, 1n];
|
|
298
298
|
for (; `${f}`.length < e + 1; ) {
|
|
299
299
|
const h = BigInt(Math.floor(t)), u = t - Number(h);
|
|
300
300
|
if ([i, c] = [c, h * c + i], [a, f] = [f, h * f + a], u === 0)
|
|
@@ -307,7 +307,7 @@ class l {
|
|
|
307
307
|
* reduction
|
|
308
308
|
*/
|
|
309
309
|
#e() {
|
|
310
|
-
const { gcd: t } =
|
|
310
|
+
const { gcd: t } = _(this.#t, this.#n);
|
|
311
311
|
t !== 0n && (this.#t /= t, this.#n /= t);
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
@@ -409,10 +409,10 @@ class l {
|
|
|
409
409
|
const r = /^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t);
|
|
410
410
|
if (!r)
|
|
411
411
|
throw Error("cannot parse");
|
|
412
|
-
const
|
|
413
|
-
if (!
|
|
412
|
+
const s = r.at(1), o = r.at(2);
|
|
413
|
+
if (!s || !o)
|
|
414
414
|
throw Error("cannot parse");
|
|
415
|
-
return new l(BigInt(
|
|
415
|
+
return new l(BigInt(s), BigInt(o));
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
418
|
const $ = new TextEncoder(), k = new TextDecoder(), it = (n, t) => {
|
|
@@ -428,25 +428,25 @@ const $ = new TextEncoder(), k = new TextDecoder(), it = (n, t) => {
|
|
|
428
428
|
case "hex": {
|
|
429
429
|
n.length & 1 && (n = "0" + n);
|
|
430
430
|
const r = n.matchAll(/.{2}/g);
|
|
431
|
-
return Uint8Array.from(r, (
|
|
431
|
+
return Uint8Array.from(r, (s) => Number.parseInt(s[0], 16));
|
|
432
432
|
}
|
|
433
433
|
case "oct": {
|
|
434
434
|
const e = n.length & 7;
|
|
435
435
|
e && (n = "0".repeat(8 - e) + n);
|
|
436
|
-
const r = n.matchAll(/.{8}/g),
|
|
436
|
+
const r = n.matchAll(/.{8}/g), o = Array.from(r, (i) => {
|
|
437
437
|
const c = i[0];
|
|
438
438
|
return Number.parseInt(c, 8).toString(16).padStart(6, "0");
|
|
439
439
|
}).join("").matchAll(/.{2}/g);
|
|
440
440
|
return Uint8Array.from(
|
|
441
|
-
|
|
441
|
+
o,
|
|
442
442
|
(i) => Number.parseInt(i[0], 16)
|
|
443
443
|
);
|
|
444
444
|
}
|
|
445
445
|
case "bin": {
|
|
446
446
|
const e = n.length & 7;
|
|
447
447
|
e && (n = "0".repeat(8 - e) + n);
|
|
448
|
-
const r = n.matchAll(/.{8}/g),
|
|
449
|
-
return Uint8Array.from(
|
|
448
|
+
const r = n.matchAll(/.{8}/g), s = Array.from(r, (o) => Number.parseInt(o[0], 2));
|
|
449
|
+
return Uint8Array.from(s);
|
|
450
450
|
}
|
|
451
451
|
default:
|
|
452
452
|
throw Error(`Invalid encoding: ${t}`, { cause: t });
|
|
@@ -460,7 +460,7 @@ const $ = new TextEncoder(), k = new TextDecoder(), it = (n, t) => {
|
|
|
460
460
|
return btoa(e);
|
|
461
461
|
}
|
|
462
462
|
case "base64url": {
|
|
463
|
-
const e = Array.from(n, (
|
|
463
|
+
const e = Array.from(n, (s) => String.fromCharCode(s)).join("");
|
|
464
464
|
return btoa(e).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
465
465
|
}
|
|
466
466
|
case "hex":
|
|
@@ -472,9 +472,9 @@ const $ = new TextEncoder(), k = new TextDecoder(), it = (n, t) => {
|
|
|
472
472
|
).join("");
|
|
473
473
|
const r = e.length % 6;
|
|
474
474
|
r && (e = "0".repeat(6 - r) + e);
|
|
475
|
-
const
|
|
475
|
+
const s = e.matchAll(/.{6}/g);
|
|
476
476
|
return Array.from(
|
|
477
|
-
|
|
477
|
+
s,
|
|
478
478
|
(i) => Number.parseInt(i[0], 16).toString(8).padStart(8, "0")
|
|
479
479
|
).join("").replace(/^0+/, "");
|
|
480
480
|
}
|
|
@@ -483,32 +483,12 @@ const $ = new TextEncoder(), k = new TextDecoder(), it = (n, t) => {
|
|
|
483
483
|
default:
|
|
484
484
|
throw Error(`Invalid encoding: ${t}`, { cause: t });
|
|
485
485
|
}
|
|
486
|
-
}, at = (n) => {
|
|
487
|
-
const t = n < 0n;
|
|
488
|
-
t && (n *= -1n);
|
|
489
|
-
const e = n.toString(2).length, r = Math.ceil(e / 7);
|
|
490
|
-
t && (n = BigInt.asUintN(7 * r, ~n + 1n));
|
|
491
|
-
const o = new Uint8Array(r);
|
|
492
|
-
for (let s = 0; s < r - 1; ++s) {
|
|
493
|
-
const i = Number(n & 127n) | 128;
|
|
494
|
-
o[s] = i, n >>= 7n;
|
|
495
|
-
}
|
|
496
|
-
return o[r - 1] = Number(n), o;
|
|
497
|
-
}, ft = (n) => {
|
|
498
|
-
const t = n.length;
|
|
499
|
-
let e = 0n;
|
|
500
|
-
for (let s = 0; s < t; ++s) {
|
|
501
|
-
const i = n[s] & 127;
|
|
502
|
-
e += BigInt(i) << BigInt(7 * s);
|
|
503
|
-
}
|
|
504
|
-
const r = 1n << BigInt(7 * t - 1);
|
|
505
|
-
return (e & r) === 1n && (e = BigInt.asIntN(7 * t, e)), e;
|
|
506
486
|
};
|
|
507
|
-
class
|
|
487
|
+
class A {
|
|
508
488
|
#t;
|
|
509
489
|
#n;
|
|
510
490
|
static name = "Queue";
|
|
511
|
-
[Symbol.toStringTag] =
|
|
491
|
+
[Symbol.toStringTag] = A.name;
|
|
512
492
|
/**
|
|
513
493
|
* Queue
|
|
514
494
|
* @param data
|
|
@@ -546,22 +526,22 @@ class N {
|
|
|
546
526
|
return this.toArray().toString();
|
|
547
527
|
}
|
|
548
528
|
}
|
|
549
|
-
class
|
|
529
|
+
class B extends Error {
|
|
550
530
|
name;
|
|
551
531
|
static name = "NamedError";
|
|
552
|
-
[Symbol.toStringTag] =
|
|
532
|
+
[Symbol.toStringTag] = B.name;
|
|
553
533
|
constructor(t, e, r) {
|
|
554
534
|
super(e, { cause: r }), this.name = t;
|
|
555
535
|
}
|
|
556
536
|
toJSON() {
|
|
557
537
|
const t = (() => {
|
|
558
|
-
const
|
|
559
|
-
return typeof
|
|
560
|
-
})(), { name: e, message: r, stack:
|
|
538
|
+
const o = this.cause;
|
|
539
|
+
return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" && o !== null ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
|
|
540
|
+
})(), { name: e, message: r, stack: s } = this;
|
|
561
541
|
return {
|
|
562
542
|
name: e,
|
|
563
543
|
message: r,
|
|
564
|
-
stack:
|
|
544
|
+
stack: s,
|
|
565
545
|
cause: t
|
|
566
546
|
};
|
|
567
547
|
}
|
|
@@ -579,19 +559,19 @@ const I = (n) => {
|
|
|
579
559
|
++t, n >>= 1n;
|
|
580
560
|
return BigInt.asUintN(64, t);
|
|
581
561
|
};
|
|
582
|
-
class
|
|
562
|
+
class U {
|
|
583
563
|
#t;
|
|
584
564
|
#n;
|
|
585
565
|
static name = "FloatRand";
|
|
586
|
-
[Symbol.toStringTag] =
|
|
566
|
+
[Symbol.toStringTag] = U.name;
|
|
587
567
|
constructor(t, e) {
|
|
588
568
|
this.#t = t, this.#n = e;
|
|
589
569
|
}
|
|
590
570
|
#e() {
|
|
591
|
-
const r = this.#t.getU32Rand() | 0,
|
|
592
|
-
let
|
|
593
|
-
if (
|
|
594
|
-
|
|
571
|
+
const r = this.#t.getU32Rand() | 0, s = r & 255;
|
|
572
|
+
let o = 126;
|
|
573
|
+
if (s === 0) {
|
|
574
|
+
o -= 8;
|
|
595
575
|
const h = 1e5;
|
|
596
576
|
let u = 0;
|
|
597
577
|
t: for (; ; ) {
|
|
@@ -599,22 +579,22 @@ class x {
|
|
|
599
579
|
throw Error("loop exceeded limit");
|
|
600
580
|
const g = this.#t.getU32Rand() | 0;
|
|
601
581
|
if (g === 0) {
|
|
602
|
-
if (
|
|
603
|
-
|
|
582
|
+
if (o -= 32, o < 0) {
|
|
583
|
+
o = 0;
|
|
604
584
|
break t;
|
|
605
585
|
}
|
|
606
586
|
} else {
|
|
607
|
-
|
|
587
|
+
o -= I(g);
|
|
608
588
|
break t;
|
|
609
589
|
}
|
|
610
590
|
++u;
|
|
611
591
|
}
|
|
612
592
|
} else
|
|
613
|
-
|
|
593
|
+
o -= I(s);
|
|
614
594
|
const i = r >>> 8 & 8388607;
|
|
615
|
-
i === 0 && r >>> 31 && ++
|
|
595
|
+
i === 0 && r >>> 31 && ++o;
|
|
616
596
|
const { buffer: c, byteOffset: a, length: f } = Uint32Array.from([
|
|
617
|
-
|
|
597
|
+
o << 23 | i
|
|
618
598
|
]);
|
|
619
599
|
return new Float32Array(c, a, f)[0];
|
|
620
600
|
}
|
|
@@ -634,36 +614,36 @@ class x {
|
|
|
634
614
|
const t = 0n, e = 1023n, r = (() => {
|
|
635
615
|
const h = BigInt(this.#t.getU32Rand() | 0), u = BigInt(this.#n.getU32Rand() | 0);
|
|
636
616
|
return h << 32n | u;
|
|
637
|
-
})(),
|
|
638
|
-
let
|
|
639
|
-
if (
|
|
640
|
-
|
|
617
|
+
})(), s = r & 0x7ffn;
|
|
618
|
+
let o = e - 1n;
|
|
619
|
+
if (s === 0n) {
|
|
620
|
+
o -= 11n;
|
|
641
621
|
const h = 1e5;
|
|
642
622
|
let u = 0;
|
|
643
623
|
t: for (; ; ) {
|
|
644
624
|
if (u > h)
|
|
645
625
|
throw Error("loop exceeded limit");
|
|
646
626
|
const g = (() => {
|
|
647
|
-
const
|
|
648
|
-
return
|
|
627
|
+
const R = BigInt(this.#t.getU32Rand() | 0), M = BigInt(this.#n.getU32Rand() | 0);
|
|
628
|
+
return R << 32n | M;
|
|
649
629
|
})();
|
|
650
630
|
if (g === 0n) {
|
|
651
|
-
if (
|
|
652
|
-
|
|
631
|
+
if (o -= 64n, o < t) {
|
|
632
|
+
o = t;
|
|
653
633
|
break t;
|
|
654
634
|
}
|
|
655
635
|
} else {
|
|
656
|
-
|
|
636
|
+
o -= S(g);
|
|
657
637
|
break t;
|
|
658
638
|
}
|
|
659
639
|
++u;
|
|
660
640
|
}
|
|
661
641
|
} else
|
|
662
|
-
|
|
642
|
+
o -= S(s);
|
|
663
643
|
const i = r >> 11n & 0xfffffffffffffn;
|
|
664
|
-
i === 0n && r >> 63n && ++
|
|
644
|
+
i === 0n && r >> 63n && ++o;
|
|
665
645
|
const { buffer: c, byteOffset: a, length: f } = BigUint64Array.from([
|
|
666
|
-
|
|
646
|
+
o << 52n | i
|
|
667
647
|
]);
|
|
668
648
|
return new Float64Array(c, a, f)[0];
|
|
669
649
|
}
|
|
@@ -681,13 +661,13 @@ class x {
|
|
|
681
661
|
}
|
|
682
662
|
}
|
|
683
663
|
const D = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], q = 0x5851f42d4c957f2dn;
|
|
684
|
-
class
|
|
664
|
+
class N {
|
|
685
665
|
/**
|
|
686
666
|
* length = 2, `[state, increment]`
|
|
687
667
|
*/
|
|
688
668
|
#t;
|
|
689
669
|
static name = "PCGMinimal";
|
|
690
|
-
[Symbol.toStringTag] =
|
|
670
|
+
[Symbol.toStringTag] = N.name;
|
|
691
671
|
/**
|
|
692
672
|
* returns seed for constructing `PCGMinimal` instance
|
|
693
673
|
* @returns random seed `BigUint64Array` with length 2
|
|
@@ -719,7 +699,7 @@ class U {
|
|
|
719
699
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
720
700
|
get #e() {
|
|
721
701
|
const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
|
|
722
|
-
return
|
|
702
|
+
return C(r, e);
|
|
723
703
|
}
|
|
724
704
|
/**
|
|
725
705
|
*
|
|
@@ -735,8 +715,8 @@ class U {
|
|
|
735
715
|
if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
|
|
736
716
|
const r = 4294967296 % t;
|
|
737
717
|
for (; ; ) {
|
|
738
|
-
const
|
|
739
|
-
if (
|
|
718
|
+
const s = this.getU32Rand();
|
|
719
|
+
if (s >= r) return s % t;
|
|
740
720
|
}
|
|
741
721
|
}
|
|
742
722
|
/**
|
|
@@ -753,37 +733,35 @@ class U {
|
|
|
753
733
|
}
|
|
754
734
|
}
|
|
755
735
|
export {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
736
|
+
U as FloatRand,
|
|
737
|
+
B as NamedError,
|
|
738
|
+
N as PCGMinimal,
|
|
739
|
+
A as Queue,
|
|
760
740
|
l as Rational,
|
|
761
|
-
|
|
741
|
+
x as bailliePSW,
|
|
762
742
|
Q as compress,
|
|
763
|
-
ft as decodeLEB128,
|
|
764
743
|
Y as decodeRFC3986URIComponent,
|
|
765
744
|
tt as decompress,
|
|
766
|
-
at as encodeLEB128,
|
|
767
745
|
X as encodeRFC3986URIComponent,
|
|
768
|
-
|
|
746
|
+
_ as exEuclidean,
|
|
769
747
|
et as factorial,
|
|
770
748
|
it as fromString,
|
|
771
749
|
H as getHash,
|
|
772
|
-
|
|
750
|
+
E as getRandBIByBitLength,
|
|
773
751
|
j as getRandBIByRange,
|
|
774
752
|
ot as getRandPrimeByBitLength,
|
|
775
753
|
st as getRandPrimeByRange,
|
|
776
754
|
nt as getRndInt,
|
|
777
755
|
d as isDeepStrictEqual,
|
|
778
756
|
Z as isNode,
|
|
779
|
-
|
|
757
|
+
F as isSquare,
|
|
780
758
|
b as jacobiSymbol,
|
|
781
759
|
W as lazify,
|
|
782
760
|
p as modPow,
|
|
783
761
|
G as parseCSV,
|
|
784
762
|
z as promiseWithResolvers,
|
|
785
763
|
m as residue,
|
|
786
|
-
|
|
764
|
+
C as rot32,
|
|
787
765
|
rt as rot32BI,
|
|
788
766
|
K as sameValueZero,
|
|
789
767
|
J as sleep,
|
package/dist/u8arr-ext.d.ts
CHANGED