@tempots/std 0.9.7 → 0.10.3

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 (106) hide show
  1. package/README.md +1 -3
  2. package/array.cjs +1 -0
  3. package/{arrays.d.ts → array.d.ts} +7 -7
  4. package/array.js +223 -0
  5. package/bigint.cjs +1 -0
  6. package/bigint.js +96 -110
  7. package/boolean.cjs +1 -0
  8. package/boolean.js +44 -0
  9. package/domain.cjs +1 -0
  10. package/domain.d.ts +22 -0
  11. package/domain.js +1 -0
  12. package/equal.cjs +1 -0
  13. package/equal.js +68 -0
  14. package/function.cjs +1 -0
  15. package/function.js +29 -0
  16. package/index.cjs +1 -0
  17. package/index.d.ts +0 -0
  18. package/index.js +1 -0
  19. package/maybe.cjs +1 -0
  20. package/maybe.d.ts +3 -3
  21. package/maybe.js +8 -24
  22. package/number.cjs +1 -0
  23. package/{numbers.d.ts → number.d.ts} +2 -5
  24. package/number.js +103 -0
  25. package/object.cjs +1 -0
  26. package/object.d.ts +8 -0
  27. package/object.js +30 -0
  28. package/package.json +55 -25
  29. package/regexp.cjs +1 -0
  30. package/regexp.js +14 -0
  31. package/string.cjs +3 -0
  32. package/{strings.d.ts → string.d.ts} +0 -2
  33. package/string.js +396 -0
  34. package/arrays.js +0 -249
  35. package/async-result.d.ts +0 -37
  36. package/async-result.js +0 -75
  37. package/booleans.js +0 -68
  38. package/colors/cmyk.d.ts +0 -21
  39. package/colors/cmyk.js +0 -54
  40. package/colors/convert.d.ts +0 -283
  41. package/colors/convert.js +0 -742
  42. package/colors/hsl.d.ts +0 -24
  43. package/colors/hsl.js +0 -56
  44. package/colors/hsla.d.ts +0 -18
  45. package/colors/hsla.js +0 -35
  46. package/colors/hsluv.d.ts +0 -24
  47. package/colors/hsluv.js +0 -56
  48. package/colors/hsv.d.ts +0 -24
  49. package/colors/hsv.js +0 -54
  50. package/colors/lab.d.ts +0 -24
  51. package/colors/lab.js +0 -54
  52. package/colors/lch.d.ts +0 -19
  53. package/colors/lch.js +0 -44
  54. package/colors/luv.d.ts +0 -19
  55. package/colors/luv.js +0 -45
  56. package/colors/rgb.d.ts +0 -13
  57. package/colors/rgb.js +0 -47
  58. package/colors/rgba.d.ts +0 -12
  59. package/colors/rgba.js +0 -44
  60. package/colors/srgb.d.ts +0 -24
  61. package/colors/srgb.js +0 -51
  62. package/colors/xyz.d.ts +0 -19
  63. package/colors/xyz.js +0 -41
  64. package/edit.d.ts +0 -20
  65. package/edit.js +0 -29
  66. package/equals.js +0 -122
  67. package/functions.js +0 -38
  68. package/json.d.ts +0 -14
  69. package/json.js +0 -33
  70. package/match.d.ts +0 -16
  71. package/match.js +0 -45
  72. package/memoize.d.ts +0 -1
  73. package/memoize.js +0 -9
  74. package/newtype.d.ts +0 -28
  75. package/newtype.js +0 -29
  76. package/numbers.js +0 -183
  77. package/objects.d.ts +0 -9
  78. package/objects.js +0 -33
  79. package/ord.d.ts +0 -19
  80. package/ord.js +0 -73
  81. package/reg-exps.js +0 -43
  82. package/result.d.ts +0 -31
  83. package/result.js +0 -95
  84. package/strings.js +0 -685
  85. package/types/assert.d.ts +0 -12
  86. package/types/assert.js +0 -13
  87. package/types/differentiate.d.ts +0 -13
  88. package/types/differentiate.js +0 -14
  89. package/types/functions.d.ts +0 -22
  90. package/types/functions.js +0 -13
  91. package/types/generic.d.ts +0 -9
  92. package/types/generic.js +0 -13
  93. package/types/objects.d.ts +0 -50
  94. package/types/objects.js +0 -13
  95. package/types/tuples.d.ts +0 -44
  96. package/types/tuples.js +0 -24
  97. package/types/utility.d.ts +0 -2
  98. package/types/utility.js +0 -1
  99. package/uuid.d.ts +0 -13
  100. package/uuid.js +0 -56
  101. package/validation.d.ts +0 -23
  102. package/validation.js +0 -44
  103. /package/{booleans.d.ts → boolean.d.ts} +0 -0
  104. /package/{equals.d.ts → equal.d.ts} +0 -0
  105. /package/{functions.d.ts → function.d.ts} +0 -0
  106. /package/{reg-exps.d.ts → regexp.d.ts} +0 -0
package/README.md CHANGED
@@ -1,3 +1 @@
1
- # @tempots/std
2
-
3
- A standard library for TypeScript.
1
+ # Tempo Standard Library
package/array.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./maybe.cjs"),M=require("./object.cjs");function q(t,e){return Array.from({length:t.length},(n,r)=>e(t[r],r))}function E(t,e){const n=[];for(let r=0;r<t.length;r++){const i=e(t[r],r);i!=null&&n.push(i)}return n}function j(t,e){const n=[];for(const r of t)n.push(...e(r));return n}function w(t){return t.length>0?y.Maybe.just(t[0]):y.Maybe.nothing}function A(t){return t.slice(1)}function b(t,e,n){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!n(t[r],e[r]))return!1;return!0}function N(t){return function(e,n){return b(e,n,t)}}function O(t){return t.length===0}function B(t){return t.length>0}function k(t,e){const n=[];for(const r of t)e(r)&&n.push(r);return n}function I(t,e){const n=[];for(let r=0;r<t.length;r++){const i=e(t[r],r);i!=null&&n.push(i)}return n}function P(t){return k(t,e=>e!=null)}function _(t){return[].concat(...t)}function S(t,e,n){for(const r of t)n=e(n,r);return n}function C(t,e){for(const n of t)if(!e(n))return!1;return!0}function R(t,e){for(const n of t)if(e(n))return!0;return!1}function T(t,e){for(const n of t)e(n)}function $(...t){return[].concat(...t)}function D(t,e=!0){return function(n,r){if(n.length<r.length)return-1*(e?1:-1);if(n.length>r.length)return 1*(e?1:-1);for(let i=0;i<n.length;i++){const u=t(n[i],r[i]);if(u!==0)return u}return 0}}function L(t,e){return e.slice().sort(t)}function d(t,e){return Array.from({length:t},(n,r)=>e(r))}function V(t,e=0){return d(t,n=>e+n)}function W(t,e){return d(t,()=>e)}function z(t){return Array.from(new Set(t))}function G(t,e){const n={};return t.forEach(r=>{n[e(r)]=r}),M.keys(n).map(r=>n[r])}function H(t,e){const n=t.indexOf(e);return n<0?!1:(t.splice(n,1),!0)}function J(t,e){const n=t.findIndex(e);return n<0?!1:(t.splice(n,1),!0)}function Q(t){const e=[];for(let n=t.next();!(n.done??!1);n=t.next())e.push(n.value);return e}function U(t,e,n){const r={removals:[],swaps:[],inserts:[]},{removals:i,inserts:u,swaps:a}=r,l=new Map;e.forEach((o,f)=>l.set(n(o),f));const s=t.map((o,f)=>[o,f]).filter(([o])=>!l.has(n(o))).map(([o,f])=>f);for(let o=s.length-1;o>=0;o--){const f=s[o],c=i.length>0?i[i.length-1]:void 0;c!=null&&c.at===f+1?(c.at--,c.qt++):i.push({at:f,qt:1})}const h=new Map;t.forEach((o,f)=>h.set(n(o),f));const g=e.map((o,f)=>[o,f]).filter(([o])=>!h.has(n(o))).map(([o,f])=>f);for(const o of g){const f=u.length>0?u[u.length-1]:void 0;f!=null&&f.at+f.values.length===o?f.values.push(e[o]):u.push({at:o,values:[e[o]]})}const p=t.filter((o,f)=>!s.includes(f)),m=new Map;for(let o=0;o<p.length;o++)m.set(n(p[o]),o);const v=e.filter((o,f)=>!g.includes(f));for(let o=0;o<v.length;o++){const f=n(v[o]),c=m.get(f);if(c==null||o===c)continue;const x=n(p[o]);m.delete(x),a.push({from:o,to:c})}return r}function X(t,e){const n=[...e];for(const{at:r,qt:i}of t.removals)n.splice(r,i);for(const{from:r,to:i}of t.swaps){const u=n[i];n[i]=n[r],n[r]=u}for(const r of t.inserts)n.splice(r.at,0,...r.values);return n}function Y(t,e=" and ",n=", "){return t.length===0?"":t.length===1?String(t[0]):`${t.slice(0,-1).join(n)}${e}${String(t[t.length-1])}`}function Z(t,e,n=!0){const r=t.map((l,s)=>[l,s]);r.sort((l,s)=>e(l[0],s[0]));const i=new Array(r.length);let u=0,a=r[0][0];for(let l=0;l<r.length;l++){const[s,h]=r[l];e(s,a)!==0&&(u=l,a=s),i[h]=u,n&&u++}return i}exports.all=C;exports.any=R;exports.applyOperations=X;exports.concat=$;exports.diffOperations=U;exports.distinctByPredicate=G;exports.distinctPrimitive=z;exports.each=T;exports.equals=b;exports.fill=W;exports.filter=k;exports.filterMap=I;exports.filterNulls=P;exports.flatMap=j;exports.flatten=_;exports.foldLeft=S;exports.hasValues=B;exports.head=w;exports.isEmpty=O;exports.joinWithConjunction=Y;exports.makeCompare=D;exports.makeEquals=N;exports.map=q;exports.mapNotNull=E;exports.numbersRange=V;exports.ofIterableIterator=Q;exports.range=d;exports.rank=Z;exports.remove=H;exports.removeByPredicate=J;exports.sort=L;exports.tail=A;
@@ -1,9 +1,6 @@
1
- /**
2
- * Utility functions to manipulate `Array` values.
3
- */
4
1
  import { Maybe } from './maybe';
5
- import { type Ordering, type Compare } from './ord';
6
- import { type Primitive } from './types/utility';
2
+ import { Compare, Primitive } from './domain';
3
+
7
4
  export declare function map<A, B>(arr: A[], f: (a: A, index: number) => B): B[];
8
5
  export declare function mapNotNull<A, B>(arr: A[], f: (a: A, index: number) => B | null | undefined): B[];
9
6
  export declare function flatMap<A, B>(arr: A[], f: (a: A) => B[]): B[];
@@ -14,6 +11,7 @@ export declare function makeEquals<T>(equality: (a: T, b: T) => boolean): (a: T[
14
11
  export declare function isEmpty<T>(arr: T[]): arr is [];
15
12
  export declare function hasValues<T>(arr: T[]): arr is [T, ...T[]];
16
13
  export declare function filter<T>(arr: T[], predicate: (v: T) => boolean): T[];
14
+ export declare function filterMap<A, B>(arr: A[], f: (a: A, index: number) => Maybe<B>): B[];
17
15
  export declare function filterNulls<T>(arr: Array<T | null | undefined>): T[];
18
16
  export declare function flatten<T>(arr: T[][]): T[];
19
17
  export declare function foldLeft<T, B>(arr: T[], f: (acc: B, curr: T) => B, b: B): B;
@@ -22,13 +20,14 @@ export declare function any<T>(arr: T[], predicate: (v: T) => boolean): boolean;
22
20
  export declare function each<T>(arr: T[], f: (v: T) => void): void;
23
21
  export declare function concat<A>(...arrs: A[][]): A[];
24
22
  export declare function makeCompare<A>(comparef: Compare<A>, shorterFirst?: boolean): (a: A[], b: A[]) => number;
25
- export declare function sort<A>(compare: (a: A, b: A) => Ordering, arr: A[]): A[];
23
+ export declare function sort<A>(compare: Compare<A>, arr: A[]): A[];
26
24
  export declare function range<A>(length: number, f: (index: number) => A): A[];
27
25
  export declare function numbersRange(length: number, startAt?: number): number[];
28
26
  export declare function fill<A>(length: number, value: A): A[];
29
27
  export declare function distinctPrimitive<T extends Primitive>(values: T[]): T[];
30
28
  export declare function distinctByPredicate<T>(values: T[], predicate: (a: T) => string): T[];
31
- export declare function remove<A>(arr: A[], item: A, predicate?: (a: A) => boolean): boolean;
29
+ export declare function remove<A>(arr: A[], item: A): boolean;
30
+ export declare function removeByPredicate<A>(arr: A[], predicate: (a: A) => boolean): boolean;
32
31
  export declare function ofIterableIterator<A>(it: IterableIterator<A>): A[];
33
32
  export interface DiffOperations<T> {
34
33
  removals: Array<{
@@ -47,3 +46,4 @@ export interface DiffOperations<T> {
47
46
  export declare function diffOperations<T, K>(from: T[], to: T[], getKey: (v: T) => K): DiffOperations<T>;
48
47
  export declare function applyOperations<T>(operations: DiffOperations<T>, start: T[]): T[];
49
48
  export declare function joinWithConjunction<A>(arr: A[], conjunction?: string, separator?: string): string;
49
+ export declare function rank<T>(array: T[], compare: (a: T, b: T) => number, incrementDuplicates?: boolean): number[];
package/array.js ADDED
@@ -0,0 +1,223 @@
1
+ import { Maybe as v } from "./maybe.js";
2
+ import { keys as w } from "./object.js";
3
+ function _(n, e) {
4
+ return Array.from({ length: n.length }, (t, r) => e(n[r], r));
5
+ }
6
+ function q(n, e) {
7
+ const t = [];
8
+ for (let r = 0; r < n.length; r++) {
9
+ const u = e(n[r], r);
10
+ u != null && t.push(u);
11
+ }
12
+ return t;
13
+ }
14
+ function y(n, e) {
15
+ const t = [];
16
+ for (const r of n)
17
+ t.push(...e(r));
18
+ return t;
19
+ }
20
+ function B(n) {
21
+ return n.length > 0 ? v.just(n[0]) : v.nothing;
22
+ }
23
+ function I(n) {
24
+ return n.slice(1);
25
+ }
26
+ function A(n, e, t) {
27
+ if (n.length !== e.length) return !1;
28
+ for (let r = 0; r < n.length; r++)
29
+ if (!t(n[r], e[r])) return !1;
30
+ return !0;
31
+ }
32
+ function N(n) {
33
+ return function(e, t) {
34
+ return A(e, t, n);
35
+ };
36
+ }
37
+ function O(n) {
38
+ return n.length === 0;
39
+ }
40
+ function j(n) {
41
+ return n.length > 0;
42
+ }
43
+ function E(n, e) {
44
+ const t = [];
45
+ for (const r of n) e(r) && t.push(r);
46
+ return t;
47
+ }
48
+ function P(n, e) {
49
+ const t = [];
50
+ for (let r = 0; r < n.length; r++) {
51
+ const u = e(n[r], r);
52
+ u != null && t.push(u);
53
+ }
54
+ return t;
55
+ }
56
+ function S(n) {
57
+ return E(n, (e) => e != null);
58
+ }
59
+ function $(n) {
60
+ return [].concat(...n);
61
+ }
62
+ function C(n, e, t) {
63
+ for (const r of n)
64
+ t = e(t, r);
65
+ return t;
66
+ }
67
+ function D(n, e) {
68
+ for (const t of n)
69
+ if (!e(t))
70
+ return !1;
71
+ return !0;
72
+ }
73
+ function R(n, e) {
74
+ for (const t of n)
75
+ if (e(t))
76
+ return !0;
77
+ return !1;
78
+ }
79
+ function T(n, e) {
80
+ for (const t of n) e(t);
81
+ }
82
+ function L(...n) {
83
+ return [].concat(...n);
84
+ }
85
+ function V(n, e = !0) {
86
+ return function(t, r) {
87
+ if (t.length < r.length)
88
+ return -1 * (e ? 1 : -1);
89
+ if (t.length > r.length)
90
+ return 1 * (e ? 1 : -1);
91
+ for (let u = 0; u < t.length; u++) {
92
+ const s = n(t[u], r[u]);
93
+ if (s !== 0) return s;
94
+ }
95
+ return 0;
96
+ };
97
+ }
98
+ function W(n, e) {
99
+ return e.slice().sort(n);
100
+ }
101
+ function x(n, e) {
102
+ return Array.from({ length: n }, (t, r) => e(r));
103
+ }
104
+ function z(n, e = 0) {
105
+ return x(n, (t) => e + t);
106
+ }
107
+ function G(n, e) {
108
+ return x(n, () => e);
109
+ }
110
+ function H(n) {
111
+ return Array.from(new Set(n));
112
+ }
113
+ function J(n, e) {
114
+ const t = {};
115
+ return n.forEach((r) => {
116
+ t[e(r)] = r;
117
+ }), w(t).map((r) => t[r]);
118
+ }
119
+ function Q(n, e) {
120
+ const t = n.indexOf(e);
121
+ return t < 0 ? !1 : (n.splice(t, 1), !0);
122
+ }
123
+ function U(n, e) {
124
+ const t = n.findIndex(e);
125
+ return t < 0 ? !1 : (n.splice(t, 1), !0);
126
+ }
127
+ function X(n) {
128
+ const e = [];
129
+ for (let t = n.next(); !(t.done ?? !1); t = n.next())
130
+ e.push(t.value);
131
+ return e;
132
+ }
133
+ function Y(n, e, t) {
134
+ const r = {
135
+ removals: [],
136
+ swaps: [],
137
+ inserts: []
138
+ }, { removals: u, inserts: s, swaps: a } = r, i = /* @__PURE__ */ new Map();
139
+ e.forEach((o, f) => i.set(t(o), f));
140
+ const l = n.map((o, f) => [o, f]).filter(([o]) => !i.has(t(o))).map(([o, f]) => f);
141
+ for (let o = l.length - 1; o >= 0; o--) {
142
+ const f = l[o], c = u.length > 0 ? u[u.length - 1] : void 0;
143
+ c != null && c.at === f + 1 ? (c.at--, c.qt++) : u.push({ at: f, qt: 1 });
144
+ }
145
+ const h = /* @__PURE__ */ new Map();
146
+ n.forEach((o, f) => h.set(t(o), f));
147
+ const g = e.map((o, f) => [o, f]).filter(([o]) => !h.has(t(o))).map(([o, f]) => f);
148
+ for (const o of g) {
149
+ const f = s.length > 0 ? s[s.length - 1] : void 0;
150
+ f != null && f.at + f.values.length === o ? f.values.push(e[o]) : s.push({ at: o, values: [e[o]] });
151
+ }
152
+ const p = n.filter((o, f) => !l.includes(f)), m = /* @__PURE__ */ new Map();
153
+ for (let o = 0; o < p.length; o++)
154
+ m.set(t(p[o]), o);
155
+ const d = e.filter((o, f) => !g.includes(f));
156
+ for (let o = 0; o < d.length; o++) {
157
+ const f = t(d[o]), c = m.get(f);
158
+ if (c == null || o === c) continue;
159
+ const k = t(p[o]);
160
+ m.delete(k), a.push({ from: o, to: c });
161
+ }
162
+ return r;
163
+ }
164
+ function Z(n, e) {
165
+ const t = [...e];
166
+ for (const { at: r, qt: u } of n.removals)
167
+ t.splice(r, u);
168
+ for (const { from: r, to: u } of n.swaps) {
169
+ const s = t[u];
170
+ t[u] = t[r], t[r] = s;
171
+ }
172
+ for (const r of n.inserts)
173
+ t.splice(r.at, 0, ...r.values);
174
+ return t;
175
+ }
176
+ function F(n, e = " and ", t = ", ") {
177
+ return n.length === 0 ? "" : n.length === 1 ? String(n[0]) : `${n.slice(0, -1).join(t)}${e}${String(n[n.length - 1])}`;
178
+ }
179
+ function K(n, e, t = !0) {
180
+ const r = n.map((i, l) => [i, l]);
181
+ r.sort((i, l) => e(i[0], l[0]));
182
+ const u = new Array(r.length);
183
+ let s = 0, a = r[0][0];
184
+ for (let i = 0; i < r.length; i++) {
185
+ const [l, h] = r[i];
186
+ e(l, a) !== 0 && (s = i, a = l), u[h] = s, t && s++;
187
+ }
188
+ return u;
189
+ }
190
+ export {
191
+ D as all,
192
+ R as any,
193
+ Z as applyOperations,
194
+ L as concat,
195
+ Y as diffOperations,
196
+ J as distinctByPredicate,
197
+ H as distinctPrimitive,
198
+ T as each,
199
+ A as equals,
200
+ G as fill,
201
+ E as filter,
202
+ P as filterMap,
203
+ S as filterNulls,
204
+ y as flatMap,
205
+ $ as flatten,
206
+ C as foldLeft,
207
+ j as hasValues,
208
+ B as head,
209
+ O as isEmpty,
210
+ F as joinWithConjunction,
211
+ V as makeCompare,
212
+ N as makeEquals,
213
+ _ as map,
214
+ q as mapNotNull,
215
+ z as numbersRange,
216
+ X as ofIterableIterator,
217
+ x as range,
218
+ K as rank,
219
+ Q as remove,
220
+ U as removeByPredicate,
221
+ W as sort,
222
+ I as tail
223
+ };
package/bigint.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(n,e){return e<0n&&(n=-n,e=-e),n<=0n?n/e:(n-1n)/e+1n}function f(n,e){return e<0n&&(n=-n,e=-e),n>=0n?n/e:(n+1n)/e-1n}function c(n,e){return n<e?-1:n>e?1:0}function i(n){return n<0n?-n:n}function s(n,e){return n<e?n:e}function l(n,e){return n>e?n:e}function m(n,e){if(e<0n)throw new Error("negative exponent");let r=1n;for(;e>0n;)(e&1n)!==0n&&(r*=n),e>>=1n,n*=n;return r}function u(n,e){for(n=i(n),e=i(e);e>0n;){const r=e;e=n%e,n=r}return n}function v(n,e){return i(n*e)/u(n,e)}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 e=5n;for(;e*e<=n;){if(n%e===0n||n%(e+2n)===0n)return!1;e+=6n}return!0}function a(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 w(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 p(n){return n%2n===0n}function P(n){return n%2n!==0n}function d(n){return n===0n}function g(n){return n===1n}function h(n){return n<0n}function O(n){return n>0n}exports.abs=i;exports.ceilDiv=o;exports.compare=c;exports.floorDiv=f;exports.gcd=u;exports.isEven=p;exports.isNegative=h;exports.isOdd=P;exports.isOne=g;exports.isPositive=O;exports.isPrime=t;exports.isZero=d;exports.lcm=v;exports.max=l;exports.min=s;exports.nextPrime=a;exports.pow=m;exports.prevPrime=w;
package/bigint.js CHANGED
@@ -1,110 +1,96 @@
1
- export function ceilDiv(x, y) {
2
- if (y < 0n) {
3
- x = -x;
4
- y = -y;
5
- }
6
- return x <= 0n ? x / y : (x - 1n) / y + 1n;
7
- }
8
- export function floorDiv(x, y) {
9
- if (y < 0n) {
10
- x = -x;
11
- y = -y;
12
- }
13
- return x >= 0n ? x / y : (x + 1n) / y - 1n;
14
- }
15
- export function compare(x, y) {
16
- return x < y ? -1 : x > y ? 1 : 0;
17
- }
18
- export function abs(x) {
19
- return x < 0n ? -x : x;
20
- }
21
- export function min(x, y) {
22
- return x < y ? x : y;
23
- }
24
- export function max(x, y) {
25
- return x > y ? x : y;
26
- }
27
- export function pow(x, y) {
28
- if (y < 0n)
29
- throw new Error('negative exponent');
30
- let result = 1n;
31
- while (y > 0n) {
32
- if ((y & 1n) !== 0n)
33
- result *= x;
34
- y >>= 1n;
35
- x *= x;
36
- }
37
- return result;
38
- }
39
- export function gcd(x, y) {
40
- x = abs(x);
41
- y = abs(y);
42
- while (y > 0n) {
43
- const t = y;
44
- y = x % y;
45
- x = t;
46
- }
47
- return x;
48
- }
49
- export function lcm(x, y) {
50
- return abs(x * y) / gcd(x, y);
51
- }
52
- export function isPrime(x) {
53
- if (x < 2n)
54
- return false;
55
- if (x === 2n || x === 3n)
56
- return true;
57
- if (x % 2n === 0n || x % 3n === 0n)
58
- return false;
59
- let i = 5n;
60
- while (i * i <= x) {
61
- if (x % i === 0n || x % (i + 2n) === 0n)
62
- return false;
63
- i += 6n;
64
- }
65
- return true;
66
- }
67
- export function nextPrime(x) {
68
- if (x < 2n)
69
- return 2n;
70
- if (x === 2n)
71
- return 3n;
72
- if (x % 2n === 0n)
73
- x++;
74
- else
75
- x += 2n;
76
- while (!isPrime(x))
77
- x += 2n;
78
- return x;
79
- }
80
- export function prevPrime(x) {
81
- if (x <= 2n)
82
- throw new Error('no previous prime');
83
- if (x === 3n)
84
- return 2n;
85
- if (x % 2n === 0n)
86
- x--;
87
- else
88
- x -= 2n;
89
- while (!isPrime(x))
90
- x -= 2n;
91
- return x;
92
- }
93
- export function isEven(x) {
94
- return x % 2n === 0n;
95
- }
96
- export function isOdd(x) {
97
- return x % 2n !== 0n;
98
- }
99
- export function isZero(x) {
100
- return x === 0n;
101
- }
102
- export function isOne(x) {
103
- return x === 1n;
104
- }
105
- export function isNegative(x) {
106
- return x < 0n;
107
- }
108
- export function isPositive(x) {
109
- return x > 0n;
110
- }
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 i(n) {
11
+ return n < 0n ? -n : n;
12
+ }
13
+ function s(n, r) {
14
+ return n < r ? n : r;
15
+ }
16
+ function l(n, r) {
17
+ return n > r ? n : r;
18
+ }
19
+ function w(n, r) {
20
+ if (r < 0n) throw new Error("negative exponent");
21
+ let e = 1n;
22
+ for (; r > 0n; )
23
+ (r & 1n) !== 0n && (e *= n), r >>= 1n, n *= n;
24
+ return e;
25
+ }
26
+ function u(n, r) {
27
+ for (n = i(n), r = i(r); r > 0n; ) {
28
+ const e = r;
29
+ r = n % r, n = e;
30
+ }
31
+ return n;
32
+ }
33
+ function a(n, r) {
34
+ return i(n * r) / u(n, r);
35
+ }
36
+ function t(n) {
37
+ if (n < 2n) return !1;
38
+ if (n === 2n || n === 3n) return !0;
39
+ 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;
44
+ }
45
+ return !0;
46
+ }
47
+ function m(n) {
48
+ if (n < 2n) return 2n;
49
+ if (n === 2n) return 3n;
50
+ for (n % 2n === 0n ? n++ : n += 2n; !t(n); ) n += 2n;
51
+ return n;
52
+ }
53
+ function v(n) {
54
+ if (n <= 2n) throw new Error("no previous prime");
55
+ if (n === 3n) return 2n;
56
+ for (n % 2n === 0n ? n-- : n -= 2n; !t(n); ) n -= 2n;
57
+ return n;
58
+ }
59
+ function h(n) {
60
+ return n % 2n === 0n;
61
+ }
62
+ function p(n) {
63
+ return n % 2n !== 0n;
64
+ }
65
+ function P(n) {
66
+ return n === 0n;
67
+ }
68
+ function d(n) {
69
+ return n === 1n;
70
+ }
71
+ function g(n) {
72
+ return n < 0n;
73
+ }
74
+ function E(n) {
75
+ return n > 0n;
76
+ }
77
+ export {
78
+ i as abs,
79
+ f as ceilDiv,
80
+ c as compare,
81
+ o as floorDiv,
82
+ u as gcd,
83
+ h as isEven,
84
+ g as isNegative,
85
+ p as isOdd,
86
+ d as isOne,
87
+ E as isPositive,
88
+ t as isPrime,
89
+ P as isZero,
90
+ a as lcm,
91
+ l as max,
92
+ s as min,
93
+ m as nextPrime,
94
+ w as pow,
95
+ v as prevPrime
96
+ };
package/boolean.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e,r){return e===r?0:e?-1:1}function a(e){return e?1:0}function 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}}function s(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 o(e,r){return e!==r}exports.canParse=n;exports.compare=t;exports.parse=s;exports.toInt=a;exports.xor=o;
package/boolean.js ADDED
@@ -0,0 +1,44 @@
1
+ function t(e, r) {
2
+ return e === r ? 0 : e ? -1 : 1;
3
+ }
4
+ function a(e) {
5
+ return e ? 1 : 0;
6
+ }
7
+ function n(e) {
8
+ if (e == null) return !1;
9
+ switch (e.toLowerCase()) {
10
+ case "true":
11
+ case "false":
12
+ case "0":
13
+ case "1":
14
+ case "on":
15
+ case "off":
16
+ return !0;
17
+ default:
18
+ return !1;
19
+ }
20
+ }
21
+ function s(e) {
22
+ switch (e.toLowerCase()) {
23
+ case "true":
24
+ case "1":
25
+ case "on":
26
+ return !0;
27
+ case "false":
28
+ case "0":
29
+ case "off":
30
+ return !1;
31
+ default:
32
+ throw new Error(`unable to parse '${e}'`);
33
+ }
34
+ }
35
+ function c(e, r) {
36
+ return e !== r;
37
+ }
38
+ export {
39
+ n as canParse,
40
+ t as compare,
41
+ s as parse,
42
+ a as toInt,
43
+ c as xor
44
+ };
package/domain.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/domain.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export type IndexKey = keyof any;
2
+ export type Primitive = string | boolean | number | null | undefined;
3
+ export type Nothing = undefined | null;
4
+ export type Compare<T> = (a: T, b: T) => number;
5
+ export type Id<T> = {} & {
6
+ [P in keyof T]: T[P];
7
+ };
8
+ export type Merge<A, B> = Id<A & B>;
9
+ export type Sample = Merge<{
10
+ a: number;
11
+ }, {
12
+ b: string;
13
+ }>;
14
+ export type TupleToUnion<T extends unknown[]> = T[number];
15
+ export type Fun0<R> = () => R;
16
+ export type Fun1<A, R> = (a: A) => R;
17
+ export type Fun2<A, B, R> = (a: A, b: B) => R;
18
+ export type Fun3<A, B, C, R> = (a: A, b: B, c: C) => R;
19
+ export type Fun4<A, B, C, D, R> = (a: A, b: B, c: C, d: D) => R;
20
+ export type Fun5<A, B, C, D, E, R> = (a: A, b: B, c: C, d: D, e: E) => R;
21
+ export type Fun6<A, B, C, D, E, F, R> = (a: A, b: B, c: C, d: D, e: E, f: F) => R;
22
+ export type FirstArgument<F> = F extends Fun1<infer A, unknown> ? A : never;
package/domain.js ADDED
@@ -0,0 +1 @@
1
+
package/equal.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(e,t){return e===t||e!==e&&t!==t}function f(e,t){if(g(e,t))return!0;if(e==null||t==null)return!1;const u=Array.isArray(e),h=Array.isArray(t);if(u!==h)return!1;if(u){const n=e,r=t,a=n.length;if(a!==r.length)return!1;for(let s=0;s<a;s++)if(!f(n[s],r[s]))return!1;return!0}const l=e instanceof Date,j=t instanceof Date;if(l!==j)return!1;if(l){const n=e,r=t;return+n==+r}const p=e instanceof Set,I=t instanceof Set;if(p!==I)return!1;if(p){const n=e,r=t;if(n.size!==r.size)return!1;const a=n.keys();for(;;){const s=a.next();if(s.done??!1)break;if(!r.has(s.value))return!1}return!0}const y=e instanceof Map,O=t instanceof Map;if(y!==O)return!1;if(y){const n=e,r=t;if(n.size!==r.size)return!1;const s=n.keys();for(;;){const o=s.next();if(o.done??!1)break;if(!f(n.get(o.value),r.get(o.value)))return!1}return!0}const b=typeof e=="object";if(b!==(typeof t=="object"))return!1;if(b){const n=e,r=t,a=Object.keys(n),s=Object.keys(r),o=a.length;if(o!==s.length)return!1;for(let i=0;i<o;i++){const c=a[i];if(!Object.prototype.hasOwnProperty.call(r,c)||!f(n[c],r[c]))return!1}return!0}return!1}function d(e,t){return e==t}exports.deepEqual=f;exports.looseEqual=d;exports.strictEqual=g;
package/equal.js ADDED
@@ -0,0 +1,68 @@
1
+ function O(e, t) {
2
+ return e === t || e !== e && t !== t;
3
+ }
4
+ function i(e, t) {
5
+ if (O(e, t)) return !0;
6
+ if (e == null || t == null) return !1;
7
+ const u = Array.isArray(e), b = Array.isArray(t);
8
+ if (u !== b) return !1;
9
+ if (u) {
10
+ const n = e, r = t, a = n.length;
11
+ if (a !== r.length) return !1;
12
+ for (let s = 0; s < a; s++)
13
+ if (!i(n[s], r[s])) return !1;
14
+ return !0;
15
+ }
16
+ const l = e instanceof Date, I = t instanceof Date;
17
+ if (l !== I) return !1;
18
+ if (l) {
19
+ const n = e, r = t;
20
+ return +n == +r;
21
+ }
22
+ const p = e instanceof Set, g = t instanceof Set;
23
+ if (p !== g) return !1;
24
+ if (p) {
25
+ const n = e, r = t;
26
+ if (n.size !== r.size) return !1;
27
+ const a = n.keys();
28
+ for (; ; ) {
29
+ const s = a.next();
30
+ if (s.done ?? !1) break;
31
+ if (!r.has(s.value)) return !1;
32
+ }
33
+ return !0;
34
+ }
35
+ const h = e instanceof Map, j = t instanceof Map;
36
+ if (h !== j) return !1;
37
+ if (h) {
38
+ const n = e, r = t;
39
+ if (n.size !== r.size) return !1;
40
+ const s = n.keys();
41
+ for (; ; ) {
42
+ const f = s.next();
43
+ if (f.done ?? !1) break;
44
+ if (!i(n.get(f.value), r.get(f.value))) return !1;
45
+ }
46
+ return !0;
47
+ }
48
+ const y = typeof e == "object";
49
+ if (y !== (typeof t == "object")) return !1;
50
+ if (y) {
51
+ const n = e, r = t, a = Object.keys(n), s = Object.keys(r), f = a.length;
52
+ if (f !== s.length) return !1;
53
+ for (let o = 0; o < f; o++) {
54
+ const c = a[o];
55
+ if (!Object.prototype.hasOwnProperty.call(r, c) || !i(n[c], r[c])) return !1;
56
+ }
57
+ return !0;
58
+ }
59
+ return !1;
60
+ }
61
+ function M(e, t) {
62
+ return e == t;
63
+ }
64
+ export {
65
+ i as deepEqual,
66
+ M as looseEqual,
67
+ O as strictEqual
68
+ };
package/function.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(...r){return t=>r.reduce((e,n)=>n(e),t)}function i(r){return r}function c(r){return t=>(...e)=>r(t,...e)}function o(r){return(...t)=>e=>r(...t.concat([e]))}function f(r){return(...t)=>r(...t.reverse())}function y(r){return r}exports.compose=u;exports.curryLeft=c;exports.curryRight=o;exports.flip=f;exports.id=y;exports.identity=i;
package/function.js ADDED
@@ -0,0 +1,29 @@
1
+ function u(...n) {
2
+ return (r) => n.reduce((t, e) => e(t), r);
3
+ }
4
+ function c(n) {
5
+ return n;
6
+ }
7
+ function i(n) {
8
+ return (r) => (...t) => n(r, ...t);
9
+ }
10
+ function o(n) {
11
+ return (...r) => (
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ (t) => n(...r.concat([t]))
14
+ );
15
+ }
16
+ function f(n) {
17
+ return (...r) => n(...r.reverse());
18
+ }
19
+ function d(n) {
20
+ return n;
21
+ }
22
+ export {
23
+ u as compose,
24
+ i as curryLeft,
25
+ o as curryRight,
26
+ f as flip,
27
+ d as id,
28
+ c as identity
29
+ };