@tktb-tess/util-fns 0.13.0 → 0.13.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.
Files changed (38) hide show
  1. package/dist/esm/async_worker.d.ts +5 -13
  2. package/dist/esm/async_worker.js +13 -27
  3. package/dist/esm/async_worker_post.d.ts +3 -0
  4. package/dist/esm/async_worker_post.js +20 -0
  5. package/dist/esm/async_worker_type.d.ts +20 -0
  6. package/dist/esm/baillie_psw.js +165 -3
  7. package/dist/esm/{u8arr_ext.d.ts → base64.d.ts} +0 -2
  8. package/dist/esm/base64.js +13 -0
  9. package/dist/esm/bpsw_worker_wrap-Ex4MZHGr.js +20 -0
  10. package/dist/esm/bpsw_worker_wrap.d.ts +1 -1
  11. package/dist/esm/compression.d.ts +30 -0
  12. package/dist/esm/compression.js +19 -0
  13. package/dist/esm/equality.d.ts +13 -0
  14. package/dist/esm/equality.js +29 -0
  15. package/dist/esm/fixed_array.d.ts +9 -0
  16. package/dist/esm/fixed_array.js +7 -0
  17. package/dist/esm/fraction.d.ts +19 -16
  18. package/dist/esm/fraction.js +2 -2
  19. package/dist/esm/index.d.ts +6 -1
  20. package/dist/esm/index.js +18 -12
  21. package/dist/esm/leb128.d.ts +10 -0
  22. package/dist/esm/math.d.ts +4 -39
  23. package/dist/esm/math.js +17 -44
  24. package/dist/esm/mod_pow-S-7GJ74l.js +17 -0
  25. package/dist/esm/mod_pow.d.ts +15 -0
  26. package/dist/esm/named_error.d.ts +2 -1
  27. package/dist/esm/named_error.js +4 -3
  28. package/dist/esm/oct.d.ts +13 -0
  29. package/dist/esm/oct.js +24 -0
  30. package/dist/esm/random.d.ts +22 -0
  31. package/dist/esm/random.js +28 -12
  32. package/dist/esm/util.d.ts +12 -36
  33. package/dist/esm/util.js +11 -56
  34. package/dist/iife/bundle.min.js +1 -2
  35. package/package.json +29 -9
  36. package/dist/esm/baillie_psw-DzyqB4sZ.js +0 -164
  37. package/dist/esm/bpsw_worker-CZOWXQMI.js +0 -16
  38. package/dist/esm/u8arr_ext.js +0 -19
@@ -1,15 +1,10 @@
1
- declare const __ID_BRAND__: unique symbol;
2
- type ID = bigint & {
3
- readonly [__ID_BRAND__]: unknown;
4
- };
5
- export interface WorkerMessage<T> {
6
- readonly value: T;
7
- readonly id: ID;
8
- }
9
- export declare class AsyncWorker<TPost = unknown, TRecv = unknown, TErr = unknown> {
1
+ import { WorkerSucceededResult, WorkerFailedResult, WorkerMessage } from './async_worker_type';
2
+ export type WorkerResult<T> = WorkerSucceededResult<T> | WorkerFailedResult;
3
+ export type { WorkerMessage };
4
+ export declare class AsyncWorker<TPost = unknown, TRecv = unknown> {
10
5
  #private;
11
6
  static readonly name = "AsyncWorker";
12
- constructor(w: Worker);
7
+ constructor(worker: Worker);
13
8
  /**
14
9
  * sends a message to the worker, and returns promise resolved by message from worker
15
10
  * @param message
@@ -17,6 +12,3 @@ export declare class AsyncWorker<TPost = unknown, TRecv = unknown, TErr = unknow
17
12
  */
18
13
  readonly postMessage: (message: TPost, options?: StructuredSerializeOptions) => Promise<TRecv>;
19
14
  }
20
- export declare const postSuccess: <TRecv>(value: TRecv, id: ID) => void;
21
- export declare const postFailed: <TErr>(error: TErr, id: ID) => void;
22
- export {};
@@ -1,18 +1,21 @@
1
1
  //#region lib/async_worker.ts
2
- var e = "AsyncWorker", t = 0n, n = () => (t === 2n ** 128n && (t = 0n), t++), r = class {
2
+ var e = "AsyncWorker", t = 1n << 128n, n = 0n, r = () => {
3
+ let e = `${n++}`;
4
+ return n === t && (n = 0n), e;
5
+ }, i = class {
3
6
  static name = e;
4
7
  #e;
5
8
  constructor(e) {
6
9
  this.#e = e;
7
10
  }
8
- postMessage = (e, t) => new Promise((r, i) => {
9
- let a = n(), o = (e) => {
11
+ postMessage = (e, t) => new Promise((n, i) => {
12
+ let a = r(), o = new AbortController(), { signal: s } = o;
13
+ this.#e.addEventListener("message", (e) => {
10
14
  let t = e.data;
11
- t.id === a && (this.#e.removeEventListener("message", o), this.#e.removeEventListener("error", s), t.success ? r(t.value) : i(t.error));
12
- }, s = (e) => {
13
- this.#e.removeEventListener("message", o), this.#e.removeEventListener("error", s), i(e.error);
14
- };
15
- this.#e.addEventListener("message", o), this.#e.addEventListener("error", s);
15
+ t.id === a && (o.abort(), t.success ? n(t.value) : i(t.error));
16
+ }, { signal: s }), this.#e.addEventListener("error", (e) => {
17
+ o.abort(), i(e.error);
18
+ }, { signal: s });
16
19
  let c = {
17
20
  value: e,
18
21
  id: a
@@ -20,26 +23,9 @@ var e = "AsyncWorker", t = 0n, n = () => (t === 2n ** 128n && (t = 0n), t++), r
20
23
  this.#e.postMessage(c, t);
21
24
  });
22
25
  };
23
- Object.defineProperty(r.prototype, Symbol.toStringTag, {
26
+ Object.defineProperty(i.prototype, Symbol.toStringTag, {
24
27
  value: e,
25
28
  enumerable: !0
26
29
  });
27
- var i = () => typeof window > "u" && typeof self < "u" && "importScripts" in self, a = (e, t) => {
28
- if (!i()) throw Error("this function must be used in Worker");
29
- let n = {
30
- success: !0,
31
- value: e,
32
- id: t
33
- };
34
- self.postMessage(n);
35
- }, o = (e, t) => {
36
- if (!i()) throw Error("this function must be used in Worker");
37
- let n = {
38
- success: !1,
39
- error: e,
40
- id: t
41
- };
42
- self.postMessage(n);
43
- };
44
30
  //#endregion
45
- export { r as AsyncWorker, o as postFailed, a as postSuccess };
31
+ export { i as AsyncWorker };
@@ -0,0 +1,3 @@
1
+ import { ID } from './async_worker_type';
2
+ export declare const postSuccess: <TRecv>(value: TRecv, id: ID) => void;
3
+ export declare const postFailed: (error: unknown, id: ID) => void;
@@ -0,0 +1,20 @@
1
+ //#region lib/async_worker_post.ts
2
+ var e = () => typeof window > "u" && typeof self < "u" && "importScripts" in self, t = (t, n) => {
3
+ if (!e()) throw Error("this function must be used in Worker");
4
+ let r = {
5
+ success: !0,
6
+ value: t,
7
+ id: n
8
+ };
9
+ self.postMessage(r);
10
+ }, n = (t, n) => {
11
+ if (!e()) throw Error("this function must be used in Worker");
12
+ let r = {
13
+ success: !1,
14
+ error: t,
15
+ id: n
16
+ };
17
+ self.postMessage(r);
18
+ };
19
+ //#endregion
20
+ export { n as postFailed, t as postSuccess };
@@ -0,0 +1,20 @@
1
+ declare const __ID_BRAND__: unique symbol;
2
+ export type ID = string & {
3
+ readonly [__ID_BRAND__]: unknown;
4
+ };
5
+ export interface WorkerMessage<T> {
6
+ readonly value: T;
7
+ readonly id: ID;
8
+ }
9
+ interface WorkerID {
10
+ readonly id: ID;
11
+ }
12
+ export interface WorkerSucceededResult<T> extends WorkerID {
13
+ readonly success: true;
14
+ readonly value: T;
15
+ }
16
+ export interface WorkerFailedResult extends WorkerID {
17
+ readonly success: false;
18
+ readonly error: unknown;
19
+ }
20
+ export {};
@@ -1,3 +1,165 @@
1
- import "./math.js";
2
- import { i as e, n as t, r as n, t as r } from "./baillie_psw-DzyqB4sZ.js";
3
- export { r as bailliePSW, t as bailliePSWAsync, n as getRandPrimeByBitLength, e as getRandPrimeByRange };
1
+ import { n as e, t } from "./mod_pow-S-7GJ74l.js";
2
+ import { isSquare as n, jacobiSymbol as r } from "./math.js";
3
+ import { getRandBIByBitLength as i, getRandBIByRange as a } from "./random.js";
4
+ //#region lib/baillie_psw.ts
5
+ var o = [
6
+ 2n,
7
+ 3n,
8
+ 5n,
9
+ 7n,
10
+ 11n,
11
+ 13n,
12
+ 17n,
13
+ 19n,
14
+ 23n,
15
+ 29n,
16
+ 31n,
17
+ 37n,
18
+ 41n,
19
+ 43n,
20
+ 47n,
21
+ 53n,
22
+ 59n,
23
+ 61n,
24
+ 67n,
25
+ 71n,
26
+ 73n,
27
+ 79n,
28
+ 83n,
29
+ 89n,
30
+ 97n,
31
+ 101n,
32
+ 103n,
33
+ 107n,
34
+ 109n,
35
+ 113n,
36
+ 127n,
37
+ 131n,
38
+ 137n,
39
+ 139n,
40
+ 149n,
41
+ 151n,
42
+ 157n,
43
+ 163n,
44
+ 167n,
45
+ 173n,
46
+ 179n,
47
+ 181n,
48
+ 191n,
49
+ 193n,
50
+ 197n,
51
+ 199n,
52
+ 211n,
53
+ 223n,
54
+ 227n,
55
+ 229n,
56
+ 233n,
57
+ 239n,
58
+ 241n,
59
+ 251n,
60
+ 257n,
61
+ 263n,
62
+ 269n,
63
+ 271n,
64
+ 277n,
65
+ 281n,
66
+ 283n,
67
+ 293n,
68
+ 307n,
69
+ 311n,
70
+ 313n,
71
+ 317n,
72
+ 331n,
73
+ 337n,
74
+ 347n,
75
+ 349n,
76
+ 353n,
77
+ 359n,
78
+ 367n,
79
+ 373n,
80
+ 379n,
81
+ 383n,
82
+ 389n,
83
+ 397n,
84
+ 401n,
85
+ 409n,
86
+ 419n,
87
+ 421n,
88
+ 431n,
89
+ 433n,
90
+ 439n,
91
+ 443n,
92
+ 449n,
93
+ 457n,
94
+ 461n,
95
+ 463n,
96
+ 467n,
97
+ 479n,
98
+ 487n,
99
+ 491n,
100
+ 499n
101
+ ], s = (e) => {
102
+ if (e <= 1n) return !1;
103
+ if (e % 2n == 0n) return e === 2n;
104
+ let n = e - 1n, r = 0n;
105
+ for (; n % 2n == 0n;) n >>= 1n, r += 1n;
106
+ let [i, a] = [n, r], o = t(2n, i, e);
107
+ if (o === 1n) return !0;
108
+ for (let t = 0n; t < a; t++) {
109
+ if (o === e - 1n) return !0;
110
+ o = o * o % e;
111
+ }
112
+ return !1;
113
+ }, c = (e) => {
114
+ let t = 5n;
115
+ for (;;) {
116
+ let i = r(t, e);
117
+ if (i === -1n) return t;
118
+ if (i === 0n || (t = t > 0n ? -(t + 2n) : -(t - 2n), t === -15n && n(e))) return null;
119
+ }
120
+ }, l = (t, n) => {
121
+ if ((n & 1n) == 0n) throw Error("`n` is not odd");
122
+ return (t & 1n) == 1n ? e(t + n >> 1n, n) : e(t >> 1n, n);
123
+ }, u = (t, n, r, i) => {
124
+ let a = 1n, o = r, s = t.toString(2).slice(1);
125
+ for (let t of s) [a, o] = [e(a * o, n), l(o * o + i * a * a, n)], t === "1" && ([a, o] = [l(r * a + o, n), l(i * a + r * o, n)]);
126
+ return [a, o];
127
+ }, d = (n, r, i, a) => {
128
+ if (n % 2n != 1n) throw RangeError("`n` must be odd");
129
+ let o = n + 1n, s = 0n;
130
+ for (; o % 2n == 0n;) o >>= 1n, s += 1n;
131
+ let [c, l] = u(o, n, i, r), d = l;
132
+ if (c === 0n) return !0;
133
+ a = t(a, o, n);
134
+ for (let r = 0n; r < s; r++) {
135
+ if (d === 0n) return !0;
136
+ d = e(d * d - 2n * a, n), a = t(a, 2n, n);
137
+ }
138
+ return !1;
139
+ }, f = (e) => {
140
+ if (e <= 1n) return !1;
141
+ if (e % 2n == 0n) return e === 2n;
142
+ for (let t of o) if (e % t === 0n) return e === t;
143
+ if (!s(e)) return !1;
144
+ let t = c(e);
145
+ return t == null ? !1 : d(e, t, 1n, (1n - t) / 4n);
146
+ }, p = (e, t) => {
147
+ if (t < 2n) throw RangeError("`max` must be 2 or larger");
148
+ for (let n = 0; n < 1e5; n++) {
149
+ let n = a(e, t);
150
+ if (f(n)) return n;
151
+ }
152
+ throw Error("no primes were found");
153
+ }, m = (e, t = !1) => {
154
+ if (e < 2) throw RangeError("`bitLength` must be 2 or larger");
155
+ for (let n = 0; n < 1e5; n++) {
156
+ let n = i(e, t);
157
+ if (f(n)) return n;
158
+ }
159
+ throw Error("no primes were found");
160
+ }, h = async (e) => {
161
+ let { getWorker: t } = await import("./bpsw_worker_wrap-Ex4MZHGr.js");
162
+ return (await t()).postMessage(e);
163
+ };
164
+ //#endregion
165
+ export { f as bailliePSW, h as bailliePSWAsync, m as getRandPrimeByBitLength, p as getRandPrimeByRange };
@@ -2,5 +2,3 @@ export declare const toBase64: (bin: Uint8Array) => string;
2
2
  export declare const fromBase64: (base64: string) => Uint8Array<ArrayBuffer>;
3
3
  export declare const toBase64URL: (bin: Uint8Array) => string;
4
4
  export declare const fromBase64URL: (base64URL: string) => Uint8Array<ArrayBuffer>;
5
- export declare const toOct: (bin: Uint8Array) => string;
6
- export declare const fromOct: (oct: string) => Uint8Array<ArrayBuffer>;
@@ -0,0 +1,13 @@
1
+ //#region lib/base64.ts
2
+ var e = (e) => {
3
+ let t = Array.from(e, (e) => String.fromCharCode(e));
4
+ return btoa(t.join(""));
5
+ }, t = (e) => {
6
+ let t = atob(e);
7
+ return Uint8Array.from(t, (e) => e.charCodeAt(0));
8
+ }, n = (t) => e(t).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), r = (e) => {
9
+ let n = 4 - (e.length & 3) & 3;
10
+ return t(e.concat("=".repeat(n)).replaceAll("-", "+").replaceAll("_", "/"));
11
+ };
12
+ //#endregion
13
+ export { t as fromBase64, r as fromBase64URL, e as toBase64, n as toBase64URL };
@@ -0,0 +1,20 @@
1
+ import { AsyncWorker as e } from "./async_worker.js";
2
+ //#region lib/bpsw_worker.ts?worker&inline
3
+ var t = "(function(){let e=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},t=(t,n,r)=>{if(r<1n)throw RangeError(\"`mod` must be positive\");if(n<0n)throw RangeError(\"`power` must not be negative\");if(t=e(t,r),r===1n)return 0n;if(t%r===1n||t%r===0n)return t;if(t===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*t%r),t=t*t%r,n>>=1n;return i},n=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError(\"`n` is out of range\");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},r=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n},i=[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,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],a=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let n=e-1n,r=0n;for(;n%2n==0n;)n>>=1n,r+=1n;let[i,a]=[n,r],o=t(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},o=e=>{let t=5n;for(;;){let i=n(t,e);if(i===-1n)return t;if(i===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&r(e)))return null}},s=(t,n)=>{if((n&1n)==0n)throw Error(\"`n` is not odd\");return(t&1n)==1n?e(t+n>>1n,n):e(t>>1n,n)},c=(t,n,r,i)=>{let a=1n,o=r,c=t.toString(2).slice(1);for(let t of c)[a,o]=[e(a*o,n),s(o*o+i*a*a,n)],t===`1`&&([a,o]=[s(r*a+o,n),s(i*a+r*o,n)]);return[a,o]},l=(n,r,i,a)=>{if(n%2n!=1n)throw RangeError(\"`n` must be odd\");let o=n+1n,s=0n;for(;o%2n==0n;)o>>=1n,s+=1n;let[l,u]=c(o,n,i,r),d=u;if(l===0n)return!0;a=t(a,o,n);for(let r=0n;r<s;r++){if(d===0n)return!0;d=e(d*d-2n*a,n),a=t(a,2n,n)}return!1},u=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of i)if(e%t===0n)return e===t;if(!a(e))return!1;let t=o(e);return t==null?!1:l(e,t,1n,(1n-t)/4n)},d=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,f=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},p=(e,t)=>{if(!d())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)},m=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{f(u(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;p({name:t,message:r,stack:i,cause:m(a)},n)}else p({name:`BPSWError`,message:`unidentified error`,cause:m(e)},n)}}})();", n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", t], { type: "text/javascript;charset=utf-8" });
4
+ function r(e) {
5
+ let r;
6
+ try {
7
+ if (r = n && (self.URL || self.webkitURL).createObjectURL(n), !r) throw "";
8
+ let t = new Worker(r, { name: e?.name });
9
+ return t.addEventListener("error", () => {
10
+ (self.URL || self.webkitURL).revokeObjectURL(r);
11
+ }), t;
12
+ } catch {
13
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(t), { name: e?.name });
14
+ }
15
+ }
16
+ //#endregion
17
+ //#region lib/bpsw_worker_wrap.ts
18
+ var i, a = async () => (i ||= new e(new r({ name: "bpsw_worker" })), i);
19
+ //#endregion
20
+ export { a as getWorker };
@@ -1,2 +1,2 @@
1
1
  import { AsyncWorker } from './async_worker';
2
- export declare const getWorker: () => Promise<AsyncWorker<bigint, boolean, unknown>>;
2
+ export declare const getWorker: () => Promise<AsyncWorker<bigint, boolean>>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Compress binary data
3
+ * @param raw
4
+ * @param format
5
+ * @returns
6
+ */
7
+ export declare const compress: (raw: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
8
+ /**
9
+ * Decompress binary data
10
+ * @param compressed
11
+ * @param format
12
+ * @returns
13
+ */
14
+ export declare const decompress: (compressed: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
15
+ /**
16
+ * Compress string into Base64(URL)-encoded string
17
+ * @param str
18
+ * @param format
19
+ * @param encoding default: `base64url`
20
+ * @returns
21
+ */
22
+ export declare const compressString: (str: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
23
+ /**
24
+ * Decompress Base64(URL)-encoded data
25
+ * @param compressedString
26
+ * @param format
27
+ * @param encoding default: `base64url`
28
+ * @returns
29
+ */
30
+ export declare const decompressString: (compressedString: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
@@ -0,0 +1,19 @@
1
+ import { fromBase64 as e, fromBase64URL as t, toBase64 as n, toBase64URL as r } from "./base64.js";
2
+ //#region lib/compression.ts
3
+ var i = (e, t) => {
4
+ let n = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
5
+ return new Response(n).bytes();
6
+ }, a = (e, t) => {
7
+ let n = new Blob([e]).stream().pipeThrough(new DecompressionStream(t));
8
+ return new Response(n).bytes();
9
+ }, o = async (e, t, i = "base64url") => {
10
+ let a = new Blob([e]).stream().pipeThrough(new CompressionStream(t)), o = await new Response(a).bytes();
11
+ return i === "base64" ? n(o) : r(o);
12
+ }, s = (n, r, i = "base64url") => {
13
+ let a;
14
+ a = i === "base64" ? e(n) : t(n);
15
+ let o = new Blob([a]).stream().pipeThrough(new DecompressionStream(r));
16
+ return new Response(o).text();
17
+ };
18
+ //#endregion
19
+ export { i as compress, o as compressString, a as decompress, s as decompressString };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Compare two objects with SameValueZero method
3
+ * @param a
4
+ * @param b
5
+ * @returns
6
+ */
7
+ export declare const sameValueZero: (a: unknown, b: unknown) => boolean;
8
+ /**
9
+ * Judges whether two objects has the same (nested) properties \
10
+ * Compares with SameValueZero, ignores symbol keys in an object
11
+ * @returns
12
+ */
13
+ export declare const isDeepStrictEqual: (a: unknown, b: unknown) => boolean;
@@ -0,0 +1,29 @@
1
+ //#region lib/equality.ts
2
+ var e = (e, t) => [e].includes(t), t = (e, n) => {
3
+ if (typeof e != typeof n) return !1;
4
+ let r = Object.prototype.toString.call(e);
5
+ if (r !== Object.prototype.toString.call(n)) return !1;
6
+ if (typeof e == "string" || typeof e == "bigint" || typeof e == "boolean" || typeof e == "symbol" || e == null) return e === n;
7
+ if (typeof e == "number") return e === n || e !== e && n !== n;
8
+ if (typeof e == "function") return !1;
9
+ if (Array.isArray(e) && Array.isArray(n)) {
10
+ if (e.length !== n.length) return !1;
11
+ for (let r = 0; r < e.length; r++) if (!t(e[r], n[r])) return !1;
12
+ return !0;
13
+ }
14
+ if (e instanceof Set && n instanceof Set) return !!t([...e.values()], [...n.values()]);
15
+ if (e instanceof Map && n instanceof Map) return !(!t([...e.keys()], [...n.keys()]) || !t([...e.values()], [...n.values()]));
16
+ if (r === "[object Object]") {
17
+ let r = e, i = n, a = Object.keys(r), o = Object.keys(i);
18
+ for (let e of a) {
19
+ let n = o.find((t) => t === e);
20
+ if (n == null) return !1;
21
+ let [a, s] = [r[e], i[n]];
22
+ if (!t(a, s)) return !1;
23
+ }
24
+ return !0;
25
+ }
26
+ throw TypeError(`comparing these objects is unavailable: ${e}, ${n}`, { cause: [e, n] });
27
+ };
28
+ //#endregion
29
+ export { t as isDeepStrictEqual, e as sameValueZero };
@@ -0,0 +1,9 @@
1
+ interface FixedUint8Array<B extends ArrayBufferLike, N extends number> extends Uint8Array<B> {
2
+ readonly length: N;
3
+ readonly byteLength: N;
4
+ }
5
+ declare const FixedUint8Array: {
6
+ new: <N extends number>(length: N) => FixedUint8Array<ArrayBuffer, N>;
7
+ fromBuffer: <B extends ArrayBufferLike, N extends number>(buffer: B, byteOffset: number, length: N) => FixedUint8Array<B, N>;
8
+ };
9
+ export { FixedUint8Array };
@@ -0,0 +1,7 @@
1
+ //#region lib/fixed_array.ts
2
+ var e = {
3
+ new: (e) => new Uint8Array(e),
4
+ fromBuffer: (e, t, n) => new Uint8Array(e, t, n)
5
+ };
6
+ //#endregion
7
+ export { e as FixedUint8Array };
@@ -3,64 +3,67 @@ export interface RationalData {
3
3
  /** `[numerator, denominator]` */
4
4
  value: [string, string];
5
5
  }
6
+ /**
7
+ * Fraction (rational) class
8
+ */
6
9
  export declare class Rational {
7
10
  #private;
8
11
  static readonly name = "Rational";
9
12
  /**
10
- * fraction (rational) class
13
+ *
11
14
  * @param numerator
12
15
  * @param denominator
13
16
  */
14
17
  constructor(numerator: bigint, denominator: bigint);
15
18
  /**
16
- * generates fraction from `number` decimal using continued fraction
19
+ * Generates fraction from `number` decimal using continued fraction
17
20
  * @param value decimal
18
21
  * @param denominatorDigits limit of digits of denominator
19
22
  */
20
23
  static fromDecimal(value: number, denominatorDigits?: number): Rational;
21
24
  /**
22
- * returns a fraction multiplied by -1
23
- * @returns
25
+ *
26
+ * @returns A fraction multiplied by -1
24
27
  */
25
28
  readonly minus: () => Rational;
26
29
  /**
27
- * returns inverse of this fraction
28
- * @returns
30
+ *
31
+ * @returns Inverse of this fraction
29
32
  */
30
33
  readonly inverse: () => Rational;
31
34
  /**
32
- * returns `this + right`
35
+ *
33
36
  * @param right
34
- * @returns
37
+ * @returns `this + right`
35
38
  */
36
39
  readonly add: (right: Rational) => Rational;
37
40
  /**
38
- * returns `this - right`
41
+ *
39
42
  * @param right
40
- * @returns
43
+ * @returns `this - right`
41
44
  */
42
45
  readonly substr: (right: Rational) => Rational;
43
46
  /**
44
- * returns `this * right`
47
+ *
45
48
  * @param right
46
- * @returns
49
+ * @returns `this * right`
47
50
  */
48
51
  readonly multiply: (right: Rational) => Rational;
49
52
  /**
50
- * returns `this / right`
53
+ *
51
54
  * @param right
52
- * @returns
55
+ * @returns `this / right`
53
56
  */
54
57
  readonly divide: (right: Rational) => Rational;
55
58
  /**
56
- * returns mediant
59
+ * Returns mediant
57
60
  * @param this `a / b`
58
61
  * @param right `c / d`
59
62
  * @returns `(a + c) / (b + d)`
60
63
  */
61
64
  readonly mediant: (right: Rational) => Rational;
62
65
  /**
63
- * returns `number` type decimal
66
+ * Returns `number` type decimal
64
67
  * @returns decimal
65
68
  */
66
69
  readonly toDecimal: () => number;
@@ -23,10 +23,10 @@ var t = "Rational", n = class n {
23
23
  }
24
24
  return new n(r ? -o : o, c);
25
25
  }
26
- #n() {
26
+ #n = () => {
27
27
  let { gcd: t } = e(this.#e, this.#t);
28
28
  t !== 0n && (this.#e /= t, this.#t /= t);
29
- }
29
+ };
30
30
  minus = () => new n(-this.#e, this.#t);
31
31
  inverse = () => new n(this.#t, this.#e);
32
32
  add = (e) => {
@@ -1,11 +1,16 @@
1
1
  export * from './util';
2
2
  export * from './math';
3
3
  export * from './baillie_psw';
4
+ export * from './base64';
5
+ export * from './compression';
6
+ export * from './equality';
4
7
  export * from './fraction';
5
- export * from './u8arr_ext';
8
+ export * from './fixed_array';
6
9
  export * from './named_error';
10
+ export * from './oct';
7
11
  export * from './random';
8
12
  export * from './pcg_minimal';
9
13
  export * from './xoshiro_minimal';
10
14
  export * from './async_worker';
15
+ export * from './async_worker_post';
11
16
  export * from './leb128';
package/dist/esm/index.js CHANGED
@@ -1,12 +1,18 @@
1
- import { AsyncWorker as e, postFailed as t, postSuccess as n } from "./async_worker.js";
2
- import { exEuclidean as r, factorial as i, getRandBIByBitLength as a, getRandBIByRange as o, getRndInt as s, isSquare as c, jacobiSymbol as l, modPow as u, residue as d, rot32 as f, rot64 as p } from "./math.js";
3
- import { i as m, n as h, r as g, t as _ } from "./baillie_psw-DzyqB4sZ.js";
4
- import { Rational as v } from "./fraction.js";
5
- import { decodeLEB128 as y, encodeLEB128 as b } from "./leb128.js";
6
- import { NamedError as x } from "./named_error.js";
7
- import { PCGMinimal as S } from "./pcg_minimal.js";
8
- import { floatRng as C } from "./random.js";
9
- import { fromBase64 as w, fromBase64URL as T, fromOct as E, toBase64 as D, toBase64URL as O, toOct as k } from "./u8arr_ext.js";
10
- import { compress as A, compressString as j, decodeRFC3986URIComponent as M, decompress as N, decompressString as P, encodeRFC3986URIComponent as F, getHash as I, getStringTag as L, isDeepStrictEqual as R, lazify as z, nullableStrictAt as B, parseCSV as V, sameValueZero as H, setTimeoutPromise as U, sleep as W, sleepSort as G, strictAt as K, withResolvers as q } from "./util.js";
11
- import { XoshiroMinimal as J } from "./xoshiro_minimal.js";
12
- export { e as AsyncWorker, x as NamedError, S as PCGMinimal, v as Rational, J as XoshiroMinimal, _ as bailliePSW, h as bailliePSWAsync, A as compress, j as compressString, y as decodeLEB128, M as decodeRFC3986URIComponent, N as decompress, P as decompressString, b as encodeLEB128, F as encodeRFC3986URIComponent, r as exEuclidean, i as factorial, C as floatRng, w as fromBase64, T as fromBase64URL, E as fromOct, I as getHash, a as getRandBIByBitLength, o as getRandBIByRange, g as getRandPrimeByBitLength, m as getRandPrimeByRange, s as getRndInt, L as getStringTag, R as isDeepStrictEqual, c as isSquare, l as jacobiSymbol, z as lazify, u as modPow, B as nullableStrictAt, V as parseCSV, t as postFailed, n as postSuccess, d as residue, f as rot32, p as rot64, H as sameValueZero, U as setTimeoutPromise, W as sleep, G as sleepSort, K as strictAt, D as toBase64, O as toBase64URL, k as toOct, q as withResolvers };
1
+ import { AsyncWorker as e } from "./async_worker.js";
2
+ import { postFailed as t, postSuccess as n } from "./async_worker_post.js";
3
+ import { n as r, t as i } from "./mod_pow-S-7GJ74l.js";
4
+ import { exEuclidean as a, factorial as o, isSquare as s, jacobiSymbol as c, rot32 as l, rot64 as u } from "./math.js";
5
+ import { floatRng as d, getRandBIByBitLength as f, getRandBIByRange as p, getRndInt as m } from "./random.js";
6
+ import { bailliePSW as h, bailliePSWAsync as g, getRandPrimeByBitLength as _, getRandPrimeByRange as v } from "./baillie_psw.js";
7
+ import { fromBase64 as y, fromBase64URL as b, toBase64 as x, toBase64URL as S } from "./base64.js";
8
+ import { compress as C, compressString as w, decompress as T, decompressString as E } from "./compression.js";
9
+ import { isDeepStrictEqual as D, sameValueZero as O } from "./equality.js";
10
+ import { Rational as k } from "./fraction.js";
11
+ import { FixedUint8Array as A } from "./fixed_array.js";
12
+ import { decodeLEB128 as j, encodeLEB128 as M } from "./leb128.js";
13
+ import { NamedError as N } from "./named_error.js";
14
+ import { fromOct as P, toOct as F } from "./oct.js";
15
+ import { PCGMinimal as I } from "./pcg_minimal.js";
16
+ import { decodeRFC3986URIComponent as L, encodeRFC3986URIComponent as R, getHash as z, getStringTag as B, lazify as V, nullableStrictAt as H, setTimeoutPromise as U, sleepSort as W, strictAt as G, withResolvers as K } from "./util.js";
17
+ import { XoshiroMinimal as q } from "./xoshiro_minimal.js";
18
+ export { e as AsyncWorker, A as FixedUint8Array, N as NamedError, I as PCGMinimal, k as Rational, q as XoshiroMinimal, h as bailliePSW, g as bailliePSWAsync, C as compress, w as compressString, j as decodeLEB128, L as decodeRFC3986URIComponent, T as decompress, E as decompressString, M as encodeLEB128, R as encodeRFC3986URIComponent, a as exEuclidean, o as factorial, d as floatRng, y as fromBase64, b as fromBase64URL, P as fromOct, z as getHash, f as getRandBIByBitLength, p as getRandBIByRange, _ as getRandPrimeByBitLength, v as getRandPrimeByRange, m as getRndInt, B as getStringTag, D as isDeepStrictEqual, s as isSquare, c as jacobiSymbol, V as lazify, i as modPow, H as nullableStrictAt, t as postFailed, n as postSuccess, r as residue, l as rot32, u as rot64, O as sameValueZero, U as setTimeoutPromise, W as sleepSort, G as strictAt, x as toBase64, S as toBase64URL, F as toOct, K as withResolvers };
@@ -1,2 +1,12 @@
1
+ /**
2
+ * Encode bigint to LEB128
3
+ * @param bigint
4
+ * @returns
5
+ */
1
6
  export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
7
+ /**
8
+ * Decode LEB128 into bigint
9
+ * @param LEB128
10
+ * @returns
11
+ */
2
12
  export declare const decodeLEB128: (LEB128: Uint8Array<ArrayBuffer>) => bigint;