@tktb-tess/util-fns 0.6.0 → 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/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- const U = new TextEncoder(), _ = (n, t) => [n].includes(t), a = (n, t) => {
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 (!a(n[s], t[s])) return !1;
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 !!a(s, i);
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 (!a(s, i)) return !1;
23
+ if (!h(s, i)) return !1;
24
24
  const o = [...n.values()], c = [...t.values()];
25
- return !!a(o, c);
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((E) => E === u);
30
+ const l = c.find((j) => j === u);
31
31
  if (l === void 0) return !1;
32
- const [h, g] = [s[u], i[l]];
33
- if (!a(h, g)) return !1;
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
- }, q = (n) => new Promise((t) => {
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
- }, k = async (n, t) => {
59
- const e = U.encode(n), r = await crypto.subtle.digest(t, 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
- }, J = () => globalThis.process && typeof process.version < "u" && typeof process.versions.node < "u", W = (n) => encodeURIComponent(n).replace(
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
- ), z = (n) => {
64
+ ), G = (n) => {
65
65
  if (n.includes("+"))
66
66
  throw Error("An input string has '+'");
67
67
  return decodeURIComponent(n);
68
- }, G = (n, t) => Math.floor(Math.random() * (t - n) + n), d = (n, t) => {
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
- }, b = (n, t = !1) => {
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
- }, P = (n, t) => {
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 = b(r);
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 = d(n, e), e === 1n) return 0n;
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
- }, T = (n, t) => {
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
- }, j = (n) => {
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
- }, H = (n) => {
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 j(n) << t;
136
- }, Z = (n, t) => BigInt.asUintN(32, n >> (t & 31n) | n << (-t & 31n)), v = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => {
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
- }, x = (n) => {
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], M = 0x5851f42d4c957f2dn;
162
- class I {
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 I.name;
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] * M + this.#t[1];
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 v(Number(r), Number(e));
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 V = (n) => {
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
- }, C = (n) => {
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 && x(n))
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 ? d(n + t >> 1n, t) : d(n >> 1n, t), R = (n, t, e, r) => {
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] = [d(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)]);
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,10 +255,10 @@ 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 = d(u * u - 2n * r, n), r = p(r, 2n, n);
258
+ u = g(u * u - 2n * r, n), r = p(r, 2n, n);
259
259
  }
260
260
  return !1;
261
- }, A = (n) => {
261
+ }, B = (n) => {
262
262
  if (n <= 1n) return !1;
263
263
  if (n % 2n === 0n) return n === 2n;
264
264
  const t = [
@@ -292,26 +292,26 @@ const V = (n) => {
292
292
  for (const i of t)
293
293
  if (n % i === 0n)
294
294
  return n === i;
295
- if (!V(n))
295
+ if (!C(n))
296
296
  return !1;
297
- const [e, r] = C(n);
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
- }, X = (n, t) => {
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 = P(n, t);
306
- if (A(s)) return s;
305
+ const s = U(n, t);
306
+ if (B(s)) return s;
307
307
  }
308
308
  throw Error("noPrimesFound");
309
- }, Y = (n, t = !1) => {
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 = b(n, t);
314
- if (A(s)) return s;
313
+ const s = I(n, t);
314
+ if (B(s)) return s;
315
315
  }
316
316
  throw Error("noPrimesFound");
317
317
  };
@@ -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 h = BigInt(Math.floor(t)), g = t - Number(h);
354
- if ([o, c] = [c, h * c + o], [u, l] = [l, h * l + u], g === 0)
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 / g;
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 } = T(this.#t, this.#n);
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 Q = (n) => {
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
- }, tt = (n) => {
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
- }, O = (n) => {
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)), nt = (n) => O(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=*$/g, ""), et = (n) => {
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
477
  };
478
- class B {
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 B.name;
485
+ return N.name;
486
486
  }
487
487
  constructor(...t) {
488
488
  this.#t = t;
@@ -508,13 +508,13 @@ class B {
508
508
  return this.toArray().toString();
509
509
  }
510
510
  }
511
- class N {
511
+ class E {
512
512
  #t;
513
513
  static get name() {
514
514
  return "Executer";
515
515
  }
516
516
  get [Symbol.toStringTag]() {
517
- return N.name;
517
+ return E.name;
518
518
  }
519
519
  constructor(t) {
520
520
  this.#t = {
@@ -558,39 +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
- Q as BItoU8Arr,
563
- N as Executer,
564
- I as PCGMinimal,
565
- B as Queue,
583
+ tt as BItoU8Arr,
584
+ E as Executer,
585
+ st as NamedError,
586
+ A as PCGMinimal,
587
+ N as Queue,
566
588
  f as Rational,
567
- A as bailliePSW,
589
+ B as bailliePSW,
568
590
  L as base64ToU8Arr,
569
- et as base64UrlToU8Arr,
570
- z as decodeRFC3986URIComponent,
571
- W as encodeRFC3986URIComponent,
572
- T as exEuclidean,
573
- H as factorial,
574
- k as getHash,
575
- b as getRandBIByBitLength,
576
- P as getRandBIByRange,
577
- Y as getRandPrimeByBitLength,
578
- X as getRandPrimeByRange,
579
- G as getRndInt,
580
- a as isEqual,
581
- J as isNode,
582
- x as isSquare,
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,
583
605
  w as jacobiSymbol,
584
606
  D as lazify,
585
607
  p as modPow,
586
608
  K as parseCSV,
587
- $ as promiseWithResolvers,
588
- d as residue,
589
- v as rot32,
590
- Z as rot32BI,
591
- _ as sameValueZero,
592
- q as sleep,
593
- tt as u8ArrToBI,
594
- O as u8ArrToBase64,
595
- nt as u8ArrToBase64Url
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
596
618
  };
package/dist/main.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './fraction';
6
6
  export * from './u8arr-ext';
7
7
  export * from './queue';
8
8
  export * from './executer';
9
+ export * from './named-error';
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tktb-tess/util-fns",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Utility functions for personal use",
5
5
  "files": [
6
6
  "dist"
@@ -25,7 +25,6 @@
25
25
  "homepage": "https://github.com/tktb-tess/util-fns/blob/main/README.md",
26
26
  "devDependencies": {
27
27
  "@types/node": "^24.6.2",
28
- "jsdom": "^26.1.0",
29
28
  "tsx": "^4.20.6",
30
29
  "typescript": "^5.9.3",
31
30
  "vite": "^7.1.9",
package/dist/brand.d.ts DELETED
File without changes