@tktb-tess/util-fns 0.5.1 → 0.7.0
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/LICENSE +21 -21
- package/README.md +30 -31
- package/dist/bundle.js +105 -84
- package/dist/executer.d.ts +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/named-error.d.ts +18 -0
- package/dist/util.d.ts +8 -2
- package/package.json +15 -19
- package/dist/brand.d.ts +0 -7
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Tessyrrhaqt
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tessyrrhaqt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
# util-fns
|
|
2
|
-
|
|
3
|
-
Utility functions for personal use
|
|
4
|
-
|
|
5
|
-
ESM only
|
|
6
|
-
|
|
7
|
-
Available in both a browser and Node.js environment.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i @tktb-tess/util-fns
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### Usage
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { modPow } from '@tktb-tess/util-fns';
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
# util-fns
|
|
2
|
+
|
|
3
|
+
Utility functions for personal use
|
|
4
|
+
|
|
5
|
+
ESM only
|
|
6
|
+
|
|
7
|
+
Available in both a browser and Node.js environment.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @tktb-tess/util-fns
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { modPow, bailliePSW } from '@tktb-tess/util-fns';
|
|
19
|
+
|
|
20
|
+
const ans = modPow(2n, 16n, 17n);
|
|
21
|
+
console.log(ans); // 1n
|
|
22
|
+
|
|
23
|
+
// Baillie-PSW primality test
|
|
24
|
+
console.log(bailliePSW(2n)); // true
|
|
25
|
+
console.log(bailliePSW(4n)): // false
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
package/dist/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T = new TextEncoder(), $ = (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,31 +11,31 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (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()], i = [...t.values()];
|
|
19
|
-
return !!
|
|
19
|
+
return !!h(s, i);
|
|
20
20
|
}
|
|
21
21
|
if (n instanceof Map && t instanceof Map) {
|
|
22
22
|
const s = [...n.keys()], i = [...t.keys()];
|
|
23
|
-
if (!
|
|
23
|
+
if (!h(s, i)) return !1;
|
|
24
24
|
const o = [...n.values()], c = [...t.values()];
|
|
25
|
-
return !!
|
|
25
|
+
return !!h(o, c);
|
|
26
26
|
}
|
|
27
27
|
if (e === "[object Object]") {
|
|
28
28
|
const s = n, i = t, o = Object.keys(s), c = Object.keys(i);
|
|
29
29
|
for (const u of o) {
|
|
30
|
-
const l = c.find((
|
|
30
|
+
const l = c.find((j) => j === u);
|
|
31
31
|
if (l === void 0) return !1;
|
|
32
|
-
const [
|
|
33
|
-
if (!a
|
|
32
|
+
const [a, d] = [s[u], i[l]];
|
|
33
|
+
if (!h(a, d)) return !1;
|
|
34
34
|
}
|
|
35
35
|
return !0;
|
|
36
36
|
}
|
|
37
37
|
throw Error(`comparing these objects is still unavailable: ${n} ${t}`);
|
|
38
|
-
},
|
|
38
|
+
}, q = () => {
|
|
39
39
|
let n, t;
|
|
40
40
|
return {
|
|
41
41
|
promise: new Promise((r, s) => {
|
|
@@ -44,7 +44,7 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
44
44
|
resolve: n,
|
|
45
45
|
reject: t
|
|
46
46
|
};
|
|
47
|
-
},
|
|
47
|
+
}, k = (n) => new Promise((t) => {
|
|
48
48
|
setTimeout(() => t(), n);
|
|
49
49
|
}), D = (n) => (...t) => () => n(...t), K = (n) => {
|
|
50
50
|
const t = [];
|
|
@@ -55,31 +55,31 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
55
55
|
` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += o;
|
|
56
56
|
}
|
|
57
57
|
return e.push(r.trim()), t.push(e), t;
|
|
58
|
-
},
|
|
59
|
-
const e =
|
|
58
|
+
}, J = async (n, t) => {
|
|
59
|
+
const e = T.encode(n), r = await crypto.subtle.digest(t, e);
|
|
60
60
|
return new Uint8Array(r);
|
|
61
|
-
},
|
|
61
|
+
}, W = () => globalThis.process && typeof process.version < "u" && typeof process.versions.node < "u", z = (n) => encodeURIComponent(n).replace(
|
|
62
62
|
/[!'()*]/g,
|
|
63
63
|
(e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`
|
|
64
|
-
),
|
|
64
|
+
), G = (n) => {
|
|
65
65
|
if (n.includes("+"))
|
|
66
66
|
throw Error("An input string has '+'");
|
|
67
67
|
return decodeURIComponent(n);
|
|
68
|
-
},
|
|
68
|
+
}, H = (n, t) => Math.floor(Math.random() * (t - n) + n), g = (n, t) => {
|
|
69
69
|
t < 0n && (t *= -1n);
|
|
70
70
|
const e = n % t;
|
|
71
71
|
return e < 0n ? e + t : e;
|
|
72
|
-
},
|
|
72
|
+
}, I = (n, t = !1) => {
|
|
73
73
|
if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
|
|
74
74
|
if (n <= 0) throw Error("`length` must be positive");
|
|
75
75
|
const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
|
|
76
76
|
let s = Array.from(r, (i) => i.toString(2).padStart(8, "0")).join("").slice(0, n);
|
|
77
77
|
return t && (s = s.replace(/^./, "1")), BigInt("0b" + s);
|
|
78
|
-
},
|
|
78
|
+
}, U = (n, t) => {
|
|
79
79
|
if (n >= t) throw Error("rangeError");
|
|
80
80
|
const e = t - n, r = e.toString(2).length, s = (() => {
|
|
81
81
|
for (let o = 0; o < 1e5; o++) {
|
|
82
|
-
const c =
|
|
82
|
+
const c = I(r);
|
|
83
83
|
if (c >= p(2n, BigInt(r), e))
|
|
84
84
|
return c % e;
|
|
85
85
|
}
|
|
@@ -89,14 +89,14 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
89
89
|
}, p = (n, t, e) => {
|
|
90
90
|
if (e < 1n) throw Error("`mod` must be positive");
|
|
91
91
|
if (t < 0n) throw Error("`power` must not be negative");
|
|
92
|
-
if (n =
|
|
92
|
+
if (n = g(n, e), e === 1n) return 0n;
|
|
93
93
|
if (n % e === 1n || n % e === 0n) return n;
|
|
94
94
|
if (n === e - 1n) return t & 1n ? e - 1n : 1n;
|
|
95
95
|
let r = 1n;
|
|
96
96
|
for (; t > 0n; )
|
|
97
97
|
t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
|
|
98
98
|
return r;
|
|
99
|
-
},
|
|
99
|
+
}, P = (n, t) => {
|
|
100
100
|
if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
|
|
101
101
|
if (n === 0n)
|
|
102
102
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
@@ -120,7 +120,7 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
120
120
|
}
|
|
121
121
|
const s = n + r | 1n, i = y(n, s), o = y(s, t);
|
|
122
122
|
return i * o;
|
|
123
|
-
},
|
|
123
|
+
}, v = (n) => {
|
|
124
124
|
let t = 3n, e = 1n, r = 1n;
|
|
125
125
|
const s = BigInt(n.toString(2).length) - 1n;
|
|
126
126
|
for (let i = s - 1n; i > -1n; --i) {
|
|
@@ -128,12 +128,12 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
128
128
|
r *= y(t, o), t = o, e *= r;
|
|
129
129
|
}
|
|
130
130
|
return e;
|
|
131
|
-
},
|
|
131
|
+
}, Z = (n) => {
|
|
132
132
|
if (n < 0n) throw Error("'n' must be non-negative");
|
|
133
133
|
if (n === 0n) return 1n;
|
|
134
134
|
const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
|
|
135
|
-
return
|
|
136
|
-
},
|
|
135
|
+
return v(n) << t;
|
|
136
|
+
}, X = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)), x = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => {
|
|
137
137
|
if (t < 1n || t % 2n === 0n)
|
|
138
138
|
throw Error("`n` is invalid");
|
|
139
139
|
for (; n < 0n; )
|
|
@@ -149,7 +149,7 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
149
149
|
[n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
|
|
150
150
|
}
|
|
151
151
|
return t === 1n ? e : 0n;
|
|
152
|
-
},
|
|
152
|
+
}, M = (n) => {
|
|
153
153
|
if (n < 0n) return !1;
|
|
154
154
|
if (n === 0n) return !0;
|
|
155
155
|
let t = 1n, e = n;
|
|
@@ -158,8 +158,8 @@ const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
|
|
|
158
158
|
r ** 2n < n ? t = r : e = r;
|
|
159
159
|
}
|
|
160
160
|
return n === t ** 2n || n === (t + 1n) ** 2n;
|
|
161
|
-
}, S = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn],
|
|
162
|
-
class
|
|
161
|
+
}, S = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], V = 0x5851f42d4c957f2dn;
|
|
162
|
+
class A {
|
|
163
163
|
/**
|
|
164
164
|
* length = 2, `[state, increment]`
|
|
165
165
|
*/
|
|
@@ -168,7 +168,7 @@ class I {
|
|
|
168
168
|
return "PCGMinimal";
|
|
169
169
|
}
|
|
170
170
|
get [Symbol.toStringTag]() {
|
|
171
|
-
return
|
|
171
|
+
return A.name;
|
|
172
172
|
}
|
|
173
173
|
/** シード値の配列を返す */
|
|
174
174
|
static getSeed() {
|
|
@@ -182,14 +182,14 @@ class I {
|
|
|
182
182
|
}
|
|
183
183
|
/** 内部状態を1サイクル進める */
|
|
184
184
|
#n() {
|
|
185
|
-
this.#t[0] = this.#t[0] *
|
|
185
|
+
this.#t[0] = this.#t[0] * V + this.#t[1];
|
|
186
186
|
}
|
|
187
187
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
188
188
|
get #e() {
|
|
189
189
|
const t = this.#t[0];
|
|
190
190
|
if (!t) throw Error("empty state");
|
|
191
191
|
const e = t >> 59n, r = BigInt.asUintN(32, (t ^ t >> 18n) >> 27n);
|
|
192
|
-
return
|
|
192
|
+
return x(Number(r), Number(e));
|
|
193
193
|
}
|
|
194
194
|
/** 内部状態を1進め、乱数を返す \
|
|
195
195
|
* 普通はこれを使う
|
|
@@ -216,7 +216,7 @@ class I {
|
|
|
216
216
|
yield typeof e == "number" ? this.getBoundedRand(e) : this.getRand();
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
const
|
|
219
|
+
const C = (n) => {
|
|
220
220
|
if (n <= 1n) return !1;
|
|
221
221
|
if (n % 2n === 0n) return n === 2n;
|
|
222
222
|
let t = n - 1n, e = 0n;
|
|
@@ -230,19 +230,19 @@ const V = (n) => {
|
|
|
230
230
|
o = o * o % n;
|
|
231
231
|
}
|
|
232
232
|
return !1;
|
|
233
|
-
},
|
|
233
|
+
}, O = (n) => {
|
|
234
234
|
let t = 5n, e = w(t, n);
|
|
235
235
|
for (; e > 0n; ) {
|
|
236
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
236
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && M(n))
|
|
237
237
|
return [0n, 0n];
|
|
238
238
|
e = w(t, n);
|
|
239
239
|
}
|
|
240
240
|
return [t, e];
|
|
241
|
-
}, m = (n, t) => (n & 1n) === 1n ?
|
|
241
|
+
}, m = (n, t) => (n & 1n) === 1n ? g(n + t >> 1n, t) : g(n >> 1n, t), R = (n, t, e, r) => {
|
|
242
242
|
let s = 1n, i = e;
|
|
243
243
|
const o = n.toString(2).slice(1);
|
|
244
244
|
for (const c of o)
|
|
245
|
-
[s, i] = [
|
|
245
|
+
[s, i] = [g(s * i, t), m(i * i + r * s * s, t)], c === "1" && ([s, i] = [m(e * s + i, t), m(r * s + e * i, t)]);
|
|
246
246
|
return [s, i];
|
|
247
247
|
}, F = (n, t, e, r) => {
|
|
248
248
|
if (n % 2n !== 1n) throw Error("`n` must be odd");
|
|
@@ -255,7 +255,7 @@ const V = (n) => {
|
|
|
255
255
|
r = p(r, s, n);
|
|
256
256
|
for (let l = 0n; l < i; l++) {
|
|
257
257
|
if (u === 0n) return !0;
|
|
258
|
-
u =
|
|
258
|
+
u = g(u * u - 2n * r, n), r = p(r, 2n, n);
|
|
259
259
|
}
|
|
260
260
|
return !1;
|
|
261
261
|
}, B = (n) => {
|
|
@@ -292,25 +292,25 @@ const V = (n) => {
|
|
|
292
292
|
for (const i of t)
|
|
293
293
|
if (n % i === 0n)
|
|
294
294
|
return n === i;
|
|
295
|
-
if (!
|
|
295
|
+
if (!C(n))
|
|
296
296
|
return !1;
|
|
297
|
-
const [e, r] =
|
|
297
|
+
const [e, r] = O(n);
|
|
298
298
|
if (r === 0n) return !1;
|
|
299
299
|
const s = (1n - e) / 4n;
|
|
300
300
|
return F(n, e, 1n, s);
|
|
301
|
-
},
|
|
301
|
+
}, Y = (n, t) => {
|
|
302
302
|
if (t < 2n)
|
|
303
303
|
throw Error("noPrimesFound");
|
|
304
304
|
for (let r = 0; r < 1e5; r++) {
|
|
305
|
-
const s =
|
|
305
|
+
const s = U(n, t);
|
|
306
306
|
if (B(s)) return s;
|
|
307
307
|
}
|
|
308
308
|
throw Error("noPrimesFound");
|
|
309
|
-
},
|
|
309
|
+
}, Q = (n, t = !1) => {
|
|
310
310
|
if (n < 2)
|
|
311
311
|
throw Error("noPrimesFound");
|
|
312
312
|
for (let r = 0; r < 1e5; r++) {
|
|
313
|
-
const s =
|
|
313
|
+
const s = I(n, t);
|
|
314
314
|
if (B(s)) return s;
|
|
315
315
|
}
|
|
316
316
|
throw Error("noPrimesFound");
|
|
@@ -350,10 +350,10 @@ class f {
|
|
|
350
350
|
t = 1 / i;
|
|
351
351
|
let [o, c] = [1n, s], [u, l] = [0n, 1n];
|
|
352
352
|
for (; `${l}`.length < e + 1; ) {
|
|
353
|
-
const
|
|
354
|
-
if ([o, c] = [c,
|
|
353
|
+
const a = BigInt(Math.floor(t)), d = t - Number(a);
|
|
354
|
+
if ([o, c] = [c, a * c + o], [u, l] = [l, a * l + u], d === 0)
|
|
355
355
|
return new f(r ? -c : c, l);
|
|
356
|
-
t = 1 /
|
|
356
|
+
t = 1 / d;
|
|
357
357
|
}
|
|
358
358
|
return new f(r ? -o : o, u);
|
|
359
359
|
}
|
|
@@ -361,7 +361,7 @@ class f {
|
|
|
361
361
|
* reduction
|
|
362
362
|
*/
|
|
363
363
|
#e() {
|
|
364
|
-
const { gcd: t } =
|
|
364
|
+
const { gcd: t } = P(this.#t, this.#n);
|
|
365
365
|
t !== 0n && (this.#t /= t, this.#n /= t);
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
@@ -458,31 +458,31 @@ class f {
|
|
|
458
458
|
throw Error("cannot parse");
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
-
const
|
|
461
|
+
const tt = (n) => {
|
|
462
462
|
let t = n.toString(16);
|
|
463
463
|
t.length & 1 && (t = "0" + t);
|
|
464
464
|
const e = [...t.match(/.{2}/g) ?? []];
|
|
465
465
|
return Uint8Array.from(e, (r) => Number.parseInt(r, 16));
|
|
466
|
-
},
|
|
466
|
+
}, nt = (n) => {
|
|
467
467
|
const t = Array.from(n, (e) => e.toString(16).padStart(2, "0")).join("") || "00";
|
|
468
468
|
return BigInt("0x" + t);
|
|
469
|
-
},
|
|
469
|
+
}, _ = (n) => {
|
|
470
470
|
const t = Array.from(n, (e) => String.fromCharCode(e)).join("");
|
|
471
471
|
return btoa(t);
|
|
472
|
-
}, L = (n) => Uint8Array.from(atob(n), (t) => t.charCodeAt(0)),
|
|
472
|
+
}, L = (n) => Uint8Array.from(atob(n), (t) => t.charCodeAt(0)), et = (n) => _(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=*$/g, ""), rt = (n) => {
|
|
473
473
|
const t = n.length & 3;
|
|
474
474
|
t > 0 && (n = n + "=".repeat(4 - t));
|
|
475
475
|
const e = n.replaceAll("-", "+").replaceAll("_", "/");
|
|
476
476
|
return L(e);
|
|
477
|
-
}
|
|
478
|
-
class
|
|
477
|
+
};
|
|
478
|
+
class N {
|
|
479
479
|
#t;
|
|
480
480
|
#n = [];
|
|
481
481
|
static get name() {
|
|
482
482
|
return "Queue";
|
|
483
483
|
}
|
|
484
484
|
get [Symbol.toStringTag]() {
|
|
485
|
-
return
|
|
485
|
+
return N.name;
|
|
486
486
|
}
|
|
487
487
|
constructor(...t) {
|
|
488
488
|
this.#t = t;
|
|
@@ -508,13 +508,13 @@ class A {
|
|
|
508
508
|
return this.toArray().toString();
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
|
-
class
|
|
511
|
+
class E {
|
|
512
512
|
#t;
|
|
513
513
|
static get name() {
|
|
514
514
|
return "Executer";
|
|
515
515
|
}
|
|
516
516
|
get [Symbol.toStringTag]() {
|
|
517
|
-
return
|
|
517
|
+
return E.name;
|
|
518
518
|
}
|
|
519
519
|
constructor(t) {
|
|
520
520
|
this.#t = {
|
|
@@ -532,7 +532,7 @@ class N {
|
|
|
532
532
|
};
|
|
533
533
|
});
|
|
534
534
|
}
|
|
535
|
-
|
|
535
|
+
get() {
|
|
536
536
|
switch (this.#t.state) {
|
|
537
537
|
case "fulfilled":
|
|
538
538
|
return this.#t.data;
|
|
@@ -558,40 +558,61 @@ class N {
|
|
|
558
558
|
return e;
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
|
+
const b = "NamedError";
|
|
562
|
+
class st extends Error {
|
|
563
|
+
name;
|
|
564
|
+
static name = b;
|
|
565
|
+
[Symbol.toStringTag] = b;
|
|
566
|
+
constructor(t, e, r) {
|
|
567
|
+
super(e, { cause: r }), this.name = t;
|
|
568
|
+
}
|
|
569
|
+
toJSON() {
|
|
570
|
+
const t = (() => {
|
|
571
|
+
const i = this.cause;
|
|
572
|
+
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;
|
|
573
|
+
})(), { name: e, message: r, stack: s } = this;
|
|
574
|
+
return {
|
|
575
|
+
name: e,
|
|
576
|
+
message: r,
|
|
577
|
+
stack: s,
|
|
578
|
+
cause: t
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
561
582
|
export {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
583
|
+
tt as BItoU8Arr,
|
|
584
|
+
E as Executer,
|
|
585
|
+
st as NamedError,
|
|
586
|
+
A as PCGMinimal,
|
|
587
|
+
N as Queue,
|
|
567
588
|
f as Rational,
|
|
568
589
|
B as bailliePSW,
|
|
569
590
|
L as base64ToU8Arr,
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
591
|
+
rt as base64UrlToU8Arr,
|
|
592
|
+
G as decodeRFC3986URIComponent,
|
|
593
|
+
z as encodeRFC3986URIComponent,
|
|
594
|
+
P as exEuclidean,
|
|
595
|
+
Z as factorial,
|
|
596
|
+
J as getHash,
|
|
597
|
+
I as getRandBIByBitLength,
|
|
598
|
+
U as getRandBIByRange,
|
|
599
|
+
Q as getRandPrimeByBitLength,
|
|
600
|
+
Y as getRandPrimeByRange,
|
|
601
|
+
H as getRndInt,
|
|
602
|
+
h as isEqual,
|
|
603
|
+
W as isNode,
|
|
604
|
+
M as isSquare,
|
|
584
605
|
w as jacobiSymbol,
|
|
585
606
|
D as lazify,
|
|
586
607
|
p as modPow,
|
|
587
608
|
K as parseCSV,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
609
|
+
q as promiseWithResolvers,
|
|
610
|
+
g as residue,
|
|
611
|
+
x as rot32,
|
|
612
|
+
X as rot32BI,
|
|
613
|
+
$ as sameValueZero,
|
|
614
|
+
k as sleep,
|
|
615
|
+
nt as u8ArrToBI,
|
|
616
|
+
_ as u8ArrToBase64,
|
|
617
|
+
et as u8ArrToBase64Url
|
|
597
618
|
};
|
package/dist/executer.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export declare class Executer<T> {
|
|
|
13
13
|
static get name(): 'Executer';
|
|
14
14
|
get [Symbol.toStringTag](): "Executer";
|
|
15
15
|
constructor(promise: Promise<T>);
|
|
16
|
-
|
|
16
|
+
get(): T;
|
|
17
17
|
static boundary<TArg extends unknown[]>(func: (...args: TArg) => void): (...args: TArg) => void;
|
|
18
18
|
}
|
package/dist/main.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface NamedError<EName extends string> {
|
|
2
|
+
readonly stack?: string;
|
|
3
|
+
readonly message: string;
|
|
4
|
+
readonly cause?: unknown;
|
|
5
|
+
}
|
|
6
|
+
declare class NamedError<EName extends string> extends Error {
|
|
7
|
+
readonly name: EName;
|
|
8
|
+
static readonly name = "NamedError";
|
|
9
|
+
readonly [Symbol.toStringTag] = "NamedError";
|
|
10
|
+
constructor(name: EName, message: string, cause?: unknown);
|
|
11
|
+
toJSON(): {
|
|
12
|
+
name: EName;
|
|
13
|
+
message: string;
|
|
14
|
+
stack: string | undefined;
|
|
15
|
+
cause: string | number | boolean | object | undefined;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export { NamedError };
|
package/dist/util.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* compare two objects with SameValueZero method
|
|
3
|
+
* @param a
|
|
4
|
+
* @param b
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
1
7
|
declare const sameValueZero: (a: unknown, b: unknown) => boolean;
|
|
2
8
|
/**
|
|
3
9
|
* judges whether two objects has the same (nested) properties \
|
|
@@ -20,12 +26,12 @@ declare const promiseWithResolvers: <T>() => {
|
|
|
20
26
|
*/
|
|
21
27
|
declare const sleep: (delay: number) => Promise<void>;
|
|
22
28
|
/**
|
|
23
|
-
* makes a function
|
|
29
|
+
* makes a function lazy
|
|
24
30
|
*/
|
|
25
31
|
declare const lazify: <ArgT extends unknown[], RetT>(func: (...args: ArgT) => RetT) => (...args: ArgT) => () => RetT;
|
|
26
32
|
/**
|
|
27
33
|
* parses CSV string \
|
|
28
|
-
*
|
|
34
|
+
* able to deal with CSV with escaping doublequote
|
|
29
35
|
* @param csv CSV
|
|
30
36
|
* @returns 2次元配列
|
|
31
37
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"author": "Tessyrrhaqt",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
|
-
},
|
|
14
11
|
"main": "./dist/bundle.js",
|
|
15
12
|
"types": "./dist/main.d.ts",
|
|
16
13
|
"exports": {
|
|
@@ -18,30 +15,29 @@
|
|
|
18
15
|
"import": "./dist/bundle.js"
|
|
19
16
|
},
|
|
20
17
|
"engines": {
|
|
21
|
-
"node": "^22
|
|
18
|
+
"node": "^22",
|
|
19
|
+
"pnpm": "^10"
|
|
22
20
|
},
|
|
23
21
|
"repository": {
|
|
24
22
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/tktb-tess/util-fns"
|
|
23
|
+
"url": "https://github.com/tktb-tess/util-fns.git"
|
|
26
24
|
},
|
|
27
25
|
"homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
|
|
28
|
-
"scripts": {
|
|
29
|
-
"dev": "vite",
|
|
30
|
-
"build": "tsc && vite build",
|
|
31
|
-
"test": "vitest run",
|
|
32
|
-
"typecheck": "tsc --noEmit"
|
|
33
|
-
},
|
|
34
26
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^24.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"typescript": "^5.9.2",
|
|
40
|
-
"vite": "^7.1.3",
|
|
27
|
+
"@types/node": "^24.6.2",
|
|
28
|
+
"tsx": "^4.20.6",
|
|
29
|
+
"typescript": "^5.9.3",
|
|
30
|
+
"vite": "^7.1.9",
|
|
41
31
|
"vite-plugin-dts": "^4.5.4",
|
|
42
32
|
"vitest": "^3.2.4"
|
|
43
33
|
},
|
|
44
34
|
"volta": {
|
|
45
35
|
"node": "22.19.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "vite",
|
|
39
|
+
"build": "tsc && vite build",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"typecheck": "tsc --noEmit"
|
|
46
42
|
}
|
|
47
|
-
}
|
|
43
|
+
}
|