@tempots/std 0.12.0 → 0.14.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/array.js CHANGED
@@ -1,188 +1,129 @@
1
1
  import { objectKeys as v } from "./object.js";
2
- function q(n, r) {
3
- return Array.from({ length: n.length }, (t, e) => r(n[e], e));
4
- }
5
- function B(n, r) {
6
- const t = [];
7
- for (const e of n)
8
- t.push(...r(e));
9
- return t;
10
- }
11
- function _(n) {
12
- return n.length > 0 ? n[0] : void 0;
13
- }
14
- function k(n) {
15
- return n.slice(1);
16
- }
17
- function F(n, r, t) {
18
- if (n.length !== r.length) return !1;
19
- for (let e = 0; e < n.length; e++)
20
- if (!t(n[e], r[e])) return !1;
2
+ const q = (t, n) => Array.from({ length: t.length }, (e, r) => n(t[r], r)), B = (t, n) => {
3
+ const e = [];
4
+ for (const r of t)
5
+ e.push(...n(r));
6
+ return e;
7
+ }, _ = (t) => t.length > 0 ? t[0] : void 0, k = (t) => t.slice(1), F = (t, n, e) => {
8
+ if (t.length !== n.length) return !1;
9
+ for (let r = 0; r < t.length; r++)
10
+ if (!e(t[r], n[r])) return !1;
21
11
  return !0;
22
- }
23
- function I(n) {
24
- return n.length === 0;
25
- }
26
- function M(n) {
27
- return n.length > 0;
28
- }
29
- function x(n, r) {
30
- const t = [];
31
- for (const e of n) r(e) && t.push(e);
32
- return t;
33
- }
34
- function b(n, r) {
35
- const t = [];
36
- for (let e = 0; e < n.length; e++) {
37
- const u = r(n[e], e);
38
- u != null && t.push(u);
12
+ }, I = (t) => t.length === 0, M = (t) => t.length > 0, x = (t, n) => {
13
+ const e = [];
14
+ for (const r of t) n(r) && e.push(r);
15
+ return e;
16
+ }, b = (t, n) => {
17
+ const e = [];
18
+ for (let r = 0; r < t.length; r++) {
19
+ const l = n(t[r], r);
20
+ l != null && e.push(l);
39
21
  }
40
- return t;
41
- }
42
- function j(n) {
43
- return x(n, (r) => r != null);
44
- }
45
- function D(n) {
46
- return [].concat(...n);
47
- }
48
- function P(n, r, t) {
49
- for (const e of n)
50
- t = r(t, e);
51
- return t;
52
- }
53
- function S(n, r) {
54
- for (const t of n)
55
- if (!r(t))
22
+ return e;
23
+ }, j = (t) => x(t, (n) => n != null), D = (t) => [].concat(...t), P = (t, n, e) => {
24
+ for (const r of t)
25
+ e = n(e, r);
26
+ return e;
27
+ }, S = (t, n) => {
28
+ for (const e of t)
29
+ if (!n(e))
56
30
  return !1;
57
31
  return !0;
58
- }
59
- function N(n, r) {
60
- for (const t of n)
61
- if (r(t))
32
+ }, N = (t, n) => {
33
+ for (const e of t)
34
+ if (n(e))
62
35
  return !0;
63
36
  return !1;
64
- }
65
- function T(n, r) {
66
- for (const t of n) r(t);
67
- }
68
- function $(...n) {
69
- return [].concat(...n);
70
- }
71
- function H(n, r, t, e = !0) {
72
- if (n.length < r.length)
73
- return -1 * (e ? 1 : -1);
74
- if (n.length > r.length)
75
- return 1 * (e ? 1 : -1);
76
- for (let u = 0; u < n.length; u++) {
77
- const l = t(n[u], r[u]);
78
- if (l !== 0) return l;
37
+ }, T = (t, n) => {
38
+ for (const e of t) n(e);
39
+ }, $ = (...t) => [].concat(...t), H = (t, n, e, r = !0) => {
40
+ if (t.length < n.length)
41
+ return -1 * (r ? 1 : -1);
42
+ if (t.length > n.length)
43
+ return 1 * (r ? 1 : -1);
44
+ for (let l = 0; l < t.length; l++) {
45
+ const a = e(t[l], n[l]);
46
+ if (a !== 0) return a;
79
47
  }
80
48
  return 0;
81
- }
82
- function C(n, r) {
83
- return n.slice().sort(r);
84
- }
85
- function g(n, r) {
86
- return Array.from({ length: n }, (t, e) => r(e));
87
- }
88
- function L(n, r = 0) {
89
- return g(n, (t) => r + t);
90
- }
91
- function R(n, r) {
92
- return g(n, () => r);
93
- }
94
- function V(n) {
95
- return Array.from(new Set(n));
96
- }
97
- function W(n, r) {
98
- const t = {};
99
- return n.forEach((e) => {
100
- t[r(e)] = e;
101
- }), v(t).map((e) => t[e]);
102
- }
103
- function E(n, r) {
104
- const t = n.indexOf(r);
105
- return t < 0 ? !1 : (n.splice(t, 1), !0);
106
- }
107
- function z(n, r) {
108
- let t = !1;
109
- for (; E(n, r); )
110
- t = !0;
111
- return t;
112
- }
113
- function w(n, r) {
114
- const t = n.findIndex(r);
115
- return t < 0 ? !1 : (n.splice(t, 1), !0);
116
- }
117
- function G(n, r) {
118
- let t = !1;
119
- for (; w(n, r); )
120
- t = !0;
121
- return t;
122
- }
123
- function J(n) {
124
- const r = [];
125
- for (let t = n.next(); !(t.done ?? !1); t = n.next())
126
- r.push(t.value);
127
- return r;
128
- }
129
- function Q(n, r, t) {
130
- const e = {
49
+ }, C = (t, n) => t.slice().sort(n), g = (t, n) => Array.from({ length: t }, (e, r) => n(r)), L = (t, n = 0) => g(t, (e) => n + e), R = (t, n) => g(t, () => n), V = (t) => Array.from(new Set(t)), W = (t, n) => {
50
+ const e = {};
51
+ return t.forEach((r) => {
52
+ e[n(r)] = r;
53
+ }), v(e).map((r) => e[r]);
54
+ }, E = (t, n) => {
55
+ const e = t.indexOf(n);
56
+ return e < 0 ? !1 : (t.splice(e, 1), !0);
57
+ }, z = (t, n) => {
58
+ let e = !1;
59
+ for (; E(t, n); )
60
+ e = !0;
61
+ return e;
62
+ }, w = (t, n) => {
63
+ const e = t.findIndex(n);
64
+ return e < 0 ? !1 : (t.splice(e, 1), !0);
65
+ }, G = (t, n) => {
66
+ let e = !1;
67
+ for (; w(t, n); )
68
+ e = !0;
69
+ return e;
70
+ }, J = (t) => {
71
+ const n = [];
72
+ for (let e = t.next(); !(e.done ?? !1); e = t.next())
73
+ n.push(e.value);
74
+ return n;
75
+ }, Q = (t, n, e) => {
76
+ const r = {
131
77
  removals: [],
132
78
  swaps: [],
133
79
  inserts: []
134
- }, { removals: u, inserts: l, swaps: c } = e, s = /* @__PURE__ */ new Map();
135
- r.forEach((o, f) => s.set(t(o), f));
136
- const a = n.map((o, f) => [o, f]).filter(([o]) => !s.has(t(o))).map(([o, f]) => f);
137
- for (let o = a.length - 1; o >= 0; o--) {
138
- const f = a[o], i = u.length > 0 ? u[u.length - 1] : void 0;
139
- i != null && i.at === f + 1 ? (i.at--, i.qt++) : u.push({ at: f, qt: 1 });
80
+ }, { removals: l, inserts: a, swaps: u } = r, c = /* @__PURE__ */ new Map();
81
+ n.forEach((s, o) => c.set(e(s), o));
82
+ const f = t.map((s, o) => [s, o]).filter(([s]) => !c.has(e(s))).map(([s, o]) => o);
83
+ for (let s = f.length - 1; s >= 0; s--) {
84
+ const o = f[s], i = l.length > 0 ? l[l.length - 1] : void 0;
85
+ i != null && i.at === o + 1 ? (i.at--, i.qt++) : l.push({ at: o, qt: 1 });
140
86
  }
141
87
  const h = /* @__PURE__ */ new Map();
142
- n.forEach((o, f) => h.set(t(o), f));
143
- const y = r.map((o, f) => [o, f]).filter(([o]) => !h.has(t(o))).map(([o, f]) => f);
144
- for (const o of y) {
145
- const f = l.length > 0 ? l[l.length - 1] : void 0;
146
- f != null && f.at + f.values.length === o ? f.values.push(r[o]) : l.push({ at: o, values: [r[o]] });
88
+ t.forEach((s, o) => h.set(e(s), o));
89
+ const y = n.map((s, o) => [s, o]).filter(([s]) => !h.has(e(s))).map(([s, o]) => o);
90
+ for (const s of y) {
91
+ const o = a.length > 0 ? a[a.length - 1] : void 0;
92
+ o != null && o.at + o.values.length === s ? o.values.push(n[s]) : a.push({ at: s, values: [n[s]] });
147
93
  }
148
- const p = n.filter((o, f) => !a.includes(f)), m = /* @__PURE__ */ new Map();
149
- for (let o = 0; o < p.length; o++)
150
- m.set(t(p[o]), o);
151
- const A = r.filter((o, f) => !y.includes(f));
152
- for (let o = 0; o < A.length; o++) {
153
- const f = t(A[o]), i = m.get(f);
154
- if (i == null || o === i) continue;
155
- const d = t(p[o]);
156
- m.delete(d), c.push({ from: o, to: i });
94
+ const p = t.filter((s, o) => !f.includes(o)), m = /* @__PURE__ */ new Map();
95
+ for (let s = 0; s < p.length; s++)
96
+ m.set(e(p[s]), s);
97
+ const A = n.filter((s, o) => !y.includes(o));
98
+ for (let s = 0; s < A.length; s++) {
99
+ const o = e(A[s]), i = m.get(o);
100
+ if (i == null || s === i) continue;
101
+ const d = e(p[s]);
102
+ m.delete(d), u.push({ from: s, to: i });
157
103
  }
158
- return e;
159
- }
160
- function U(n, r) {
161
- const t = [...r];
162
- for (const { at: e, qt: u } of n.removals)
163
- t.splice(e, u);
164
- for (const { from: e, to: u } of n.swaps) {
165
- const l = t[u];
166
- t[u] = t[e], t[e] = l;
104
+ return r;
105
+ }, U = (t, n) => {
106
+ const e = [...n];
107
+ for (const { at: r, qt: l } of t.removals)
108
+ e.splice(r, l);
109
+ for (const { from: r, to: l } of t.swaps) {
110
+ const a = e[l];
111
+ e[l] = e[r], e[r] = a;
167
112
  }
168
- for (const e of n.inserts)
169
- t.splice(e.at, 0, ...e.values);
170
- return t;
171
- }
172
- function X(n, r = " and ", t = ", ") {
173
- return n.length === 0 ? "" : n.length === 1 ? String(n[0]) : `${n.slice(0, -1).join(t)}${r}${String(n[n.length - 1])}`;
174
- }
175
- function Y(n, r, t = !0) {
176
- const e = n.map((s, a) => [s, a]);
177
- e.sort((s, a) => r(s[0], a[0]));
178
- const u = new Array(e.length);
179
- let l = 0, c = e[0][0];
180
- for (let s = 0; s < e.length; s++) {
181
- const [a, h] = e[s];
182
- r(a, c) !== 0 && (l = s, c = a), u[h] = l, t && l++;
113
+ for (const r of t.inserts)
114
+ e.splice(r.at, 0, ...r.values);
115
+ return e;
116
+ }, X = (t, n = " and ", e = ", ") => t.length === 0 ? "" : t.length === 1 ? String(t[0]) : `${t.slice(0, -1).join(e)}${n}${String(t[t.length - 1])}`, Y = (t, n, e = !0) => {
117
+ const r = t.map((c, f) => [c, f]);
118
+ r.sort((c, f) => n(c[0], f[0]));
119
+ const l = new Array(r.length);
120
+ let a = 0, u = r[0][0];
121
+ for (let c = 0; c < r.length; c++) {
122
+ const [f, h] = r[c];
123
+ n(f, u) !== 0 && (a = c, u = f), l[h] = a, e && a++;
183
124
  }
184
- return u;
185
- }
125
+ return l;
126
+ };
186
127
  export {
187
128
  S as allElements,
188
129
  N as anyElement,
package/async-result.d.ts CHANGED
@@ -4,35 +4,35 @@ import { Maybe } from './domain';
4
4
  * Represents the state when a result has not been requested yet.
5
5
  * @public
6
6
  */
7
- export interface NotAsked {
8
- type: 'NotAsked';
9
- }
7
+ export type NotAsked = {
8
+ readonly type: 'NotAsked';
9
+ };
10
10
  /**
11
11
  * Represents a loading state in an asynchronous result.
12
12
  * @public
13
13
  */
14
- export interface Loading<V> {
15
- type: 'Loading';
16
- previousValue?: V;
17
- }
14
+ export type Loading<V> = {
15
+ readonly type: 'Loading';
16
+ readonly previousValue?: V;
17
+ };
18
18
  /**
19
19
  * Represents a successful result.
20
20
  * @typeParam V - The type of the value.
21
21
  * @public
22
22
  */
23
- export interface AsyncSuccess<V> {
24
- type: 'AsyncSuccess';
25
- value: V;
26
- }
23
+ export type AsyncSuccess<V> = {
24
+ readonly type: 'AsyncSuccess';
25
+ readonly value: V;
26
+ };
27
27
  /**
28
28
  * Represents a failure result.
29
29
  * @typeParam E - - The type of the error.
30
30
  * @public
31
31
  */
32
- export interface AsyncFailure<E> {
33
- type: 'AsyncFailure';
34
- error: E;
35
- }
32
+ export type AsyncFailure<E> = {
33
+ readonly type: 'AsyncFailure';
34
+ readonly error: E;
35
+ };
36
36
  /**
37
37
  * Represents the result of an asynchronous operation that can be in one of the following states:
38
38
  * - `NotAsked`: The operation has not been requested yet.
package/bigint.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(n,i){return i<0n&&(n=-n,i=-i),n<=0n?n/i:(n-1n)/i+1n}function b(n,i){return i<0n&&(n=-n,i=-i),n>=0n?n/i:(n+1n)/i-1n}function f(n,i){return n<i?-1:n>i?1:0}function r(n){return n<0n?-n:n}function s(n,i){return n<i?n:i}function c(n,i){return n>i?n:i}function l(n,i){if(i<0n)throw new Error("negative exponent");let e=1n;for(;i>0n;)(i&1n)!==0n&&(e*=n),i>>=1n,n*=n;return e}function u(n,i){for(n=r(n),i=r(i);i>0n;){const e=i;i=n%i,n=e}return n}function v(n,i){return r(n*i)/u(n,i)}function t(n){if(n<2n)return!1;if(n===2n||n===3n)return!0;if(n%2n===0n||n%3n===0n)return!1;let i=5n;for(;i*i<=n;){if(n%i===0n||n%(i+2n)===0n)return!1;i+=6n}return!0}function I(n){if(n<2n)return 2n;if(n===2n)return 3n;for(n%2n===0n?n++:n+=2n;!t(n);)n+=2n;return n}function P(n){if(n<=2n)throw new Error("no previous prime");if(n===3n)return 2n;for(n%2n===0n?n--:n-=2n;!t(n);)n-=2n;return n}function a(n){return n%2n===0n}function m(n){return n%2n!==0n}function w(n){return n===0n}function d(n){return n===1n}function h(n){return n<0n}function p(n){return n>0n}exports.biAbs=r;exports.biCeilDiv=o;exports.biCompare=f;exports.biFloorDiv=b;exports.biGcd=u;exports.biIsEven=a;exports.biIsNegative=h;exports.biIsOdd=m;exports.biIsOne=d;exports.biIsPositive=p;exports.biIsPrime=t;exports.biIsZero=w;exports.biLcm=v;exports.biMax=c;exports.biMin=s;exports.biNextPrime=I;exports.biPow=l;exports.biPrevPrime=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./error.cjs"),b=(n,i)=>(i<0n&&(n=-n,i=-i),n<=0n?n/i:(n-1n)/i+1n),c=(n,i)=>(i<0n&&(n=-n,i=-i),n>=0n?n/i:(n+1n)/i-1n),u=(n,i)=>n<i?-1:n>i?1:0,r=n=>n<0n?-n:n,f=(n,i)=>n<i?n:i,l=(n,i)=>n>i?n:i,m=(n,i)=>{if(i<0n)throw new o.ArgumentError("negative exponent for parameter y of biPow");let e=1n;for(;i>0n;)(i&1n)!==0n&&(e*=n),i>>=1n,n*=n;return e},s=(n,i)=>{for(n=r(n),i=r(i);i>0n;){const e=i;i=n%i,n=e}return n},v=(n,i)=>r(n*i)/s(n,i),t=n=>{if(n<2n)return!1;if(n===2n||n===3n)return!0;if(n%2n===0n||n%3n===0n)return!1;let i=5n;for(;i*i<=n;){if(n%i===0n||n%(i+2n)===0n)return!1;i+=6n}return!0},P=n=>{if(n<2n)return 2n;if(n===2n)return 3n;for(n%2n===0n?n++:n+=2n;!t(n);)n+=2n;return n},a=n=>{if(n<=2n)throw new o.ArgumentError(`no previous prime ${n} for biPrevPrime`);if(n===3n)return 2n;for(n%2n===0n?n--:n-=2n;!t(n);)n-=2n;return n},I=n=>n%2n===0n,w=n=>n%2n!==0n,d=n=>n===0n,g=n=>n===1n,h=n=>n<0n,p=n=>n>0n;exports.biAbs=r;exports.biCeilDiv=b;exports.biCompare=u;exports.biFloorDiv=c;exports.biGcd=s;exports.biIsEven=I;exports.biIsNegative=h;exports.biIsOdd=w;exports.biIsOne=g;exports.biIsPositive=p;exports.biIsPrime=t;exports.biIsZero=d;exports.biLcm=v;exports.biMax=l;exports.biMin=f;exports.biNextPrime=P;exports.biPow=m;exports.biPrevPrime=a;
package/bigint.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * @returns The result of dividing `x` by `y`, rounded up to the nearest whole number.
7
7
  * @public
8
8
  */
9
- export declare function biCeilDiv(x: bigint, y: bigint): bigint;
9
+ export declare const biCeilDiv: (x: bigint, y: bigint) => bigint;
10
10
  /**
11
11
  * Divides two BigInt numbers and returns the largest integer less than or equal to the quotient.
12
12
  *
@@ -15,7 +15,7 @@ export declare function biCeilDiv(x: bigint, y: bigint): bigint;
15
15
  * @returns The largest integer less than or equal to the quotient of `x` divided by `y`.
16
16
  * @public
17
17
  */
18
- export declare function biFloorDiv(x: bigint, y: bigint): bigint;
18
+ export declare const biFloorDiv: (x: bigint, y: bigint) => bigint;
19
19
  /**
20
20
  * Compares two BigInt values and returns a number indicating their relative order.
21
21
  * @param x - The first BigInt value to compare.
@@ -24,7 +24,7 @@ export declare function biFloorDiv(x: bigint, y: bigint): bigint;
24
24
  * @public
25
25
  * or zero if `x` is equal to `y`.
26
26
  */
27
- export declare function biCompare(x: bigint, y: bigint): number;
27
+ export declare const biCompare: (x: bigint, y: bigint) => number;
28
28
  /**
29
29
  * Returns the absolute value of a bigint.
30
30
  *
@@ -32,7 +32,7 @@ export declare function biCompare(x: bigint, y: bigint): number;
32
32
  * @returns The absolute value of `x`.
33
33
  * @public
34
34
  */
35
- export declare function biAbs(x: bigint): bigint;
35
+ export declare const biAbs: (x: bigint) => bigint;
36
36
  /**
37
37
  * Returns the minimum of two BigInt values.
38
38
  *
@@ -41,7 +41,7 @@ export declare function biAbs(x: bigint): bigint;
41
41
  * @returns The smaller of the two BigInt values.
42
42
  * @public
43
43
  */
44
- export declare function biMin(x: bigint, y: bigint): bigint;
44
+ export declare const biMin: (x: bigint, y: bigint) => bigint;
45
45
  /**
46
46
  * Returns the maximum of two BigInt values.
47
47
  *
@@ -50,7 +50,7 @@ export declare function biMin(x: bigint, y: bigint): bigint;
50
50
  * @returns The maximum of the two BigInt values.
51
51
  * @public
52
52
  */
53
- export declare function biMax(x: bigint, y: bigint): bigint;
53
+ export declare const biMax: (x: bigint, y: bigint) => bigint;
54
54
  /**
55
55
  * Calculates the power of a bigint number.
56
56
  *
@@ -58,9 +58,9 @@ export declare function biMax(x: bigint, y: bigint): bigint;
58
58
  * @param y - The exponent.
59
59
  * @returns The result of raising `x` to the power of `y`.
60
60
  * @public
61
- * @throws Error If the exponent `y` is negative.
61
+ * @throws Throws `ArgumentError` if the exponent `y` is negative.
62
62
  */
63
- export declare function biPow(x: bigint, y: bigint): bigint;
63
+ export declare const biPow: (x: bigint, y: bigint) => bigint;
64
64
  /**
65
65
  * Calculates the greatest common divisor (GCD) of two BigInt numbers.
66
66
  *
@@ -69,7 +69,7 @@ export declare function biPow(x: bigint, y: bigint): bigint;
69
69
  * @returns The GCD of `x` and `y`.
70
70
  * @public
71
71
  */
72
- export declare function biGcd(x: bigint, y: bigint): bigint;
72
+ export declare const biGcd: (x: bigint, y: bigint) => bigint;
73
73
  /**
74
74
  * Calculates the least common multiple (LCM) of two BigInt numbers.
75
75
  *
@@ -78,7 +78,7 @@ export declare function biGcd(x: bigint, y: bigint): bigint;
78
78
  * @returns The least common multiple of `x` and `y`.
79
79
  * @public
80
80
  */
81
- export declare function biLcm(x: bigint, y: bigint): bigint;
81
+ export declare const biLcm: (x: bigint, y: bigint) => bigint;
82
82
  /**
83
83
  * Checks if a given number is prime.
84
84
  *
@@ -86,7 +86,7 @@ export declare function biLcm(x: bigint, y: bigint): bigint;
86
86
  * @returns `true` if the number is prime, `false` otherwise.
87
87
  * @public
88
88
  */
89
- export declare function biIsPrime(x: bigint): boolean;
89
+ export declare const biIsPrime: (x: bigint) => boolean;
90
90
  /**
91
91
  * Finds the next prime number greater than the given number.
92
92
  *
@@ -94,7 +94,7 @@ export declare function biIsPrime(x: bigint): boolean;
94
94
  * @returns The next prime number greater than `x`.
95
95
  * @public
96
96
  */
97
- export declare function biNextPrime(x: bigint): bigint;
97
+ export declare const biNextPrime: (x: bigint) => bigint;
98
98
  /**
99
99
  * Returns the previous prime number less than the given number.
100
100
  * Throws an error if there is no previous prime.
@@ -102,9 +102,9 @@ export declare function biNextPrime(x: bigint): bigint;
102
102
  * @param x - The number to find the previous prime for.
103
103
  * @returns The previous prime number less than `x`.
104
104
  * @public
105
- * @throws Error if there is no previous prime.
105
+ * @throws Throws `ArgumentError` if there is no previous prime.
106
106
  */
107
- export declare function biPrevPrime(x: bigint): bigint;
107
+ export declare const biPrevPrime: (x: bigint) => bigint;
108
108
  /**
109
109
  * Checks if a given bigint is even.
110
110
  *
@@ -112,7 +112,7 @@ export declare function biPrevPrime(x: bigint): bigint;
112
112
  * @returns `true` if the bigint is even, `false` otherwise.
113
113
  * @public
114
114
  */
115
- export declare function biIsEven(x: bigint): boolean;
115
+ export declare const biIsEven: (x: bigint) => boolean;
116
116
  /**
117
117
  * Checks if a given bigint is odd.
118
118
  *
@@ -120,7 +120,7 @@ export declare function biIsEven(x: bigint): boolean;
120
120
  * @returns `true` if the bigint is odd, `false` otherwise.
121
121
  * @public
122
122
  */
123
- export declare function biIsOdd(x: bigint): boolean;
123
+ export declare const biIsOdd: (x: bigint) => boolean;
124
124
  /**
125
125
  * Checks if a given bigint is zero.
126
126
  *
@@ -128,7 +128,7 @@ export declare function biIsOdd(x: bigint): boolean;
128
128
  * @returns `true` if the bigint is zero, `false` otherwise.
129
129
  * @public
130
130
  */
131
- export declare function biIsZero(x: bigint): boolean;
131
+ export declare const biIsZero: (x: bigint) => boolean;
132
132
  /**
133
133
  * Checks if a given bigint is equal to 1n.
134
134
  *
@@ -136,7 +136,7 @@ export declare function biIsZero(x: bigint): boolean;
136
136
  * @returns `true` if the bigint is equal to 1n, `false` otherwise.
137
137
  * @public
138
138
  */
139
- export declare function biIsOne(x: bigint): boolean;
139
+ export declare const biIsOne: (x: bigint) => boolean;
140
140
  /**
141
141
  * Checks if a given bigint is negative.
142
142
  *
@@ -144,7 +144,7 @@ export declare function biIsOne(x: bigint): boolean;
144
144
  * @returns `true` if the bigint is negative, `false` otherwise.
145
145
  * @public
146
146
  */
147
- export declare function biIsNegative(x: bigint): boolean;
147
+ export declare const biIsNegative: (x: bigint) => boolean;
148
148
  /**
149
149
  * Checks if a bigint is positive.
150
150
  *
@@ -152,4 +152,4 @@ export declare function biIsNegative(x: bigint): boolean;
152
152
  * @returns `true` if the bigint is positive, `false` otherwise.
153
153
  * @public
154
154
  */
155
- export declare function biIsPositive(x: bigint): boolean;
155
+ export declare const biIsPositive: (x: bigint) => boolean;
package/bigint.js CHANGED
@@ -1,96 +1,55 @@
1
- function f(n, r) {
2
- return r < 0n && (n = -n, r = -r), n <= 0n ? n / r : (n - 1n) / r + 1n;
3
- }
4
- function o(n, r) {
5
- return r < 0n && (n = -n, r = -r), n >= 0n ? n / r : (n + 1n) / r - 1n;
6
- }
7
- function c(n, r) {
8
- return n < r ? -1 : n > r ? 1 : 0;
9
- }
10
- function e(n) {
11
- return n < 0n ? -n : n;
12
- }
13
- function b(n, r) {
14
- return n < r ? n : r;
15
- }
16
- function s(n, r) {
17
- return n > r ? n : r;
18
- }
19
- function l(n, r) {
20
- if (r < 0n) throw new Error("negative exponent");
1
+ import { ArgumentError as t } from "./error.js";
2
+ const c = (n, e) => (e < 0n && (n = -n, e = -e), n <= 0n ? n / e : (n - 1n) / e + 1n), f = (n, e) => (e < 0n && (n = -n, e = -e), n >= 0n ? n / e : (n + 1n) / e - 1n), u = (n, e) => n < e ? -1 : n > e ? 1 : 0, r = (n) => n < 0n ? -n : n, l = (n, e) => n < e ? n : e, m = (n, e) => n > e ? n : e, w = (n, e) => {
3
+ if (e < 0n)
4
+ throw new t("negative exponent for parameter y of biPow");
21
5
  let i = 1n;
22
- for (; r > 0n; )
23
- (r & 1n) !== 0n && (i *= n), r >>= 1n, n *= n;
6
+ for (; e > 0n; )
7
+ (e & 1n) !== 0n && (i *= n), e >>= 1n, n *= n;
24
8
  return i;
25
- }
26
- function u(n, r) {
27
- for (n = e(n), r = e(r); r > 0n; ) {
28
- const i = r;
29
- r = n % r, n = i;
9
+ }, s = (n, e) => {
10
+ for (n = r(n), e = r(e); e > 0n; ) {
11
+ const i = e;
12
+ e = n % e, n = i;
30
13
  }
31
14
  return n;
32
- }
33
- function w(n, r) {
34
- return e(n * r) / u(n, r);
35
- }
36
- function t(n) {
15
+ }, a = (n, e) => r(n * e) / s(n, e), o = (n) => {
37
16
  if (n < 2n) return !1;
38
17
  if (n === 2n || n === 3n) return !0;
39
18
  if (n % 2n === 0n || n % 3n === 0n) return !1;
40
- let r = 5n;
41
- for (; r * r <= n; ) {
42
- if (n % r === 0n || n % (r + 2n) === 0n) return !1;
43
- r += 6n;
19
+ let e = 5n;
20
+ for (; e * e <= n; ) {
21
+ if (n % e === 0n || n % (e + 2n) === 0n) return !1;
22
+ e += 6n;
44
23
  }
45
24
  return !0;
46
- }
47
- function v(n) {
25
+ }, v = (n) => {
48
26
  if (n < 2n) return 2n;
49
27
  if (n === 2n) return 3n;
50
- for (n % 2n === 0n ? n++ : n += 2n; !t(n); ) n += 2n;
28
+ for (n % 2n === 0n ? n++ : n += 2n; !o(n); ) n += 2n;
51
29
  return n;
52
- }
53
- function a(n) {
54
- if (n <= 2n) throw new Error("no previous prime");
30
+ }, P = (n) => {
31
+ if (n <= 2n) throw new t(`no previous prime ${n} for biPrevPrime`);
55
32
  if (n === 3n) return 2n;
56
- for (n % 2n === 0n ? n-- : n -= 2n; !t(n); ) n -= 2n;
33
+ for (n % 2n === 0n ? n-- : n -= 2n; !o(n); ) n -= 2n;
57
34
  return n;
58
- }
59
- function h(n) {
60
- return n % 2n === 0n;
61
- }
62
- function I(n) {
63
- return n % 2n !== 0n;
64
- }
65
- function m(n) {
66
- return n === 0n;
67
- }
68
- function P(n) {
69
- return n === 1n;
70
- }
71
- function p(n) {
72
- return n < 0n;
73
- }
74
- function d(n) {
75
- return n > 0n;
76
- }
35
+ }, h = (n) => n % 2n === 0n, p = (n) => n % 2n !== 0n, I = (n) => n === 0n, d = (n) => n === 1n, g = (n) => n < 0n, A = (n) => n > 0n;
77
36
  export {
78
- e as biAbs,
79
- f as biCeilDiv,
80
- c as biCompare,
81
- o as biFloorDiv,
82
- u as biGcd,
37
+ r as biAbs,
38
+ c as biCeilDiv,
39
+ u as biCompare,
40
+ f as biFloorDiv,
41
+ s as biGcd,
83
42
  h as biIsEven,
84
- p as biIsNegative,
85
- I as biIsOdd,
86
- P as biIsOne,
87
- d as biIsPositive,
88
- t as biIsPrime,
89
- m as biIsZero,
90
- w as biLcm,
91
- s as biMax,
92
- b as biMin,
43
+ g as biIsNegative,
44
+ p as biIsOdd,
45
+ d as biIsOne,
46
+ A as biIsPositive,
47
+ o as biIsPrime,
48
+ I as biIsZero,
49
+ a as biLcm,
50
+ m as biMax,
51
+ l as biMin,
93
52
  v as biNextPrime,
94
- l as biPow,
95
- a as biPrevPrime
53
+ w as biPow,
54
+ P as biPrevPrime
96
55
  };
package/boolean.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(e,o){return e===o?0:e?-1:1}function n(e){return e?1:0}function r(e){if(e==null)return!1;switch(e.toLowerCase()){case"true":case"false":case"0":case"1":case"on":case"off":return!0;default:return!1}}function t(e){switch(e.toLowerCase()){case"true":case"1":case"on":return!0;case"false":case"0":case"off":return!1;default:throw new Error(`unable to parse '${e}'`)}}function s(e,o){return e!==o}exports.booleanToInt=n;exports.canParseBoolean=r;exports.compareBooleans=a;exports.parseBoolean=t;exports.xorBoolean=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./error.cjs"),r=(e,o)=>e===o?0:e?-1:1,s=e=>e?1:0,n=e=>{if(e==null)return!1;switch(e.toLowerCase()){case"true":case"false":case"0":case"1":case"on":case"off":return!0;default:return!1}},t=e=>{switch(e.toLowerCase()){case"true":case"1":case"on":return!0;case"false":case"0":case"off":return!1;default:throw new a.ParsingError(`unable to parse '${e}' to boolean`)}},c=(e,o)=>e!==o;exports.booleanToInt=s;exports.canParseBoolean=n;exports.compareBooleans=r;exports.parseBoolean=t;exports.xorBoolean=c;