@tktb-tess/util-fns 0.3.0 → 0.3.2
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/brand.d.ts +7 -0
- package/dist/bundle.d.ts +8 -8
- package/dist/bundle.js +180 -158
- package/dist/bundle.umd.cjs +2 -2
- package/dist/fraction.d.ts +2 -4
- package/dist/math.d.ts +0 -6
- package/dist/pcg-minimal.d.ts +0 -7
- package/dist/util.d.ts +18 -10
- package/package.json +2 -1
package/dist/brand.d.ts
ADDED
package/dist/bundle.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getRndInt, residue,
|
|
1
|
+
import { isEqual, sleep, lazify, parseCSV, getHash, toBigInt, isNode } from './util';
|
|
2
|
+
import { getRndInt, residue, getRandBIByBitLength, getRandBIByRange, modPow, exEuclidean, factorial, rot32, rot32BI, jacobiSymbol, isSquare } from './math';
|
|
3
3
|
import { default as PCGMinimal } from './pcg-minimal';
|
|
4
4
|
import { bailliePSW, getRandPrimeByBitLength, getRandPrimeByRange } from './baillie-psw';
|
|
5
5
|
import { default as Fraction } from './fraction';
|
|
6
6
|
import { base64ToU8Arr, base64UrlToU8Arr, u8ArrToBase64, u8ArrToBase64Url, BItoU8Arr, u8ArrToBI } from './u8arr-ext';
|
|
7
|
+
import { Brand } from './brand';
|
|
7
8
|
declare const Util: {
|
|
8
|
-
|
|
9
|
+
isEqual: (a: unknown, b: unknown) => boolean;
|
|
9
10
|
sleep: (delay: number) => Promise<void>;
|
|
10
11
|
lazify: <ArgT extends unknown[], RetT>(func: (...args: ArgT) => RetT) => (...args: ArgT) => () => RetT;
|
|
11
12
|
parseCSV: (csv: string) => string[][];
|
|
12
13
|
getHash: (str: string, algorithm: AlgorithmIdentifier) => Promise<Uint8Array<ArrayBuffer>>;
|
|
14
|
+
isNode: () => boolean;
|
|
15
|
+
toBigInt: (...nums: number[]) => bigint[];
|
|
13
16
|
};
|
|
14
|
-
declare const
|
|
17
|
+
declare const Calc: {
|
|
15
18
|
getRndInt: (min: number, max: number) => number;
|
|
16
19
|
residue: (n: bigint, mod: bigint) => bigint;
|
|
17
|
-
toBigInt: (...nums: number[]) => bigint[];
|
|
18
20
|
getRandBIByBitLength: (length: number, fixed?: boolean) => bigint;
|
|
19
21
|
getRandBIByRange: (min: bigint, max: bigint) => bigint;
|
|
20
22
|
modPow: (base: bigint, power: bigint, mod: bigint) => bigint;
|
|
@@ -28,8 +30,6 @@ declare const AdMath: {
|
|
|
28
30
|
rot32BI: (value: bigint, rot: bigint) => bigint;
|
|
29
31
|
jacobiSymbol: (a: bigint, n: bigint) => bigint;
|
|
30
32
|
isSquare: (n: bigint) => boolean;
|
|
31
|
-
};
|
|
32
|
-
declare const Prime: {
|
|
33
33
|
bailliePSW: (n: bigint) => boolean;
|
|
34
34
|
getRandPrimeByBitLength: (bitLength: number, fixed?: boolean) => bigint;
|
|
35
35
|
getRandPrimeByRange: (min: bigint, max: bigint) => bigint;
|
|
@@ -42,4 +42,4 @@ declare const U8Ext: {
|
|
|
42
42
|
BItoU8Arr: (n: bigint) => Uint8Array<ArrayBuffer>;
|
|
43
43
|
u8ArrToBI: (buf: Uint8Array) => bigint;
|
|
44
44
|
};
|
|
45
|
-
export {
|
|
45
|
+
export { isEqual, sleep, lazify, parseCSV, getHash, getRndInt, residue, toBigInt, isNode, getRandBIByBitLength, getRandBIByRange, modPow, exEuclidean, factorial, rot32, rot32BI, jacobiSymbol, isSquare, bailliePSW, getRandPrimeByBitLength, getRandPrimeByRange, base64ToU8Arr, base64UrlToU8Arr, u8ArrToBase64, u8ArrToBase64Url, BItoU8Arr, u8ArrToBI, PCGMinimal, Fraction, Util, Calc, U8Ext, type Brand, };
|
package/dist/bundle.js
CHANGED
|
@@ -1,45 +1,69 @@
|
|
|
1
|
-
const R = new TextEncoder(),
|
|
2
|
-
if (n
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const R = new TextEncoder(), p = (n, t) => {
|
|
2
|
+
if (typeof n != typeof t) return !1;
|
|
3
|
+
const r = Object.prototype.toString.call(n), e = Object.prototype.toString.call(t);
|
|
4
|
+
if (r !== e) return !1;
|
|
5
|
+
if (typeof n == "string" || typeof n == "bigint" || typeof n == "boolean" || typeof n == "symbol" || typeof n > "u")
|
|
6
|
+
return n === t;
|
|
7
|
+
if (typeof n == "number")
|
|
8
|
+
return Number.isNaN(n) && Number.isNaN(t) || n === t;
|
|
9
|
+
if (n === null) return n === t;
|
|
10
|
+
if (typeof n == "function")
|
|
11
|
+
throw Error("comparing these objects is still unavailable");
|
|
12
|
+
if (Array.isArray(n) && Array.isArray(t)) {
|
|
13
|
+
if (n.length !== t.length) return !1;
|
|
14
|
+
for (let i = 0; i < n.length; i++)
|
|
15
|
+
if (!p(n[i], t[i])) return !1;
|
|
16
|
+
return !0;
|
|
17
|
+
}
|
|
18
|
+
if (r === "[object Object]") {
|
|
19
|
+
const i = n, s = t, o = Object.getOwnPropertyNames(n), c = Object.getOwnPropertyNames(t);
|
|
20
|
+
o.push(...Object.getOwnPropertySymbols(n)), c.push(...Object.getOwnPropertySymbols(t));
|
|
21
|
+
for (const l of o) {
|
|
22
|
+
const u = c.find((O) => O === l);
|
|
23
|
+
if (u === void 0) return !1;
|
|
24
|
+
const [h, d] = [i[l], s[u]];
|
|
25
|
+
if (!p(h, d)) return !1;
|
|
26
|
+
}
|
|
27
|
+
return !0;
|
|
28
|
+
}
|
|
29
|
+
throw Error("comparing these objects is still unavailable");
|
|
30
|
+
}, x = (n) => new Promise((t) => {
|
|
7
31
|
setTimeout(() => {
|
|
8
32
|
t();
|
|
9
33
|
}, n);
|
|
10
34
|
}), M = (n) => (...t) => () => n(...t), T = (n) => {
|
|
11
35
|
const t = [];
|
|
12
|
-
let r = [], e = "",
|
|
13
|
-
for (let
|
|
14
|
-
const o = n[
|
|
15
|
-
o === '"' && (
|
|
16
|
-
` && !
|
|
36
|
+
let r = [], e = "", i = !1;
|
|
37
|
+
for (let s = 0; s < n.length; s++) {
|
|
38
|
+
const o = n[s];
|
|
39
|
+
o === '"' && (s === 0 || n[s - 1] !== "\\") ? i = !i : o === "," && !i ? (r.push(e.trim()), e = "") : o === `
|
|
40
|
+
` && !i ? (r.push(e.trim()), t.push(r), r = [], e = "") : e += o;
|
|
17
41
|
}
|
|
18
42
|
return r.push(e.trim()), t.push(r), t;
|
|
19
|
-
},
|
|
43
|
+
}, _ = async (n, t) => {
|
|
20
44
|
const r = R.encode(n), e = await crypto.subtle.digest(t, r);
|
|
21
45
|
return new Uint8Array(e);
|
|
22
|
-
},
|
|
46
|
+
}, L = (...n) => n.map((t) => BigInt(t)), b = () => typeof globalThis.process < "u" && typeof globalThis.require < "u", V = (n, t) => Math.floor(Math.random() * (t - n) + n), a = (n, t) => {
|
|
23
47
|
const r = n % t;
|
|
24
48
|
return r < 0n ? r + t : r;
|
|
25
|
-
},
|
|
49
|
+
}, B = (n, t = !1) => {
|
|
26
50
|
if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
|
|
27
51
|
if (n <= 0) throw Error("`length` must be positive");
|
|
28
52
|
const r = Math.ceil(n / 8), e = crypto.getRandomValues(new Uint8Array(r));
|
|
29
|
-
let
|
|
30
|
-
return t && (
|
|
53
|
+
let i = Array.from(e, (s) => s.toString(2).padStart(8, "0")).join("").slice(0, n);
|
|
54
|
+
return t && (i = i.replace(/^./, "1")), BigInt("0b" + i);
|
|
31
55
|
}, S = (n, t) => {
|
|
32
56
|
if (n >= t) throw Error("rangeError");
|
|
33
|
-
const r = t - n, e = r.toString(2).length,
|
|
57
|
+
const r = t - n, e = r.toString(2).length, i = (() => {
|
|
34
58
|
for (let o = 0; o < 1e5; o++) {
|
|
35
|
-
const c =
|
|
36
|
-
if (c >=
|
|
59
|
+
const c = B(e);
|
|
60
|
+
if (c >= g(2n, BigInt(e), r))
|
|
37
61
|
return c % r;
|
|
38
62
|
}
|
|
39
63
|
throw Error("Failed to generate a random bigint");
|
|
40
64
|
})();
|
|
41
|
-
return n +
|
|
42
|
-
},
|
|
65
|
+
return n + i;
|
|
66
|
+
}, g = (n, t, r) => {
|
|
43
67
|
if (r < 1n) throw Error("`mod` must be positive");
|
|
44
68
|
if (t < 0n) throw Error("`power` must not be negative");
|
|
45
69
|
for (; n < 0n; ) n += r;
|
|
@@ -56,29 +80,29 @@ const R = new TextEncoder(), x = (n, t) => {
|
|
|
56
80
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
57
81
|
if (t === 0n)
|
|
58
82
|
return n > 0n ? { x: 1n, y: 0n, gcd: n } : { x: -1n, y: 0n, gcd: -n };
|
|
59
|
-
let [r, e,
|
|
83
|
+
let [r, e, i] = [1n, 0n, n], [s, o, c] = [0n, -1n, t];
|
|
60
84
|
for (; ; ) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
[r,
|
|
85
|
+
const l = i / c, u = i - l * c;
|
|
86
|
+
if (u === 0n) break;
|
|
87
|
+
[r, s] = [s, r - l * s], [e, o] = [o, e - l * o], [i, c] = [c, u];
|
|
64
88
|
}
|
|
65
|
-
return c < 0n && (
|
|
89
|
+
return c < 0n && (s *= -1n, o *= -1n, c *= -1n), { x: s, y: o, gcd: c };
|
|
66
90
|
}, m = (n, t) => {
|
|
67
91
|
if (n >= t) return 1n;
|
|
68
92
|
const r = BigInt((t - 2n).toString(2).length), e = (t - n) / 2n;
|
|
69
93
|
if (r * e < 63n) {
|
|
70
94
|
let c = n;
|
|
71
|
-
for (let
|
|
72
|
-
c *=
|
|
95
|
+
for (let l = n + 2n; l < t; l += 2n)
|
|
96
|
+
c *= l;
|
|
73
97
|
return c;
|
|
74
98
|
}
|
|
75
|
-
const
|
|
76
|
-
return
|
|
99
|
+
const i = n + e | 1n, s = m(n, i), o = m(i, t);
|
|
100
|
+
return s * o;
|
|
77
101
|
}, C = (n) => {
|
|
78
102
|
let t = 3n, r = 1n, e = 1n;
|
|
79
|
-
const
|
|
80
|
-
for (let
|
|
81
|
-
const o = (n >>
|
|
103
|
+
const i = BigInt(n.toString(2).length) - 1n;
|
|
104
|
+
for (let s = i - 1n; s > -1n; --s) {
|
|
105
|
+
const o = (n >> s) + 1n | 1n;
|
|
82
106
|
e *= m(t, o), t = o, r *= e;
|
|
83
107
|
}
|
|
84
108
|
return r;
|
|
@@ -87,7 +111,7 @@ const R = new TextEncoder(), x = (n, t) => {
|
|
|
87
111
|
if (n === 0n) return 1n;
|
|
88
112
|
const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
|
|
89
113
|
return C(n) << t;
|
|
90
|
-
}, D = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)), E = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0,
|
|
114
|
+
}, D = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)), E = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => {
|
|
91
115
|
if (t < 1n || t % 2n === 0n)
|
|
92
116
|
throw Error("`n` is invalid");
|
|
93
117
|
for (; n < 0n; )
|
|
@@ -103,7 +127,7 @@ const R = new TextEncoder(), x = (n, t) => {
|
|
|
103
127
|
[n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (r *= -1n), n %= t;
|
|
104
128
|
}
|
|
105
129
|
return t === 1n ? r : 0n;
|
|
106
|
-
},
|
|
130
|
+
}, P = (n) => {
|
|
107
131
|
if (n < 0n) return !1;
|
|
108
132
|
if (n === 0n) return !0;
|
|
109
133
|
let t = 1n, r = n;
|
|
@@ -112,13 +136,12 @@ const R = new TextEncoder(), x = (n, t) => {
|
|
|
112
136
|
e ** 2n < n ? t = e : r = e;
|
|
113
137
|
}
|
|
114
138
|
return n === t ** 2n || n === (t + 1n) ** 2n;
|
|
115
|
-
},
|
|
116
|
-
class
|
|
139
|
+
}, N = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], $ = 0x5851f42d4c957f2dn;
|
|
140
|
+
class Z {
|
|
117
141
|
/**
|
|
118
142
|
* length = 2, `[state, increment]`
|
|
119
143
|
*/
|
|
120
144
|
#t = new BigUint64Array(2);
|
|
121
|
-
[O];
|
|
122
145
|
/** シード値の配列を返す */
|
|
123
146
|
static getSeed() {
|
|
124
147
|
return crypto.getRandomValues(new BigUint64Array(2));
|
|
@@ -127,14 +150,14 @@ class F {
|
|
|
127
150
|
* @param seeds 64bit整数の配列 (長さ2以上), 省略した場合, 常に同じ値によって初期化される
|
|
128
151
|
*/
|
|
129
152
|
constructor(t) {
|
|
130
|
-
t ? (this.#t[1] = t[1] << 1n | 1n, this
|
|
153
|
+
t ? (this.#t[1] = t[1] << 1n | 1n, this.#n(), this.#t[0] = t[0], this.#n()) : (this.#t[0] = N[0], this.#t[1] = N[1]);
|
|
131
154
|
}
|
|
132
155
|
/** 内部状態を1サイクル進める */
|
|
133
|
-
|
|
156
|
+
#n() {
|
|
134
157
|
this.#t[0] = this.#t[0] * $ + this.#t[1];
|
|
135
158
|
}
|
|
136
159
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
137
|
-
get
|
|
160
|
+
get #r() {
|
|
138
161
|
const t = this.#t[0];
|
|
139
162
|
if (!t) throw Error("empty state");
|
|
140
163
|
const r = t >> 59n, e = BigInt.asUintN(32, (t ^ t >> 18n) >> 27n);
|
|
@@ -144,15 +167,15 @@ class F {
|
|
|
144
167
|
* 普通はこれを使う
|
|
145
168
|
*/
|
|
146
169
|
getRand() {
|
|
147
|
-
return this
|
|
170
|
+
return this.#n(), this.#r;
|
|
148
171
|
}
|
|
149
172
|
/** `bound` 未満の乱数を返す */
|
|
150
173
|
getBoundedRand(t) {
|
|
151
174
|
if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
|
|
152
175
|
const e = 4294967296 % t;
|
|
153
176
|
for (; ; ) {
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
177
|
+
const i = this.getRand();
|
|
178
|
+
if (i >= e) return i % t;
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
/**
|
|
@@ -165,49 +188,49 @@ class F {
|
|
|
165
188
|
yield typeof r == "number" ? this.getBoundedRand(r) : this.getRand();
|
|
166
189
|
}
|
|
167
190
|
}
|
|
168
|
-
const
|
|
191
|
+
const K = (n) => {
|
|
169
192
|
if (n <= 1n) return !1;
|
|
170
193
|
if (n % 2n === 0n) return n === 2n;
|
|
171
194
|
let t = n - 1n, r = 0n;
|
|
172
195
|
for (; t % 2n === 0n; )
|
|
173
196
|
t >>= 1n, r += 1n;
|
|
174
|
-
const [e,
|
|
175
|
-
let o =
|
|
197
|
+
const [e, i] = [t, r];
|
|
198
|
+
let o = g(2n, e, n);
|
|
176
199
|
if (o === 1n) return !0;
|
|
177
|
-
for (let c = 0n; c <
|
|
200
|
+
for (let c = 0n; c < i; c++) {
|
|
178
201
|
if (o === n - 1n) return !0;
|
|
179
202
|
o = o * o % n;
|
|
180
203
|
}
|
|
181
204
|
return !1;
|
|
182
|
-
},
|
|
183
|
-
let t = 5n, r =
|
|
205
|
+
}, v = (n) => {
|
|
206
|
+
let t = 5n, r = w(t, n);
|
|
184
207
|
for (; r > 0n; ) {
|
|
185
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
208
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && P(n))
|
|
186
209
|
return [0n, 0n];
|
|
187
|
-
r =
|
|
210
|
+
r = w(t, n);
|
|
188
211
|
}
|
|
189
212
|
return [t, r];
|
|
190
|
-
},
|
|
191
|
-
let
|
|
213
|
+
}, y = (n, t) => (n & 1n) === 1n ? a(n + t >> 1n, t) : a(n >> 1n, t), J = (n, t, r, e) => {
|
|
214
|
+
let i = 1n, s = r;
|
|
192
215
|
const o = n.toString(2).slice(1);
|
|
193
216
|
for (const c of o)
|
|
194
|
-
[
|
|
195
|
-
return [
|
|
196
|
-
},
|
|
217
|
+
[i, s] = [a(i * s, t), y(s * s + e * i * i, t)], c === "1" && ([i, s] = [y(r * i + s, t), y(e * i + r * s, t)]);
|
|
218
|
+
return [i, s];
|
|
219
|
+
}, k = (n, t, r, e) => {
|
|
197
220
|
if (n % 2n !== 1n) throw Error("`n` must be odd");
|
|
198
|
-
let
|
|
199
|
-
for (;
|
|
200
|
-
|
|
201
|
-
const [o, c] =
|
|
202
|
-
let
|
|
221
|
+
let i = n + 1n, s = 0n;
|
|
222
|
+
for (; i % 2n === 0n; )
|
|
223
|
+
i >>= 1n, s += 1n;
|
|
224
|
+
const [o, c] = J(i, n, r, t);
|
|
225
|
+
let l = c;
|
|
203
226
|
if (o === 0n) return !0;
|
|
204
|
-
e =
|
|
205
|
-
for (let
|
|
206
|
-
if (
|
|
207
|
-
|
|
227
|
+
e = g(e, i, n);
|
|
228
|
+
for (let u = 0n; u < s; u++) {
|
|
229
|
+
if (l === 0n) return !0;
|
|
230
|
+
l = a(l * l - 2n * e, n), e = g(e, 2n, n);
|
|
208
231
|
}
|
|
209
232
|
return !1;
|
|
210
|
-
},
|
|
233
|
+
}, I = (n) => {
|
|
211
234
|
if (n <= 1n) return !1;
|
|
212
235
|
if (n % 2n === 0n) return n === 2n;
|
|
213
236
|
const t = [
|
|
@@ -238,36 +261,35 @@ const v = (n) => {
|
|
|
238
261
|
97n,
|
|
239
262
|
101n
|
|
240
263
|
];
|
|
241
|
-
for (const
|
|
242
|
-
if (n %
|
|
243
|
-
return n ===
|
|
244
|
-
if (!
|
|
264
|
+
for (const s of t)
|
|
265
|
+
if (n % s === 0n)
|
|
266
|
+
return n === s;
|
|
267
|
+
if (!K(n))
|
|
245
268
|
return !1;
|
|
246
|
-
const [r, e] =
|
|
269
|
+
const [r, e] = v(n);
|
|
247
270
|
if (e === 0n) return !1;
|
|
248
|
-
const
|
|
249
|
-
return
|
|
250
|
-
},
|
|
271
|
+
const i = (1n - r) / 4n;
|
|
272
|
+
return k(n, r, 1n, i);
|
|
273
|
+
}, z = (n, t) => {
|
|
251
274
|
if (t < 2n)
|
|
252
275
|
throw Error("noPrimesFound");
|
|
253
276
|
for (let e = 0; e < 1e5; e++) {
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
277
|
+
const i = S(n, t);
|
|
278
|
+
if (I(i)) return i;
|
|
256
279
|
}
|
|
257
280
|
throw Error("noPrimesFound");
|
|
258
|
-
},
|
|
281
|
+
}, G = (n, t = !1) => {
|
|
259
282
|
if (n < 2)
|
|
260
283
|
throw Error("noPrimesFound");
|
|
261
284
|
for (let e = 0; e < 1e5; e++) {
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
285
|
+
const i = B(n, t);
|
|
286
|
+
if (I(i)) return i;
|
|
264
287
|
}
|
|
265
288
|
throw Error("noPrimesFound");
|
|
266
|
-
}
|
|
267
|
-
class
|
|
289
|
+
};
|
|
290
|
+
class f {
|
|
268
291
|
#t;
|
|
269
292
|
#n;
|
|
270
|
-
[W];
|
|
271
293
|
/**
|
|
272
294
|
*
|
|
273
295
|
* @param numerator
|
|
@@ -283,23 +305,23 @@ class l {
|
|
|
283
305
|
*/
|
|
284
306
|
static fromDecimal(t, r = 20) {
|
|
285
307
|
if (Number.isNaN(t))
|
|
286
|
-
return new
|
|
308
|
+
return new f(0n, 0n);
|
|
287
309
|
if (Math.abs(t) === 1 / 0)
|
|
288
|
-
return new
|
|
310
|
+
return new f(t > 0 ? 1n : -1n, 0n);
|
|
289
311
|
const e = t < 0;
|
|
290
312
|
e && (t *= -1);
|
|
291
|
-
const
|
|
292
|
-
if (
|
|
293
|
-
return new
|
|
294
|
-
t = 1 /
|
|
295
|
-
let [o, c] = [1n,
|
|
296
|
-
for (; `${
|
|
297
|
-
const
|
|
298
|
-
if ([o, c] = [c,
|
|
299
|
-
return new
|
|
300
|
-
t = 1 /
|
|
313
|
+
const i = BigInt(Math.floor(t)), s = t - Number(i);
|
|
314
|
+
if (s === 0)
|
|
315
|
+
return new f(e ? -i : i, 1n);
|
|
316
|
+
t = 1 / s;
|
|
317
|
+
let [o, c] = [1n, i], [l, u] = [0n, 1n];
|
|
318
|
+
for (; `${u}`.length < r + 1; ) {
|
|
319
|
+
const h = BigInt(Math.floor(t)), d = t - Number(h);
|
|
320
|
+
if ([o, c] = [c, h * c + o], [l, u] = [u, h * u + l], d === 0)
|
|
321
|
+
return new f(e ? -c : c, u);
|
|
322
|
+
t = 1 / d;
|
|
301
323
|
}
|
|
302
|
-
return new
|
|
324
|
+
return new f(e ? -o : o, l);
|
|
303
325
|
}
|
|
304
326
|
/**
|
|
305
327
|
* reduction
|
|
@@ -313,14 +335,14 @@ class l {
|
|
|
313
335
|
* @returns
|
|
314
336
|
*/
|
|
315
337
|
minus() {
|
|
316
|
-
return new
|
|
338
|
+
return new f(-this.#t, this.#n);
|
|
317
339
|
}
|
|
318
340
|
/**
|
|
319
341
|
* returns inverse of this fraction
|
|
320
342
|
* @returns
|
|
321
343
|
*/
|
|
322
344
|
inverse() {
|
|
323
|
-
return new
|
|
345
|
+
return new f(this.#n, this.#t);
|
|
324
346
|
}
|
|
325
347
|
/**
|
|
326
348
|
* returns `this + right`
|
|
@@ -329,7 +351,7 @@ class l {
|
|
|
329
351
|
*/
|
|
330
352
|
add(t) {
|
|
331
353
|
const r = this.#n * t.#n, e = this.#t * t.#n + t.#t * this.#n;
|
|
332
|
-
return new
|
|
354
|
+
return new f(e, r);
|
|
333
355
|
}
|
|
334
356
|
/**
|
|
335
357
|
* returns `this - right`
|
|
@@ -337,7 +359,7 @@ class l {
|
|
|
337
359
|
* @returns
|
|
338
360
|
*/
|
|
339
361
|
substr(t) {
|
|
340
|
-
return new
|
|
362
|
+
return new f(this.#t, this.#n).add(t.minus());
|
|
341
363
|
}
|
|
342
364
|
/**
|
|
343
365
|
* returns `this * right`
|
|
@@ -346,7 +368,7 @@ class l {
|
|
|
346
368
|
*/
|
|
347
369
|
multiply(t) {
|
|
348
370
|
const r = this.#n * t.#n, e = this.#t * t.#t;
|
|
349
|
-
return new
|
|
371
|
+
return new f(e, r);
|
|
350
372
|
}
|
|
351
373
|
/**
|
|
352
374
|
* returns `this / right`
|
|
@@ -354,7 +376,7 @@ class l {
|
|
|
354
376
|
* @returns
|
|
355
377
|
*/
|
|
356
378
|
divide(t) {
|
|
357
|
-
return new
|
|
379
|
+
return new f(this.#t, this.#n).multiply(
|
|
358
380
|
t.inverse()
|
|
359
381
|
);
|
|
360
382
|
}
|
|
@@ -365,7 +387,7 @@ class l {
|
|
|
365
387
|
*/
|
|
366
388
|
mediant(t) {
|
|
367
389
|
const r = this.#n + t.#n, e = this.#t + t.#t;
|
|
368
|
-
return new
|
|
390
|
+
return new f(e, r);
|
|
369
391
|
}
|
|
370
392
|
/**
|
|
371
393
|
* `number` 型の小数に変換
|
|
@@ -392,103 +414,103 @@ class l {
|
|
|
392
414
|
};
|
|
393
415
|
}
|
|
394
416
|
static parse(t) {
|
|
395
|
-
const r = JSON.parse(t), { type: e, numerator:
|
|
417
|
+
const r = JSON.parse(t), { type: e, numerator: i, denominator: s } = r;
|
|
396
418
|
if (e !== "Fraction") throw Error("cannot parse");
|
|
397
|
-
if (typeof
|
|
398
|
-
const o = BigInt(
|
|
399
|
-
return new
|
|
419
|
+
if (typeof i == "string" && typeof s == "string") {
|
|
420
|
+
const o = BigInt(i), c = BigInt(s);
|
|
421
|
+
return new f(o, c);
|
|
400
422
|
} else
|
|
401
423
|
throw Error("cannot parse");
|
|
402
424
|
}
|
|
403
425
|
}
|
|
404
|
-
const
|
|
426
|
+
const H = (n) => {
|
|
405
427
|
let t = n.toString(16);
|
|
406
428
|
t.length & 1 && (t = "0" + t);
|
|
407
429
|
const r = [...t.match(/.{2}/g) ?? []];
|
|
408
430
|
return Uint8Array.from(r, (e) => Number.parseInt(e, 16));
|
|
409
|
-
},
|
|
431
|
+
}, W = (n) => {
|
|
410
432
|
const t = Array.from(n, (r) => r.toString(16).padStart(2, "0")).join("") || "00";
|
|
411
433
|
return BigInt("0x" + t);
|
|
412
434
|
}, U = (n) => {
|
|
413
|
-
if (
|
|
435
|
+
if (b())
|
|
414
436
|
return Buffer.copyBytesFrom(n).toString("base64");
|
|
415
437
|
{
|
|
416
438
|
const t = Array.from(n, (r) => String.fromCharCode(r)).join("");
|
|
417
439
|
return btoa(t);
|
|
418
440
|
}
|
|
419
|
-
},
|
|
420
|
-
if (
|
|
441
|
+
}, j = (n) => {
|
|
442
|
+
if (b()) {
|
|
421
443
|
const t = Buffer.from(n, "base64");
|
|
422
444
|
return new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
|
|
423
445
|
} else
|
|
424
446
|
return Uint8Array.from(atob(n), (t) => t.charCodeAt(0));
|
|
425
|
-
},
|
|
447
|
+
}, X = (n) => U(n).replaceAll(/\+/g, "-").replaceAll(/\//g, "_").replaceAll(/=*$/g, ""), Y = (n) => {
|
|
426
448
|
const t = n.length & 3;
|
|
427
449
|
t > 0 && (n = n + "=".repeat(4 - t));
|
|
428
450
|
const r = n.replaceAll(/-/g, "+").replaceAll(/_/g, "/");
|
|
429
|
-
return
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
sleep:
|
|
451
|
+
return j(r);
|
|
452
|
+
}, F = {
|
|
453
|
+
isEqual: p,
|
|
454
|
+
sleep: x,
|
|
433
455
|
lazify: M,
|
|
434
456
|
parseCSV: T,
|
|
435
|
-
getHash:
|
|
436
|
-
|
|
457
|
+
getHash: _,
|
|
458
|
+
isNode: b,
|
|
459
|
+
toBigInt: L
|
|
460
|
+
}, Q = {
|
|
437
461
|
getRndInt: V,
|
|
438
|
-
residue:
|
|
439
|
-
|
|
440
|
-
getRandBIByBitLength: w,
|
|
462
|
+
residue: a,
|
|
463
|
+
getRandBIByBitLength: B,
|
|
441
464
|
getRandBIByRange: S,
|
|
442
|
-
modPow:
|
|
465
|
+
modPow: g,
|
|
443
466
|
exEuclidean: A,
|
|
444
467
|
factorial: q,
|
|
445
468
|
rot32: E,
|
|
446
469
|
rot32BI: D,
|
|
447
|
-
jacobiSymbol:
|
|
448
|
-
isSquare:
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
base64UrlToU8Arr: Z,
|
|
470
|
+
jacobiSymbol: w,
|
|
471
|
+
isSquare: P,
|
|
472
|
+
bailliePSW: I,
|
|
473
|
+
getRandPrimeByBitLength: G,
|
|
474
|
+
getRandPrimeByRange: z
|
|
475
|
+
}, tt = {
|
|
476
|
+
base64ToU8Arr: j,
|
|
477
|
+
base64UrlToU8Arr: Y,
|
|
456
478
|
u8ArrToBase64: U,
|
|
457
|
-
u8ArrToBase64Url:
|
|
458
|
-
BItoU8Arr:
|
|
459
|
-
u8ArrToBI:
|
|
479
|
+
u8ArrToBase64Url: X,
|
|
480
|
+
BItoU8Arr: H,
|
|
481
|
+
u8ArrToBI: W
|
|
460
482
|
};
|
|
461
483
|
export {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
Z as base64UrlToU8Arr,
|
|
484
|
+
H as BItoU8Arr,
|
|
485
|
+
Q as Calc,
|
|
486
|
+
f as Fraction,
|
|
487
|
+
Z as PCGMinimal,
|
|
488
|
+
tt as U8Ext,
|
|
489
|
+
F as Util,
|
|
490
|
+
I as bailliePSW,
|
|
491
|
+
j as base64ToU8Arr,
|
|
492
|
+
Y as base64UrlToU8Arr,
|
|
472
493
|
A as exEuclidean,
|
|
473
494
|
q as factorial,
|
|
474
|
-
|
|
475
|
-
|
|
495
|
+
_ as getHash,
|
|
496
|
+
B as getRandBIByBitLength,
|
|
476
497
|
S as getRandBIByRange,
|
|
477
|
-
|
|
478
|
-
|
|
498
|
+
G as getRandPrimeByBitLength,
|
|
499
|
+
z as getRandPrimeByRange,
|
|
479
500
|
V as getRndInt,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
501
|
+
p as isEqual,
|
|
502
|
+
b as isNode,
|
|
503
|
+
P as isSquare,
|
|
504
|
+
w as jacobiSymbol,
|
|
483
505
|
M as lazify,
|
|
484
|
-
|
|
506
|
+
g as modPow,
|
|
485
507
|
T as parseCSV,
|
|
486
|
-
|
|
508
|
+
a as residue,
|
|
487
509
|
E as rot32,
|
|
488
510
|
D as rot32BI,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
511
|
+
x as sleep,
|
|
512
|
+
L as toBigInt,
|
|
513
|
+
W as u8ArrToBI,
|
|
492
514
|
U as u8ArrToBase64,
|
|
493
|
-
|
|
515
|
+
X as u8ArrToBase64Url
|
|
494
516
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`&&!i?(e.push(r.trim()),
|
|
1
|
+
(function(l,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(l=typeof globalThis<"u"?globalThis:l||self,g(l["util-fns"]={}))})(this,(function(l){"use strict";const g=new TextEncoder,m=(n,t)=>{if(typeof n!=typeof t)return!1;const e=Object.prototype.toString.call(n),r=Object.prototype.toString.call(t);if(e!==r)return!1;if(typeof n=="string"||typeof n=="bigint"||typeof n=="boolean"||typeof n=="symbol"||typeof n>"u")return n===t;if(typeof n=="number")return Number.isNaN(n)&&Number.isNaN(t)||n===t;if(n===null)return n===t;if(typeof n=="function")throw Error("comparing these objects is still unavailable");if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;for(let i=0;i<n.length;i++)if(!m(n[i],t[i]))return!1;return!0}if(e==="[object Object]"){const i=n,s=t,o=Object.getOwnPropertyNames(n),c=Object.getOwnPropertyNames(t);o.push(...Object.getOwnPropertySymbols(n)),c.push(...Object.getOwnPropertySymbols(t));for(const u of o){const a=c.find(nt=>nt===u);if(a===void 0)return!1;const[y,I]=[i[u],s[a]];if(!m(y,I))return!1}return!0}throw Error("comparing these objects is still unavailable")},j=n=>new Promise(t=>{setTimeout(()=>{t()},n)}),O=n=>(...t)=>()=>n(...t),M=n=>{const t=[];let e=[],r="",i=!1;for(let s=0;s<n.length;s++){const o=n[s];o==='"'&&(s===0||n[s-1]!=="\\")?i=!i:o===","&&!i?(e.push(r.trim()),r=""):o===`
|
|
2
|
+
`&&!i?(e.push(r.trim()),t.push(e),e=[],r=""):r+=o}return e.push(r.trim()),t.push(e),t},L=async(n,t)=>{const e=g.encode(n),r=await crypto.subtle.digest(t,e);return new Uint8Array(r)},_=(...n)=>n.map(t=>BigInt(t)),w=()=>typeof globalThis.process<"u"&&typeof globalThis.require<"u",C=(n,t)=>Math.floor(Math.random()*(t-n)+n),h=(n,t)=>{const e=n%t;return e<0n?e+t:e},b=(n,t=!1)=>{if(!Number.isFinite(n))throw Error("`length` is not a valid number");if(n<=0)throw Error("`length` must be positive");const e=Math.ceil(n/8),r=crypto.getRandomValues(new Uint8Array(e));let i=Array.from(r,s=>s.toString(2).padStart(8,"0")).join("").slice(0,n);return t&&(i=i.replace(/^./,"1")),BigInt("0b"+i)},S=(n,t)=>{if(n>=t)throw Error("rangeError");const e=t-n,r=e.toString(2).length,i=(()=>{for(let o=0;o<1e5;o++){const c=b(r);if(c>=d(2n,BigInt(r),e))return c%e}throw Error("Failed to generate a random bigint")})();return n+i},d=(n,t,e)=>{if(e<1n)throw Error("`mod` must be positive");if(t<0n)throw Error("`power` must not be negative");for(;n<0n;)n+=e;if(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},N=(n,t)=>{if(n===0n&&t===0n)return{x:0n,y:0n,gcd:0n};if(n===0n)return t>0n?{x:0n,y:-1n,gcd:t}:{x:0n,y:1n,gcd:-t};if(t===0n)return n>0n?{x:1n,y:0n,gcd:n}:{x:-1n,y:0n,gcd:-n};let[e,r,i]=[1n,0n,n],[s,o,c]=[0n,-1n,t];for(;;){const u=i/c,a=i-u*c;if(a===0n)break;[e,s]=[s,e-u*s],[r,o]=[o,r-u*o],[i,c]=[c,a]}return c<0n&&(s*=-1n,o*=-1n,c*=-1n),{x:s,y:o,gcd:c}},A=(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 u=n+2n;u<t;u+=2n)c*=u;return c}const i=n+r|1n,s=A(n,i),o=A(i,t);return s*o},J=n=>{let t=3n,e=1n,r=1n;const i=BigInt(n.toString(2).length)-1n;for(let s=i-1n;s>-1n;--s){const o=(n>>s)+1n|1n;r*=A(t,o),t=o,e*=r}return e},V=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 J(n)<<t},q=(n,t)=>BigInt.asUintN(32,n>>(t&31n)|n<<(-t&31n)),E=(n,t)=>(n>>>(t&31)|n<<(-t&31))>>>0,B=(n,t)=>{if(t<1n||t%2n===0n)throw Error("`n` is invalid");for(;n<0n;)n+=t;n%=t;let e=1n;for(;n!==0n;){for(;n%2n===0n;){n/=2n;const r=t%8n;(r===3n||r===5n)&&(e*=-1n)}[n,t]=[t,n],n%4n===3n&&t%4n===3n&&(e*=-1n),n%=t}return t===1n?e:0n},P=n=>{if(n<0n)return!1;if(n===0n)return!0;let t=1n,e=n;for(;t+1n<e;){const r=(t+e)/2n;r**2n<n?t=r:e=r}return n===t**2n||n===(t+1n)**2n},D=[0x853c49e6748fea9bn,0xda3e39cb94b95bdbn],W=0x5851f42d4c957f2dn;class k{#t=new BigUint64Array(2);static getSeed(){return crypto.getRandomValues(new BigUint64Array(2))}constructor(t){t?(this.#t[1]=t[1]<<1n|1n,this.#n(),this.#t[0]=t[0],this.#n()):(this.#t[0]=D[0],this.#t[1]=D[1])}#n(){this.#t[0]=this.#t[0]*W+this.#t[1]}get#e(){const t=this.#t[0];if(!t)throw Error("empty state");const e=t>>59n,r=BigInt.asUintN(32,(t^t>>18n)>>27n);return E(Number(r),Number(e))}getRand(){return this.#n(),this.#e}getBoundedRand(t){if(t>4294967296)throw Error("`bound` exceeded limit (2^32)");const r=4294967296%t;for(;;){const i=this.getRand();if(i>=r)return i%t}}*genRands(t,e){for(let r=0;r<t;r++)yield typeof e=="number"?this.getBoundedRand(e):this.getRand()}}const X=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;let t=n-1n,e=0n;for(;t%2n===0n;)t>>=1n,e+=1n;const[r,i]=[t,e];let o=d(2n,r,n);if(o===1n)return!0;for(let c=0n;c<i;c++){if(o===n-1n)return!0;o=o*o%n}return!1},Y=n=>{let t=5n,e=B(t,n);for(;e>0n;){if(t=t>0n?t+2n:t-2n,t*=-1n,t===-15n&&P(n))return[0n,0n];e=B(t,n)}return[t,e]},U=(n,t)=>(n&1n)===1n?h(n+t>>1n,t):h(n>>1n,t),Z=(n,t,e,r)=>{let i=1n,s=e;const o=n.toString(2).slice(1);for(const c of o)[i,s]=[h(i*s,t),U(s*s+r*i*i,t)],c==="1"&&([i,s]=[U(e*i+s,t),U(r*i+e*s,t)]);return[i,s]},F=(n,t,e,r)=>{if(n%2n!==1n)throw Error("`n` must be odd");let i=n+1n,s=0n;for(;i%2n===0n;)i>>=1n,s+=1n;const[o,c]=Z(i,n,e,t);let u=c;if(o===0n)return!0;r=d(r,i,n);for(let a=0n;a<s;a++){if(u===0n)return!0;u=h(u*u-2n*r,n),r=d(r,2n,n)}return!1},p=n=>{if(n<=1n)return!1;if(n%2n===0n)return n===2n;const t=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n];for(const s of t)if(n%s===0n)return n===s;if(!X(n))return!1;const[e,r]=Y(n);if(r===0n)return!1;const i=(1n-e)/4n;return F(n,e,1n,i)},$=(n,t)=>{if(t<2n)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=S(n,t);if(p(i))return i}throw Error("noPrimesFound")},v=(n,t=!1)=>{if(n<2)throw Error("noPrimesFound");for(let r=0;r<1e5;r++){const i=b(n,t);if(p(i))return i}throw Error("noPrimesFound")};class f{#t;#n;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=20){if(Number.isNaN(t))return new f(0n,0n);if(Math.abs(t)===1/0)return new f(t>0?1n:-1n,0n);const r=t<0;r&&(t*=-1);const i=BigInt(Math.floor(t)),s=t-Number(i);if(s===0)return new f(r?-i:i,1n);t=1/s;let[o,c]=[1n,i],[u,a]=[0n,1n];for(;`${a}`.length<e+1;){const y=BigInt(Math.floor(t)),I=t-Number(y);if([o,c]=[c,y*c+o],[u,a]=[a,y*a+u],I===0)return new f(r?-c:c,a);t=1/I}return new f(r?-o:o,u)}#e(){const{gcd:t}=N(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 new f(this.#t,this.#n).add(t.minus())}multiply(t){const e=this.#n*t.#n,r=this.#t*t.#t;return new f(r,e)}divide(t){return new f(this.#t,this.#n).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:"Fraction",numerator:"0x"+this.#t.toString(16),denominator:"0x"+this.#n.toString(16)}}static parse(t){const e=JSON.parse(t),{type:r,numerator:i,denominator:s}=e;if(r!=="Fraction")throw Error("cannot parse");if(typeof i=="string"&&typeof s=="string"){const o=BigInt(i),c=BigInt(s);return new f(o,c)}else throw Error("cannot parse")}}const K=n=>{let t=n.toString(16);t.length&1&&(t="0"+t);const e=[...t.match(/.{2}/g)??[]];return Uint8Array.from(e,r=>Number.parseInt(r,16))},z=n=>{const t=Array.from(n,e=>e.toString(16).padStart(2,"0")).join("")||"00";return BigInt("0x"+t)},R=n=>{if(w())return Buffer.copyBytesFrom(n).toString("base64");{const t=Array.from(n,e=>String.fromCharCode(e)).join("");return btoa(t)}},T=n=>{if(w()){const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}else return Uint8Array.from(atob(n),t=>t.charCodeAt(0))},G=n=>R(n).replaceAll(/\+/g,"-").replaceAll(/\//g,"_").replaceAll(/=*$/g,""),H=n=>{const t=n.length&3;t>0&&(n=n+"=".repeat(4-t));const e=n.replaceAll(/-/g,"+").replaceAll(/_/g,"/");return T(e)},Q={isEqual:m,sleep:j,lazify:O,parseCSV:M,getHash:L,isNode:w,toBigInt:_},x={getRndInt:C,residue:h,getRandBIByBitLength:b,getRandBIByRange:S,modPow:d,exEuclidean:N,factorial:V,rot32:E,rot32BI:q,jacobiSymbol:B,isSquare:P,bailliePSW:p,getRandPrimeByBitLength:v,getRandPrimeByRange:$},tt={base64ToU8Arr:T,base64UrlToU8Arr:H,u8ArrToBase64:R,u8ArrToBase64Url:G,BItoU8Arr:K,u8ArrToBI:z};l.BItoU8Arr=K,l.Calc=x,l.Fraction=f,l.PCGMinimal=k,l.U8Ext=tt,l.Util=Q,l.bailliePSW=p,l.base64ToU8Arr=T,l.base64UrlToU8Arr=H,l.exEuclidean=N,l.factorial=V,l.getHash=L,l.getRandBIByBitLength=b,l.getRandBIByRange=S,l.getRandPrimeByBitLength=v,l.getRandPrimeByRange=$,l.getRndInt=C,l.isEqual=m,l.isNode=w,l.isSquare=P,l.jacobiSymbol=B,l.lazify=O,l.modPow=d,l.parseCSV=M,l.residue=h,l.rot32=E,l.rot32BI=q,l.sleep=j,l.toBigInt=_,l.u8ArrToBI=z,l.u8ArrToBase64=R,l.u8ArrToBase64Url=G,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/fraction.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
declare const __frac_brand: unique symbol;
|
|
2
1
|
export type FractionData = {
|
|
3
2
|
type: 'Fraction';
|
|
4
3
|
numerator: string;
|
|
5
4
|
denominator: string;
|
|
6
5
|
};
|
|
7
|
-
|
|
6
|
+
declare class Fraction {
|
|
8
7
|
#private;
|
|
9
|
-
readonly [__frac_brand]: unknown;
|
|
10
8
|
/**
|
|
11
9
|
*
|
|
12
10
|
* @param numerator
|
|
@@ -73,4 +71,4 @@ export default class Fraction {
|
|
|
73
71
|
toJSON(): FractionData;
|
|
74
72
|
static parse(text: string): Fraction;
|
|
75
73
|
}
|
|
76
|
-
export
|
|
74
|
+
export default Fraction;
|
package/dist/math.d.ts
CHANGED
|
@@ -12,12 +12,6 @@ export declare const getRndInt: (min: number, max: number) => number;
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
export declare const residue: (n: bigint, mod: bigint) => bigint;
|
|
15
|
-
/**
|
|
16
|
-
* number を bigint に変換
|
|
17
|
-
* @param nums
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export declare const toBigInt: (...nums: number[]) => bigint[];
|
|
21
15
|
/**
|
|
22
16
|
* `length` ビットの乱数 or `length` ビット以下の乱数を出力する
|
|
23
17
|
* @param length ビット長
|
package/dist/pcg-minimal.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
declare const __pcg_brand: unique symbol;
|
|
2
1
|
/**
|
|
3
2
|
* PCG-XSH-RR (Permuted congruential generator) 乱数のクラス
|
|
4
3
|
*/
|
|
5
4
|
export default class PCGMinimal {
|
|
6
5
|
#private;
|
|
7
|
-
readonly [__pcg_brand]: unknown;
|
|
8
6
|
/** シード値の配列を返す */
|
|
9
7
|
static getSeed(): BigUint64Array<ArrayBuffer>;
|
|
10
8
|
/**
|
|
11
9
|
* @param seeds 64bit整数の配列 (長さ2以上), 省略した場合, 常に同じ値によって初期化される
|
|
12
10
|
*/
|
|
13
11
|
constructor(seeds?: BigUint64Array<ArrayBuffer>);
|
|
14
|
-
/** 内部状態を1サイクル進める */
|
|
15
|
-
step(): void;
|
|
16
|
-
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
17
|
-
get value(): number;
|
|
18
12
|
/** 内部状態を1進め、乱数を返す \
|
|
19
13
|
* 普通はこれを使う
|
|
20
14
|
*/
|
|
@@ -28,4 +22,3 @@ export default class PCGMinimal {
|
|
|
28
22
|
*/
|
|
29
23
|
genRands(step: number, bound?: number): Generator<number, void, unknown>;
|
|
30
24
|
}
|
|
31
|
-
export {};
|
package/dist/util.d.ts
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* オブジェクトが等しいかどうかの真偽値を返す
|
|
3
3
|
* @returns
|
|
4
4
|
*/
|
|
5
|
-
declare const
|
|
5
|
+
declare const isEqual: (a: unknown, b: unknown) => boolean;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param delay
|
|
7
|
+
* sleep
|
|
8
|
+
* @param delay milliseconds
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
declare const sleep: (delay: number) => Promise<void>;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* makes function lazy
|
|
14
|
+
*/
|
|
13
15
|
declare const lazify: <ArgT extends unknown[], RetT>(func: (...args: ArgT) => RetT) => (...args: ArgT) => () => RetT;
|
|
14
16
|
/**
|
|
15
|
-
* CSV
|
|
16
|
-
*
|
|
17
|
+
* parses CSV string \
|
|
18
|
+
* can deal with CSV with escaping doublequote
|
|
17
19
|
* @param csv CSV
|
|
18
20
|
* @returns 2次元配列
|
|
19
21
|
*/
|
|
20
22
|
declare const parseCSV: (csv: string) => string[][];
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* returns hash of a string
|
|
23
25
|
* @param str 文字列
|
|
24
26
|
* @param algorithm アルゴリズム
|
|
25
27
|
* @returns ハッシュ値
|
|
26
28
|
*/
|
|
27
29
|
declare const getHash: (str: string, algorithm: AlgorithmIdentifier) => Promise<Uint8Array<ArrayBuffer>>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* number を bigint に変換
|
|
32
|
+
* @param nums
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
declare const toBigInt: (...nums: number[]) => bigint[];
|
|
36
|
+
declare const isNode: () => boolean;
|
|
37
|
+
export { isEqual, sleep, lazify, parseCSV, getHash, isNode, toBigInt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tktb-tess/util-fns",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Utility functions for personal use",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/tktb-tess/util-fns"
|
|
25
25
|
},
|
|
26
|
+
"homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
|
|
26
27
|
"scripts": {
|
|
27
28
|
"dev": "vite",
|
|
28
29
|
"build": "tsc && vite build",
|