@tktb-tess/util-fns 0.11.2 → 0.11.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 +2 -0
- package/dist/bundle.js +147 -146
- package/dist/bundle.min.js +2 -2
- package/package.json +8 -7
package/README.md
CHANGED
package/dist/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T = new TextEncoder(), H = (n, t) => [n].includes(t), h = (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;
|
|
@@ -11,33 +11,33 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
11
11
|
if (Array.isArray(n) && Array.isArray(t)) {
|
|
12
12
|
if (n.length !== t.length) return !1;
|
|
13
13
|
for (let s = 0; s < n.length; s++)
|
|
14
|
-
if (!
|
|
14
|
+
if (!h(n[s], t[s])) return !1;
|
|
15
15
|
return !0;
|
|
16
16
|
}
|
|
17
17
|
if (n instanceof Set && t instanceof Set) {
|
|
18
18
|
const s = [...n.values()], o = [...t.values()];
|
|
19
|
-
return !!
|
|
19
|
+
return !!h(s, o);
|
|
20
20
|
}
|
|
21
21
|
if (n instanceof Map && t instanceof Map) {
|
|
22
22
|
const s = [...n.keys()], o = [...t.keys()];
|
|
23
|
-
if (!
|
|
23
|
+
if (!h(s, o)) return !1;
|
|
24
24
|
const i = [...n.values()], c = [...t.values()];
|
|
25
|
-
return !!
|
|
25
|
+
return !!h(i, c);
|
|
26
26
|
}
|
|
27
27
|
if (e === "[object Object]") {
|
|
28
28
|
const s = n, o = t, i = Object.keys(s), c = Object.keys(o);
|
|
29
29
|
for (const l of i) {
|
|
30
|
-
const u = c.find((
|
|
30
|
+
const u = c.find((x) => x === l);
|
|
31
31
|
if (u === void 0) return !1;
|
|
32
|
-
const [f,
|
|
33
|
-
if (!
|
|
32
|
+
const [f, g] = [s[l], o[u]];
|
|
33
|
+
if (!h(f, g)) return !1;
|
|
34
34
|
}
|
|
35
35
|
return !0;
|
|
36
36
|
}
|
|
37
37
|
throw Error(`comparing these objects is unavailable: ${n}, ${t}`, {
|
|
38
38
|
cause: [n, t]
|
|
39
39
|
});
|
|
40
|
-
},
|
|
40
|
+
}, J = () => {
|
|
41
41
|
let n, t;
|
|
42
42
|
return {
|
|
43
43
|
promise: new Promise((r, s) => {
|
|
@@ -46,12 +46,12 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
46
46
|
resolve: n,
|
|
47
47
|
reject: t
|
|
48
48
|
};
|
|
49
|
-
},
|
|
49
|
+
}, Y = (n) => new Promise((t) => {
|
|
50
50
|
setTimeout(() => t(), n);
|
|
51
|
-
}),
|
|
51
|
+
}), Z = (n) => {
|
|
52
52
|
const t = Object.prototype.toString.call(n);
|
|
53
53
|
return t.slice(8, t.length - 1);
|
|
54
|
-
},
|
|
54
|
+
}, Q = (n) => (...t) => () => n(...t), tt = (n) => {
|
|
55
55
|
const t = [];
|
|
56
56
|
let e = [], r = "", s = !1;
|
|
57
57
|
for (let o = 0; o < n.length; o++) {
|
|
@@ -60,23 +60,23 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
60
60
|
` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
|
|
61
61
|
}
|
|
62
62
|
return e.push(r.trim()), t.push(e), t;
|
|
63
|
-
},
|
|
64
|
-
const e =
|
|
63
|
+
}, nt = async (n, t) => {
|
|
64
|
+
const e = T.encode(n), r = await crypto.subtle.digest(t, e);
|
|
65
65
|
return new Uint8Array(r);
|
|
66
|
-
},
|
|
66
|
+
}, et = (n) => encodeURIComponent(n).replace(
|
|
67
67
|
/[!'()*]/g,
|
|
68
68
|
(e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`
|
|
69
|
-
),
|
|
69
|
+
), rt = (n) => {
|
|
70
70
|
if (n.includes("+"))
|
|
71
71
|
throw Error("An input string has '+'");
|
|
72
72
|
return decodeURIComponent(n);
|
|
73
|
-
},
|
|
73
|
+
}, st = async (n, t) => {
|
|
74
74
|
const r = new Blob([n]).stream().pipeThrough(new CompressionStream(t));
|
|
75
75
|
return new Response(r).bytes();
|
|
76
|
-
},
|
|
76
|
+
}, ot = async (n, t) => {
|
|
77
77
|
const r = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
|
|
78
78
|
return new Response(r).bytes();
|
|
79
|
-
},
|
|
79
|
+
}, it = (n, t) => new Promise((e, r) => {
|
|
80
80
|
setTimeout(async () => {
|
|
81
81
|
try {
|
|
82
82
|
const s = await n();
|
|
@@ -85,16 +85,17 @@ const x = new TextEncoder(), z = (n, t) => [n].includes(t), d = (n, t) => {
|
|
|
85
85
|
r(s);
|
|
86
86
|
}
|
|
87
87
|
}, t);
|
|
88
|
-
}),
|
|
88
|
+
}), N = "NamedError";
|
|
89
89
|
class I extends Error {
|
|
90
90
|
constructor(t, e, r) {
|
|
91
91
|
super(e, r), this.errName = t;
|
|
92
92
|
}
|
|
93
|
-
static name =
|
|
93
|
+
static name = N;
|
|
94
94
|
toJSON() {
|
|
95
95
|
const t = (() => {
|
|
96
96
|
const o = this.cause;
|
|
97
|
-
|
|
97
|
+
if (o != null)
|
|
98
|
+
return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
|
|
98
99
|
})(), { errName: e, message: r, stack: s } = this;
|
|
99
100
|
return {
|
|
100
101
|
errName: e,
|
|
@@ -105,24 +106,24 @@ class I extends Error {
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
Object.defineProperty(I.prototype, Symbol.toStringTag, {
|
|
108
|
-
value:
|
|
109
|
+
value: N
|
|
109
110
|
});
|
|
110
|
-
const
|
|
111
|
+
const ct = (n, t) => Math.floor(Math.random() * (t - n) + n), d = (n, t) => {
|
|
111
112
|
t < 0n && (t *= -1n);
|
|
112
113
|
const e = n % t;
|
|
113
114
|
return e < 0n ? e + t : e;
|
|
114
|
-
},
|
|
115
|
+
}, U = (n, t = !1) => {
|
|
115
116
|
if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
|
|
116
117
|
if (n <= 0) throw Error("`length` must be positive");
|
|
117
118
|
const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
|
|
118
119
|
let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
|
|
119
120
|
return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
|
|
120
|
-
},
|
|
121
|
+
}, R = (n, t) => {
|
|
121
122
|
if (n >= t)
|
|
122
123
|
throw new I("RangeError", "min is larger than max");
|
|
123
124
|
const e = t - n, r = e.toString(2).length, s = (() => {
|
|
124
125
|
for (let i = 0; i < 1e5; i++) {
|
|
125
|
-
const c =
|
|
126
|
+
const c = U(r);
|
|
126
127
|
if (c >= m(2n, BigInt(r), e))
|
|
127
128
|
return c % e;
|
|
128
129
|
}
|
|
@@ -132,14 +133,14 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
132
133
|
}, m = (n, t, e) => {
|
|
133
134
|
if (e < 1n) throw Error("`mod` must be positive");
|
|
134
135
|
if (t < 0n) throw Error("`power` must not be negative");
|
|
135
|
-
if (n =
|
|
136
|
+
if (n = d(n, e), e === 1n) return 0n;
|
|
136
137
|
if (n % e === 1n || n % e === 0n) return n;
|
|
137
138
|
if (n === e - 1n) return t & 1n ? e - 1n : 1n;
|
|
138
139
|
let r = 1n;
|
|
139
140
|
for (; t > 0n; )
|
|
140
141
|
t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
|
|
141
142
|
return r;
|
|
142
|
-
},
|
|
143
|
+
}, P = (n, t) => {
|
|
143
144
|
if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
|
|
144
145
|
if (n === 0n)
|
|
145
146
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
@@ -163,7 +164,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
163
164
|
}
|
|
164
165
|
const s = n + r | 1n, o = y(n, s), i = y(s, t);
|
|
165
166
|
return o * i;
|
|
166
|
-
},
|
|
167
|
+
}, j = (n) => {
|
|
167
168
|
let t = 3n, e = 1n, r = 1n;
|
|
168
169
|
const s = BigInt(n.toString(2).length) - 1n;
|
|
169
170
|
for (let o = s - 1n; o > -1n; --o) {
|
|
@@ -171,12 +172,12 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
171
172
|
r *= y(t, i), t = i, e *= r;
|
|
172
173
|
}
|
|
173
174
|
return e;
|
|
174
|
-
},
|
|
175
|
+
}, lt = (n) => {
|
|
175
176
|
if (n < 0n) throw Error("'n' must be non-negative");
|
|
176
177
|
if (n === 0n) return 1n;
|
|
177
178
|
const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
|
|
178
|
-
return
|
|
179
|
-
},
|
|
179
|
+
return j(n) << t;
|
|
180
|
+
}, _ = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), E = (n, t) => {
|
|
180
181
|
if (t < 1n || t % 2n === 0n)
|
|
181
182
|
throw Error("`n` is invalid");
|
|
182
183
|
for (; n < 0n; )
|
|
@@ -192,7 +193,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
192
193
|
[n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
|
|
193
194
|
}
|
|
194
195
|
return t === 1n ? e : 0n;
|
|
195
|
-
},
|
|
196
|
+
}, C = (n) => {
|
|
196
197
|
if (n < 0n) return !1;
|
|
197
198
|
if (n === 0n) return !0;
|
|
198
199
|
let t = 1n, e = n;
|
|
@@ -201,7 +202,7 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
201
202
|
r * r < n ? t = r : e = r;
|
|
202
203
|
}
|
|
203
204
|
return n === t ** 2n || n === (t + 1n) ** 2n;
|
|
204
|
-
},
|
|
205
|
+
}, O = (n) => {
|
|
205
206
|
if (n <= 1n) return !1;
|
|
206
207
|
if (n % 2n === 0n) return n === 2n;
|
|
207
208
|
let t = n - 1n, e = 0n;
|
|
@@ -215,36 +216,36 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
215
216
|
i = i * i % n;
|
|
216
217
|
}
|
|
217
218
|
return !1;
|
|
218
|
-
},
|
|
219
|
+
}, V = (n) => {
|
|
219
220
|
let t = 5n, e = E(t, n);
|
|
220
221
|
for (; e > 0n; ) {
|
|
221
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
222
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && C(n))
|
|
222
223
|
return [0n, 0n];
|
|
223
224
|
e = E(t, n);
|
|
224
225
|
}
|
|
225
226
|
return [t, e];
|
|
226
|
-
}, p = (n, t) => (n & 1n) === 1n ?
|
|
227
|
+
}, p = (n, t) => (n & 1n) === 1n ? d(n + t >> 1n, t) : d(n >> 1n, t), F = (n, t, e, r) => {
|
|
227
228
|
let s = 1n, o = e;
|
|
228
229
|
const i = n.toString(2).slice(1);
|
|
229
230
|
for (const c of i)
|
|
230
|
-
[s, o] = [
|
|
231
|
+
[s, o] = [d(s * o, t), p(o * o + r * s * s, t)], c === "1" && ([s, o] = [p(e * s + o, t), p(r * s + e * o, t)]);
|
|
231
232
|
return [s, o];
|
|
232
|
-
},
|
|
233
|
+
}, $ = (n, t, e, r) => {
|
|
233
234
|
if (n % 2n !== 1n)
|
|
234
235
|
throw Error("`n` must be odd");
|
|
235
236
|
let s = n + 1n, o = 0n;
|
|
236
237
|
for (; s % 2n === 0n; )
|
|
237
238
|
s >>= 1n, o += 1n;
|
|
238
|
-
const [i, c] =
|
|
239
|
+
const [i, c] = F(s, n, e, t);
|
|
239
240
|
let l = c;
|
|
240
241
|
if (i === 0n) return !0;
|
|
241
242
|
r = m(r, s, n);
|
|
242
243
|
for (let u = 0n; u < o; u++) {
|
|
243
244
|
if (l === 0n) return !0;
|
|
244
|
-
l =
|
|
245
|
+
l = d(l * l - 2n * r, n), r = m(r, 2n, n);
|
|
245
246
|
}
|
|
246
247
|
return !1;
|
|
247
|
-
},
|
|
248
|
+
}, v = (n) => {
|
|
248
249
|
if (n <= 1n) return !1;
|
|
249
250
|
if (n % 2n === 0n) return n === 2n;
|
|
250
251
|
const t = [
|
|
@@ -278,33 +279,33 @@ const it = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
|
278
279
|
for (const o of t)
|
|
279
280
|
if (n % o === 0n)
|
|
280
281
|
return n === o;
|
|
281
|
-
if (!
|
|
282
|
+
if (!O(n))
|
|
282
283
|
return !1;
|
|
283
|
-
const [e, r] =
|
|
284
|
+
const [e, r] = V(n);
|
|
284
285
|
if (r === 0n) return !1;
|
|
285
286
|
const s = (1n - e) / 4n;
|
|
286
|
-
return
|
|
287
|
-
},
|
|
287
|
+
return $(n, e, 1n, s);
|
|
288
|
+
}, ut = (n, t) => {
|
|
288
289
|
if (t < 2n)
|
|
289
290
|
throw Error("NoPrimesFound");
|
|
290
291
|
for (let r = 0; r < 1e5; r++) {
|
|
291
|
-
const s =
|
|
292
|
-
if (
|
|
292
|
+
const s = R(n, t);
|
|
293
|
+
if (v(s)) return s;
|
|
293
294
|
}
|
|
294
295
|
throw Error("NoPrimesFound");
|
|
295
|
-
},
|
|
296
|
+
}, at = (n, t = !1) => {
|
|
296
297
|
if (n < 2)
|
|
297
298
|
throw Error("NoPrimesFound");
|
|
298
299
|
for (let r = 0; r < 1e5; r++) {
|
|
299
|
-
const s =
|
|
300
|
-
if (
|
|
300
|
+
const s = U(n, t);
|
|
301
|
+
if (v(s)) return s;
|
|
301
302
|
}
|
|
302
303
|
throw Error("NoPrimesFound");
|
|
303
|
-
},
|
|
304
|
+
}, L = "Rational";
|
|
304
305
|
class a {
|
|
305
306
|
#t;
|
|
306
307
|
#n;
|
|
307
|
-
static name =
|
|
308
|
+
static name = L;
|
|
308
309
|
/**
|
|
309
310
|
* fraction (rational) class
|
|
310
311
|
* @param numerator
|
|
@@ -331,10 +332,10 @@ class a {
|
|
|
331
332
|
t = 1 / o;
|
|
332
333
|
let [i, c] = [1n, s], [l, u] = [0n, 1n];
|
|
333
334
|
for (; `${u}`.length < e + 1; ) {
|
|
334
|
-
const f = BigInt(Math.floor(t)),
|
|
335
|
-
if ([i, c] = [c, f * c + i], [l, u] = [u, f * u + l],
|
|
335
|
+
const f = BigInt(Math.floor(t)), g = t - Number(f);
|
|
336
|
+
if ([i, c] = [c, f * c + i], [l, u] = [u, f * u + l], g === 0)
|
|
336
337
|
return new a(r ? -c : c, u);
|
|
337
|
-
t = 1 /
|
|
338
|
+
t = 1 / g;
|
|
338
339
|
}
|
|
339
340
|
return new a(r ? -i : i, l);
|
|
340
341
|
}
|
|
@@ -342,7 +343,7 @@ class a {
|
|
|
342
343
|
* reduction
|
|
343
344
|
*/
|
|
344
345
|
#e() {
|
|
345
|
-
const { gcd: t } =
|
|
346
|
+
const { gcd: t } = P(this.#t, this.#n);
|
|
346
347
|
t !== 0n && (this.#t /= t, this.#n /= t);
|
|
347
348
|
}
|
|
348
349
|
/**
|
|
@@ -451,20 +452,20 @@ class a {
|
|
|
451
452
|
}
|
|
452
453
|
}
|
|
453
454
|
Object.defineProperty(a.prototype, Symbol.toStringTag, {
|
|
454
|
-
value:
|
|
455
|
+
value: L
|
|
455
456
|
});
|
|
456
|
-
const
|
|
457
|
+
const D = (n) => {
|
|
457
458
|
const t = Array.from(n, (e) => String.fromCharCode(e));
|
|
458
459
|
return btoa(t.join(""));
|
|
459
|
-
},
|
|
460
|
+
}, q = (n) => {
|
|
460
461
|
const t = atob(n);
|
|
461
462
|
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
462
|
-
},
|
|
463
|
+
}, ft = (n) => D(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), ht = (n) => {
|
|
463
464
|
const t = n.length & 3;
|
|
464
465
|
t > 0 && (n = n + "=".repeat(4 - t));
|
|
465
466
|
const e = n.replaceAll("-", "+").replaceAll("_", "/");
|
|
466
|
-
return
|
|
467
|
-
},
|
|
467
|
+
return q(e);
|
|
468
|
+
}, dt = (n) => {
|
|
468
469
|
let t = Array.from(n, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
469
470
|
const e = t.length % 6;
|
|
470
471
|
e && (t = "0".repeat(6 - e) + t);
|
|
@@ -473,7 +474,7 @@ const $ = (n) => {
|
|
|
473
474
|
r,
|
|
474
475
|
(o) => Number.parseInt(o[0], 16).toString(8).padStart(8, "0")
|
|
475
476
|
).join("").replace(/^0+/, "");
|
|
476
|
-
},
|
|
477
|
+
}, gt = (n) => {
|
|
477
478
|
const t = n.length & 7;
|
|
478
479
|
t && (n = "0".repeat(8 - t) + n);
|
|
479
480
|
const e = n.matchAll(/.{8}/g), s = Array.from(e, (o) => {
|
|
@@ -481,13 +482,13 @@ const $ = (n) => {
|
|
|
481
482
|
return Number.parseInt(i, 8).toString(16).padStart(6, "0");
|
|
482
483
|
}).join("").matchAll(/.{2}/g);
|
|
483
484
|
return Uint8Array.from(s, (o) => Number.parseInt(o[0], 16));
|
|
484
|
-
},
|
|
485
|
+
}, K = (n) => {
|
|
485
486
|
const t = n < 0n;
|
|
486
487
|
t && (n *= -1n);
|
|
487
488
|
const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, s = Math.floor(e / 7) + 1;
|
|
488
489
|
return r ? s - 1 : s;
|
|
489
|
-
},
|
|
490
|
-
const t =
|
|
490
|
+
}, mt = (n) => {
|
|
491
|
+
const t = K(n);
|
|
491
492
|
n = BigInt.asUintN(t * 7, n);
|
|
492
493
|
const e = new Uint8Array(t);
|
|
493
494
|
for (let s = 0; s < t - 1; ++s) {
|
|
@@ -496,7 +497,7 @@ const $ = (n) => {
|
|
|
496
497
|
}
|
|
497
498
|
const r = Number(n & 127n);
|
|
498
499
|
return e[t - 1] = r, n >>= 7n, e;
|
|
499
|
-
},
|
|
500
|
+
}, pt = (n) => {
|
|
500
501
|
const t = n.length;
|
|
501
502
|
let e = 0n;
|
|
502
503
|
for (let r = 0; r < t; ++r) {
|
|
@@ -510,41 +511,41 @@ const $ = (n) => {
|
|
|
510
511
|
for (; n > 0n && !(n & 1n); )
|
|
511
512
|
++t, n >>= 1n;
|
|
512
513
|
return BigInt.asUintN(64, t);
|
|
513
|
-
},
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
const
|
|
531
|
-
return new Float64Array(
|
|
514
|
+
}, S = (n, t) => {
|
|
515
|
+
const e = 0n, r = 1023n, s = n & 0x7ffn;
|
|
516
|
+
let o = r - 1n;
|
|
517
|
+
if (s > 0n)
|
|
518
|
+
return o -= b(s), o;
|
|
519
|
+
o -= 11n;
|
|
520
|
+
const i = 1e5;
|
|
521
|
+
for (let c = 0; c < i; ++c) {
|
|
522
|
+
const l = t();
|
|
523
|
+
if (l > 0n)
|
|
524
|
+
return o -= b(l), o;
|
|
525
|
+
if (o -= 64n, o < e)
|
|
526
|
+
return e;
|
|
527
|
+
}
|
|
528
|
+
throw Error("loop exceeded limit");
|
|
529
|
+
}, yt = (n) => {
|
|
530
|
+
const t = () => BigInt.asUintN(64, n()), e = () => {
|
|
531
|
+
const r = t(), s = BigInt.asUintN(52, r >> 11n), i = s === 0n && r >> 63n === 1n ? S(r, t) + 1n : S(r, t), { buffer: c } = BigUint64Array.from([i << 52n | s]);
|
|
532
|
+
return new Float64Array(c)[0];
|
|
532
533
|
};
|
|
533
534
|
return () => {
|
|
534
|
-
for (let
|
|
535
|
-
const
|
|
536
|
-
if (
|
|
537
|
-
return
|
|
535
|
+
for (let s = 0; s < 1e5; ++s) {
|
|
536
|
+
const o = e();
|
|
537
|
+
if (o < 1)
|
|
538
|
+
return o;
|
|
538
539
|
}
|
|
539
540
|
throw Error("Loop limit exceeded");
|
|
540
541
|
};
|
|
541
|
-
},
|
|
542
|
-
class
|
|
542
|
+
}, G = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], W = 0x5851f42d4c957f2dn, A = "PCGMinimal";
|
|
543
|
+
class X {
|
|
543
544
|
/**
|
|
544
545
|
* length = 2, `[state, increment]`
|
|
545
546
|
*/
|
|
546
547
|
#t;
|
|
547
|
-
static name =
|
|
548
|
+
static name = A;
|
|
548
549
|
/**
|
|
549
550
|
* @param seeds
|
|
550
551
|
* `BigUint64Array` with length 2. \
|
|
@@ -559,16 +560,16 @@ class W {
|
|
|
559
560
|
* const betterRng = new PCGMinimal(seed);
|
|
560
561
|
*/
|
|
561
562
|
constructor(t) {
|
|
562
|
-
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(
|
|
563
|
+
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(G);
|
|
563
564
|
}
|
|
564
565
|
/** step inner state */
|
|
565
566
|
#n() {
|
|
566
|
-
this.#t[0] = this.#t[0] *
|
|
567
|
+
this.#t[0] = this.#t[0] * W + this.#t[1];
|
|
567
568
|
}
|
|
568
569
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
569
570
|
get #e() {
|
|
570
571
|
const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
|
|
571
|
-
return
|
|
572
|
+
return _(r, e);
|
|
572
573
|
}
|
|
573
574
|
/**
|
|
574
575
|
*
|
|
@@ -607,16 +608,16 @@ class W {
|
|
|
607
608
|
yield typeof e == "number" ? this.getBoundedRandU32(e) : this.getRandU32();
|
|
608
609
|
}
|
|
609
610
|
}
|
|
610
|
-
Object.defineProperty(
|
|
611
|
-
value:
|
|
611
|
+
Object.defineProperty(X.prototype, Symbol.toStringTag, {
|
|
612
|
+
value: A
|
|
612
613
|
});
|
|
613
|
-
const
|
|
614
|
+
const k = [
|
|
614
615
|
0xbe562cb412e2260en,
|
|
615
616
|
0x2e4284137d641affn,
|
|
616
617
|
0x4e19b36ee933e27en,
|
|
617
618
|
0x7581cf8c4f4d4f7dn
|
|
618
619
|
];
|
|
619
|
-
class
|
|
620
|
+
class B {
|
|
620
621
|
bits = 64;
|
|
621
622
|
#t;
|
|
622
623
|
static name = "XoshiroMinimal";
|
|
@@ -634,7 +635,7 @@ class S {
|
|
|
634
635
|
* const betterRng = new XoshiroMinimal(seed);
|
|
635
636
|
*/
|
|
636
637
|
constructor(t) {
|
|
637
|
-
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(
|
|
638
|
+
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(k);
|
|
638
639
|
}
|
|
639
640
|
#n() {
|
|
640
641
|
const t = this.#t[1] << 17n;
|
|
@@ -687,14 +688,14 @@ class S {
|
|
|
687
688
|
yield e === void 0 ? this.getRandU32() : this.getBoundedRandU32(e);
|
|
688
689
|
}
|
|
689
690
|
}
|
|
690
|
-
Object.defineProperty(
|
|
691
|
-
value:
|
|
691
|
+
Object.defineProperty(B.prototype, Symbol.toStringTag, {
|
|
692
|
+
value: B.name
|
|
692
693
|
});
|
|
693
|
-
const
|
|
694
|
-
class
|
|
694
|
+
const M = "WorkerStream";
|
|
695
|
+
class z extends ReadableStream {
|
|
695
696
|
close;
|
|
696
697
|
#t;
|
|
697
|
-
static name =
|
|
698
|
+
static name = M;
|
|
698
699
|
constructor(t, e) {
|
|
699
700
|
let r, s, o;
|
|
700
701
|
super(
|
|
@@ -723,49 +724,49 @@ class k extends ReadableStream {
|
|
|
723
724
|
this.#t.postMessage(t, e);
|
|
724
725
|
}
|
|
725
726
|
}
|
|
726
|
-
Object.defineProperty(
|
|
727
|
-
value:
|
|
727
|
+
Object.defineProperty(z.prototype, Symbol.toStringTag, {
|
|
728
|
+
value: M
|
|
728
729
|
});
|
|
729
730
|
export {
|
|
730
731
|
I as NamedError,
|
|
731
|
-
|
|
732
|
+
X as PCGMinimal,
|
|
732
733
|
a as Rational,
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
734
|
+
z as WorkerStream,
|
|
735
|
+
B as XoshiroMinimal,
|
|
736
|
+
v as bailliePSW,
|
|
737
|
+
st as compress,
|
|
738
|
+
pt as decodeLEB128,
|
|
739
|
+
rt as decodeRFC3986URIComponent,
|
|
740
|
+
ot as decompress,
|
|
741
|
+
mt as encodeLEB128,
|
|
742
|
+
et as encodeRFC3986URIComponent,
|
|
743
|
+
P as exEuclidean,
|
|
744
|
+
lt as factorial,
|
|
745
|
+
yt as floatRng,
|
|
746
|
+
q as fromBase64,
|
|
747
|
+
ht as fromBase64Url,
|
|
748
|
+
gt as fromOct,
|
|
749
|
+
nt as getHash,
|
|
750
|
+
U as getRandBIByBitLength,
|
|
751
|
+
R as getRandBIByRange,
|
|
752
|
+
at as getRandPrimeByBitLength,
|
|
753
|
+
ut as getRandPrimeByRange,
|
|
754
|
+
ct as getRndInt,
|
|
755
|
+
Z as getStringTag,
|
|
756
|
+
h as isDeepStrictEqual,
|
|
757
|
+
C as isSquare,
|
|
757
758
|
E as jacobiSymbol,
|
|
758
|
-
|
|
759
|
+
Q as lazify,
|
|
759
760
|
m as modPow,
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
761
|
+
tt as parseCSV,
|
|
762
|
+
d as residue,
|
|
763
|
+
_ as rot32,
|
|
763
764
|
w as rot64,
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
765
|
+
H as sameValueZero,
|
|
766
|
+
it as setTimeoutPromise,
|
|
767
|
+
Y as sleep,
|
|
768
|
+
D as toBase64,
|
|
769
|
+
ft as toBase64Url,
|
|
770
|
+
dt as toOct,
|
|
771
|
+
J as withResolvers
|
|
771
772
|
};
|
package/dist/bundle.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var UtilFns=(function(
|
|
2
|
-
`&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=i}return e.push(r.trim()),t.push(e),t},X=async(n,t)=>{const e=V.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},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)},H=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()},Y=(n,t)=>new Promise((e,r)=>{setTimeout(async()=>{try{const s=await n();e(s)}catch(s){r(s)}},t)}),N="NamedError";class p extends Error{constructor(t,e,r){super(e,r),this.errName=t}static name=N;toJSON(){const t=(()=>{const o=this.cause;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})(),{errName:e,message:r,stack:s}=this;return{errName:e,message:r,stack:s,cause:t}}}Object.defineProperty(p.prototype,Symbol.toStringTag,{value:N});const Z=(n,t)=>Math.floor(Math.random()*(t-n)+n),m=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},I=(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,o=>o.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 new p("RangeError","min is larger than max");const e=t-n,r=e.toString(2).length,s=(()=>{for(let i=0;i<1e5;i++){const c=I(r);if(c>=y(2n,BigInt(r),e))return c%e}throw Error("Failed to generate a random bigint")})();return n+s},y=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=m(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},R=(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],[o,i,c]=[0n,-1n,t];for(;;){const l=s/c,u=s-l*c;if(u===0n)break;[e,o]=[o,e-l*o],[r,i]=[i,r-l*i],[s,c]=[c,u]}return c<0n&&(o*=-1n,i*=-1n,c*=-1n),{x:o,y:i,gcd:c}},w=(n,t)=>{if(n>=t)return 1n;const e=BigInt((t-2n).toString(2).length),r=(t-n)/2n;if(e*r<63n){let c=n;for(let l=n+2n;l<t;l+=2n)c*=l;return c}const s=n+r|1n,o=w(n,s),i=w(s,t);return o*i},Q=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let o=s-1n;o>-1n;--o){const i=(n>>o)+1n|1n;r*=w(t,i),t=i,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 Q(n)<<t},L=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,B=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),E=(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},M=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*r<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},tt=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 i=y(2n,r,n);if(i===1n)return!0;for(let c=0n;c<s;c++){if(i===n-1n)return!0;i=i*i%n}return!1},nt=n=>{let t=5n,e=E(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&M(n))return[0n,0n];e=E(t,n)}return[t,e]},b=(n,t)=>(n&1n)===1n?m(n+t>>1n,t):m(n>>1n,t),et=(n,t,e,r)=>{let s=1n,o=e;const i=n.toString(2).slice(1);for(const c of i)[s,o]=[m(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)]);return[s,o]},rt=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,o=0n;for(;s%2n===0n;)s>>=1n,o+=1n;const[i,c]=et(s,n,e,t);let l=c;if(i===0n)return!0;r=y(r,s,n);for(let u=0n;u<o;u++){if(l===0n)return!0;l=m(l*l-2n*r,n),r=y(r,2n,n)}return!1},S=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 o of t)if(n%o===0n)return n===o;if(!tt(n))return!1;const[e,r]=nt(n);if(r===0n)return!1;const s=(1n-e)/4n;return rt(n,e,1n,s)},st=(n,t)=>{if(t<2n)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=v(n,t);if(S(s))return s}throw Error("NoPrimesFound")},ot=(n,t=!1)=>{if(n<2)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=I(n,t);if(S(s))return s}throw Error("NoPrimesFound")},A="Rational";class f{#t;#n;static name=A;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)),o=t-Number(s);if(o===0)return new f(r?-s:s,1n);t=1/o;let[i,c]=[1n,s],[l,u]=[0n,1n];for(;`${u}`.length<e+1;){const h=BigInt(Math.floor(t)),d=t-Number(h);if([i,c]=[c,h*c+i],[l,u]=[u,h*u+l],d===0)return new f(r?-c:c,u);t=1/d}return new f(r?-i:i,l)}#e(){const{gcd:t}=R(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),o=r.at(2);if(!s||!o)throw Error("cannot parse");return new f(BigInt(s),BigInt(o))}}Object.defineProperty(f.prototype,Symbol.toStringTag,{value:A});const T=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},P=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},it=n=>T(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),ct=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return P(e)},at=n=>{let t=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const e=t.length%6;e&&(t="0".repeat(6-e)+t);const r=t.matchAll(/.{6}/g);return Array.from(r,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},lt=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),s=Array.from(e,o=>{const i=o[0];return Number.parseInt(i,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,o=>Number.parseInt(o[0],16))},ut=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},ft=n=>{const t=ut(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const o=Number(n&127n)|128;e[s]=o,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},ht=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)},C=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)},dt=n=>{const t=0n,e=1023n,r=()=>BigInt.asUintN(64,n()),s=i=>{const c=i&0x7ffn;let l=e-1n;if(c>0n)return l-=C(c),l;l-=11n;const u=1e5;for(let h=0;h<u;++h){const d=r();if(d>0n)return l-=C(d),l;if(l-=64n,l<t)return t}throw Error("loop exceeded limit")},o=()=>{const i=r(),c=BigInt.asUintN(52,i>>11n),u=c===0n&&i>>63n===1n?s(i)+1n:s(i),{buffer:h}=BigUint64Array.from([u<<52n|c]);return new Float64Array(h)[0]};return()=>{for(let c=0;c<1e5;++c){const l=o();if(l<1)return l}throw Error("Loop limit exceeded")}},gt=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],mt=0x5851f42d4c957f2dn,j="PCGMinimal";class _{#t;static name=j;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(gt)}#n(){this.#t[0]=this.#t[0]*mt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return L(r,e)}getRandU32(){return this.#n(),this.#e}getBoundedRandU32(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 o=0;o<s;++o){const i=this.getRandU32();if(i>=r)return i%t}throw Error("exceeded loop limit")}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedRandU32(e):this.getRandU32()}}Object.defineProperty(_.prototype,Symbol.toStringTag,{value:j});const yt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class U{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(yt)}#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]=B(this.#t[3],45n)}get value(){const t=B(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}getRandU64(){const t=this.value;return this.#n(),t}getRandU32(){const t=BigInt.asUintN(32,this.getRandU64());return Number(t)}getBoundedRandU64(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 o=0;o<s;++o){const i=this.getRandU64();if(i>=r)return i%t}throw Error("exceeded loop limit")}getBoundedRandU32(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedRandU64(BigInt(t));return Number(r)}*genRandU64s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU64():this.getBoundedRandU64(e)}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU32():this.getBoundedRandU32(e)}}Object.defineProperty(U.prototype,Symbol.toStringTag,{value:U.name});const O="WorkerStream";class F extends ReadableStream{close;#t;static name=O;constructor(t,e){let r,s,o;super({start:i=>{r=c=>{i.enqueue(c.data)},s=c=>{t.removeEventListener("message",r),t.removeEventListener("error",s);const l=new p("WorkerStreamError",c.message,{cause:c.error});i.error(l)},o=()=>{t.removeEventListener("message",r),t.removeEventListener("error",s),i.close()},t.addEventListener("message",r),t.addEventListener("error",s)},cancel:i=>{console.log("Canceled reason:",i),t.removeEventListener("message",r),t.removeEventListener("error",s)}},e),this.close=o,this.#t=t}postMessage(t,e){this.#t.postMessage(t,e)}}return Object.defineProperty(F.prototype,Symbol.toStringTag,{value:O}),a.NamedError=p,a.PCGMinimal=_,a.Rational=f,a.WorkerStream=F,a.XoshiroMinimal=U,a.bailliePSW=S,a.compress=H,a.decodeLEB128=ht,a.decodeRFC3986URIComponent=z,a.decompress=J,a.encodeLEB128=ft,a.encodeRFC3986URIComponent=k,a.exEuclidean=R,a.factorial=x,a.floatRng=dt,a.fromBase64=P,a.fromBase64Url=ct,a.fromOct=lt,a.getHash=X,a.getRandBIByBitLength=I,a.getRandBIByRange=v,a.getRandPrimeByBitLength=ot,a.getRandPrimeByRange=st,a.getRndInt=Z,a.getStringTag=K,a.isDeepStrictEqual=g,a.isSquare=M,a.jacobiSymbol=E,a.lazify=W,a.modPow=y,a.parseCSV=G,a.residue=m,a.rot32=L,a.rot64=B,a.sameValueZero=$,a.setTimeoutPromise=Y,a.sleep=q,a.toBase64=T,a.toBase64Url=it,a.toOct=at,a.withResolvers=D,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),a})({});
|
|
1
|
+
var UtilFns=(function(c){"use strict";const $=new TextEncoder,D=(n,t)=>[n].includes(t),h=(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(!h(n[s],t[s]))return!1;return!0}if(n instanceof Set&&t instanceof Set){const s=[...n.values()],o=[...t.values()];return!!h(s,o)}if(n instanceof Map&&t instanceof Map){const s=[...n.keys()],o=[...t.keys()];if(!h(s,o))return!1;const i=[...n.values()],a=[...t.values()];return!!h(i,a)}if(e==="[object Object]"){const s=n,o=t,i=Object.keys(s),a=Object.keys(o);for(const l of i){const f=a.find(It=>It===l);if(f===void 0)return!1;const[m,p]=[s[l],o[f]];if(!h(m,p))return!1}return!0}throw Error(`comparing these objects is unavailable: ${n}, ${t}`,{cause:[n,t]})},q=()=>{let n,t;return{promise:new Promise((r,s)=>{n=r,t=s}),resolve:n,reject:t}},K=n=>new Promise(t=>{setTimeout(()=>t(),n)}),W=n=>{const t=Object.prototype.toString.call(n);return t.slice(8,t.length-1)},G=n=>(...t)=>()=>n(...t),X=n=>{const t=[];let e=[],r="",s=!1;for(let o=0;o<n.length;o++){const i=n[o];i==='"'&&(o===0||n[o-1]!=="\\")?s=!s:i===","&&!s?(e.push(r.trim()),r=""):i===`
|
|
2
|
+
`&&!s?(e.push(r.trim()),t.push(e),e=[],r=""):r+=i}return e.push(r.trim()),t.push(e),t},k=async(n,t)=>{const e=$.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},z=n=>encodeURIComponent(n).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),H=n=>{if(n.includes("+"))throw Error("An input string has '+'");return decodeURIComponent(n)},J=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new CompressionStream(t));return new Response(r).bytes()},Y=async(n,t)=>{const r=new Blob([n]).stream().pipeThrough(new DecompressionStream(t));return new Response(r).bytes()},Z=(n,t)=>new Promise((e,r)=>{setTimeout(async()=>{try{const s=await n();e(s)}catch(s){r(s)}},t)}),N="NamedError";class y extends Error{constructor(t,e,r){super(e,r),this.errName=t}static name=N;toJSON(){const t=(()=>{const o=this.cause;if(o!=null)return typeof o=="string"||typeof o=="number"||typeof o=="boolean"?o:typeof o=="bigint"?o.toString():typeof o=="object"?o instanceof Set||o instanceof Map?Object.fromEntries(o):o:void 0})(),{errName:e,message:r,stack:s}=this;return{errName:e,message:r,stack:s,cause:t}}}Object.defineProperty(y.prototype,Symbol.toStringTag,{value:N});const Q=(n,t)=>Math.floor(Math.random()*(t-n)+n),d=(n,t)=>{t<0n&&(t*=-1n);const e=n%t;return e<0n?e+t:e},I=(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,o=>o.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(s=s.replace(/^\d/,"1")),BigInt("0b"+s)},R=(n,t)=>{if(n>=t)throw new y("RangeError","min is larger than max");const e=t-n,r=e.toString(2).length,s=(()=>{for(let i=0;i<1e5;i++){const a=I(r);if(a>=g(2n,BigInt(r),e))return a%e}throw Error("Failed to generate a random bigint")})();return n+s},g=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");if(n=d(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},v=(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],[o,i,a]=[0n,-1n,t];for(;;){const l=s/a,f=s-l*a;if(f===0n)break;[e,o]=[o,e-l*o],[r,i]=[i,r-l*i],[s,a]=[a,f]}return a<0n&&(o*=-1n,i*=-1n,a*=-1n),{x:o,y:i,gcd:a}},w=(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,o=w(n,s),i=w(s,t);return o*i},x=n=>{let t=3n,e=1n,r=1n;const s=BigInt(n.toString(2).length)-1n;for(let o=s-1n;o>-1n;--o){const i=(n>>o)+1n|1n;r*=w(t,i),t=i,e*=r}return e},tt=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},L=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,B=(n,t)=>BigInt.asUintN(64,n>>(t&63n)|n<<(-t&63n)),E=(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},M=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*r<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},nt=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 i=g(2n,r,n);if(i===1n)return!0;for(let a=0n;a<s;a++){if(i===n-1n)return!0;i=i*i%n}return!1},et=n=>{let t=5n,e=E(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&M(n))return[0n,0n];e=E(t,n)}return[t,e]},b=(n,t)=>(n&1n)===1n?d(n+t>>1n,t):d(n>>1n,t),rt=(n,t,e,r)=>{let s=1n,o=e;const i=n.toString(2).slice(1);for(const a of i)[s,o]=[d(s*o,t),b(o*o+r*s*s,t)],a==="1"&&([s,o]=[b(e*s+o,t),b(r*s+e*o,t)]);return[s,o]},st=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let s=n+1n,o=0n;for(;s%2n===0n;)s>>=1n,o+=1n;const[i,a]=rt(s,n,e,t);let l=a;if(i===0n)return!0;r=g(r,s,n);for(let f=0n;f<o;f++){if(l===0n)return!0;l=d(l*l-2n*r,n),r=g(r,2n,n)}return!1},S=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 o of t)if(n%o===0n)return n===o;if(!nt(n))return!1;const[e,r]=et(n);if(r===0n)return!1;const s=(1n-e)/4n;return st(n,e,1n,s)},ot=(n,t)=>{if(t<2n)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=R(n,t);if(S(s))return s}throw Error("NoPrimesFound")},it=(n,t=!1)=>{if(n<2)throw Error("NoPrimesFound");for(let r=0;r<1e5;r++){const s=I(n,t);if(S(s))return s}throw Error("NoPrimesFound")},A="Rational";class u{#t;#n;static name=A;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 u(0n,0n);if(Math.abs(t)===1/0)return new u(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const s=BigInt(Math.floor(t)),o=t-Number(s);if(o===0)return new u(r?-s:s,1n);t=1/o;let[i,a]=[1n,s],[l,f]=[0n,1n];for(;`${f}`.length<e+1;){const m=BigInt(Math.floor(t)),p=t-Number(m);if([i,a]=[a,m*a+i],[l,f]=[f,m*f+l],p===0)return new u(r?-a:a,f);t=1/p}return new u(r?-i:i,l)}#e(){const{gcd:t}=v(this.#t,this.#n);t!==0n&&(this.#t/=t,this.#n/=t)}minus(){return new u(-this.#t,this.#n)}inverse(){return new u(this.#n,this.#t)}add(t){const e=this.#n*t.#n,r=this.#t*t.#n+t.#t*this.#n;return new u(r,e)}substr(t){return this.add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new u(r,e)}divide(t){return this.multiply(t.inverse())}mediant(t){const e=this.#n+t.#n,r=this.#t+t.#t;return new u(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 u(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),o=r.at(2);if(!s||!o)throw Error("cannot parse");return new u(BigInt(s),BigInt(o))}}Object.defineProperty(u.prototype,Symbol.toStringTag,{value:A});const T=n=>{const t=Array.from(n,e=>String.fromCharCode(e));return btoa(t.join(""))},P=n=>{const t=atob(n);return Uint8Array.from(t,e=>e.charCodeAt(0))},ct=n=>T(n).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,""),at=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll("-","+").replaceAll("_","/");return P(e)},lt=n=>{let t=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");const e=t.length%6;e&&(t="0".repeat(6-e)+t);const r=t.matchAll(/.{6}/g);return Array.from(r,o=>Number.parseInt(o[0],16).toString(8).padStart(8,"0")).join("").replace(/^0+/,"")},ut=n=>{const t=n.length&7;t&&(n="0".repeat(8-t)+n);const e=n.matchAll(/.{8}/g),s=Array.from(e,o=>{const i=o[0];return Number.parseInt(i,8).toString(16).padStart(6,"0")}).join("").matchAll(/.{2}/g);return Uint8Array.from(s,o=>Number.parseInt(o[0],16))},ft=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},ht=n=>{const t=ft(n);n=BigInt.asUintN(t*7,n);const e=new Uint8Array(t);for(let s=0;s<t-1;++s){const o=Number(n&127n)|128;e[s]=o,n>>=7n}const r=Number(n&127n);return e[t-1]=r,n>>=7n,e},dt=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)},C=n=>{if(n===0n)return 64n;let t=0n;for(;n>0n&&!(n&1n);)++t,n>>=1n;return BigInt.asUintN(64,t)},j=(n,t)=>{const e=0n,r=1023n,s=n&0x7ffn;let o=r-1n;if(s>0n)return o-=C(s),o;o-=11n;const i=1e5;for(let a=0;a<i;++a){const l=t();if(l>0n)return o-=C(l),o;if(o-=64n,o<e)return e}throw Error("loop exceeded limit")},gt=n=>{const t=()=>BigInt.asUintN(64,n()),e=()=>{const r=t(),s=BigInt.asUintN(52,r>>11n),i=s===0n&&r>>63n===1n?j(r,t)+1n:j(r,t),{buffer:a}=BigUint64Array.from([i<<52n|s]);return new Float64Array(a)[0]};return()=>{for(let s=0;s<1e5;++s){const o=e();if(o<1)return o}throw Error("Loop limit exceeded")}},mt=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],yt=0x5851f42d4c957f2dn,O="PCGMinimal";class _{#t;static name=O;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(mt)}#n(){this.#t[0]=this.#t[0]*yt+this.#t[1]}get#e(){const t=this.#t[0],e=Number(t>>59n),r=Number(BigInt.asUintN(32,(t^t>>18n)>>27n));return L(r,e)}getRandU32(){return this.#n(),this.#e}getBoundedRandU32(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 o=0;o<s;++o){const i=this.getRandU32();if(i>=r)return i%t}throw Error("exceeded loop limit")}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedRandU32(e):this.getRandU32()}}Object.defineProperty(_.prototype,Symbol.toStringTag,{value:O});const pt=[0xbe562cb412e2260en,0x2e4284137d641affn,0x4e19b36ee933e27en,0x7581cf8c4f4d4f7dn];class U{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(pt)}#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]=B(this.#t[3],45n)}get value(){const t=B(this.#t[0]+this.#t[3],23n)+this.#t[0];return BigInt.asUintN(64,t)}getRandU64(){const t=this.value;return this.#n(),t}getRandU32(){const t=BigInt.asUintN(32,this.getRandU64());return Number(t)}getBoundedRandU64(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 o=0;o<s;++o){const i=this.getRandU64();if(i>=r)return i%t}throw Error("exceeded loop limit")}getBoundedRandU32(t){if(t>4294967296)throw Error("'bound' exceeded limit");if(t<=0n)throw Error("'bound' must be positive");const r=this.getBoundedRandU64(BigInt(t));return Number(r)}*genRandU64s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU64():this.getBoundedRandU64(e)}*genRandU32s(t,e){if(t<=0)throw Error("'step' must be positive");for(let r=0;r<t;++r)yield e===void 0?this.getRandU32():this.getBoundedRandU32(e)}}Object.defineProperty(U.prototype,Symbol.toStringTag,{value:U.name});const F="WorkerStream";class V extends ReadableStream{close;#t;static name=F;constructor(t,e){let r,s,o;super({start:i=>{r=a=>{i.enqueue(a.data)},s=a=>{t.removeEventListener("message",r),t.removeEventListener("error",s);const l=new y("WorkerStreamError",a.message,{cause:a.error});i.error(l)},o=()=>{t.removeEventListener("message",r),t.removeEventListener("error",s),i.close()},t.addEventListener("message",r),t.addEventListener("error",s)},cancel:i=>{console.log("Canceled reason:",i),t.removeEventListener("message",r),t.removeEventListener("error",s)}},e),this.close=o,this.#t=t}postMessage(t,e){this.#t.postMessage(t,e)}}return Object.defineProperty(V.prototype,Symbol.toStringTag,{value:F}),c.NamedError=y,c.PCGMinimal=_,c.Rational=u,c.WorkerStream=V,c.XoshiroMinimal=U,c.bailliePSW=S,c.compress=J,c.decodeLEB128=dt,c.decodeRFC3986URIComponent=H,c.decompress=Y,c.encodeLEB128=ht,c.encodeRFC3986URIComponent=z,c.exEuclidean=v,c.factorial=tt,c.floatRng=gt,c.fromBase64=P,c.fromBase64Url=at,c.fromOct=ut,c.getHash=k,c.getRandBIByBitLength=I,c.getRandBIByRange=R,c.getRandPrimeByBitLength=it,c.getRandPrimeByRange=ot,c.getRndInt=Q,c.getStringTag=W,c.isDeepStrictEqual=h,c.isSquare=M,c.jacobiSymbol=E,c.lazify=G,c.modPow=g,c.parseCSV=X,c.residue=d,c.rot32=L,c.rot64=B,c.sameValueZero=D,c.setTimeoutPromise=Z,c.sleep=K,c.toBase64=T,c.toBase64Url=ct,c.toOct=lt,c.withResolvers=q,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"}),c})({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"import": "./dist/bundle.js"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": "
|
|
21
|
-
"pnpm": "
|
|
20
|
+
"node": ">=22",
|
|
21
|
+
"pnpm": ">=10"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
@@ -26,15 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^25.0.
|
|
29
|
+
"@types/node": "^25.0.9",
|
|
30
30
|
"tsx": "^4.21.0",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
|
-
"vite": "^7.3.
|
|
32
|
+
"vite": "^7.3.1",
|
|
33
33
|
"vite-plugin-dts": "^4.5.4",
|
|
34
|
-
"vitest": "^4.0.
|
|
34
|
+
"vitest": "^4.0.17"
|
|
35
35
|
},
|
|
36
36
|
"volta": {
|
|
37
|
-
"node": "
|
|
37
|
+
"node": "24.13.0",
|
|
38
|
+
"pnpm": "10.28.0"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"dev": "vite",
|