@tempots/std 0.13.0 → 0.15.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.cjs +1 -1
- package/array.d.ts +35 -35
- package/array.js +109 -168
- package/async-result.cjs +1 -1
- package/async-result.d.ts +38 -15
- package/async-result.js +40 -5
- package/bigint.cjs +1 -1
- package/bigint.d.ts +20 -20
- package/bigint.js +37 -78
- package/boolean.cjs +1 -1
- package/boolean.d.ts +5 -5
- package/boolean.js +10 -19
- package/equal.cjs +1 -1
- package/equal.d.ts +3 -3
- package/equal.js +31 -37
- package/error.cjs +1 -0
- package/error.d.ts +24 -0
- package/error.js +26 -0
- package/function.cjs +1 -1
- package/function.d.ts +3 -3
- package/function.js +4 -10
- package/index.cjs +1 -1
- package/index.d.ts +1 -0
- package/index.js +120 -118
- package/number.cjs +1 -1
- package/number.d.ts +25 -46
- package/number.js +29 -86
- package/object.cjs +1 -1
- package/object.d.ts +6 -6
- package/object.js +12 -27
- package/package.json +15 -1
- package/promise.cjs +1 -0
- package/promise.d.ts +11 -0
- package/promise.js +9 -0
- package/regexp.cjs +1 -1
- package/regexp.d.ts +1 -1
- package/regexp.js +8 -8
- package/{result-Czm7RKNP.js → result-CGd0jCdl.js} +54 -19
- package/result-CdwVhaAc.cjs +1 -0
- package/result.cjs +1 -1
- package/result.d.ts +31 -8
- package/result.js +1 -1
- package/string.cjs +4 -4
- package/string.d.ts +85 -89
- package/string.js +193 -379
- package/validation.cjs +1 -1
- package/validation.d.ts +7 -7
- package/validation.js +1 -1
- package/result-DzdZiQoR.cjs +0 -1
package/array.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("./object.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("./object.cjs"),x=(r,t)=>Array.from({length:r.length},(e,n)=>t(r[n],n)),F=(r,t)=>{const e=[];for(const n of r)e.push(...t(n));return e},w=r=>r.length>0?r[0]:void 0,B=r=>r.slice(1),P=(r,t,e)=>{if(r.length!==t.length)return!1;for(let n=0;n<r.length;n++)if(!e(r[n],t[n]))return!1;return!0},b=r=>r.length===0,j=r=>r.length>0,g=(r,t)=>{const e=[];for(const n of r)t(n)&&e.push(n);return e},M=(r,t)=>{const e=[];for(let n=0;n<r.length;n++){const s=t(r[n],n);s!=null&&e.push(s)}return e},I=r=>g(r,t=>t!=null),S=r=>[].concat(...r),k=(r,t,e)=>{for(const n of r)e=t(e,n);return e},D=(r,t)=>{for(const e of r)if(!t(e))return!1;return!0},_=(r,t)=>{for(const e of r)if(t(e))return!0;return!1},T=(r,t)=>{for(const e of r)t(e)},H=(...r)=>[].concat(...r),N=(r,t,e,n=!0)=>{if(r.length<t.length)return-1*(n?1:-1);if(r.length>t.length)return 1*(n?1:-1);for(let s=0;s<r.length;s++){const l=e(r[s],t[s]);if(l!==0)return l}return 0},$=(r,t)=>r.slice().sort(t),p=(r,t)=>Array.from({length:r},(e,n)=>t(n)),C=(r,t=0)=>p(r,e=>t+e),L=(r,t)=>p(r,()=>t),V=r=>Array.from(new Set(r)),W=(r,t)=>{const e={};return r.forEach(n=>{e[t(n)]=n}),q.objectKeys(e).map(n=>e[n])},v=(r,t)=>{const e=r.indexOf(t);return e<0?!1:(r.splice(e,1),!0)},R=(r,t)=>{let e=!1;for(;v(r,t);)e=!0;return e},E=(r,t)=>{const e=r.findIndex(t);return e<0?!1:(r.splice(e,1),!0)},z=(r,t)=>{let e=!1;for(;E(r,t);)e=!0;return e},G=r=>{const t=[];for(let e=r.next();!(e.done??!1);e=r.next())t.push(e.value);return t},J=(r,t,e)=>{const n={removals:[],swaps:[],inserts:[]},{removals:s,inserts:l,swaps:u}=n,c=new Map;t.forEach((a,o)=>c.set(e(a),o));const f=r.map((a,o)=>[a,o]).filter(([a])=>!c.has(e(a))).map(([a,o])=>o);for(let a=f.length-1;a>=0;a--){const o=f[a],i=s.length>0?s[s.length-1]:void 0;i!=null&&i.at===o+1?(i.at--,i.qt++):s.push({at:o,qt:1})}const y=new Map;r.forEach((a,o)=>y.set(e(a),o));const h=t.map((a,o)=>[a,o]).filter(([a])=>!y.has(e(a))).map(([a,o])=>o);for(const a of h){const o=l.length>0?l[l.length-1]:void 0;o!=null&&o.at+o.values.length===a?o.values.push(t[a]):l.push({at:a,values:[t[a]]})}const A=r.filter((a,o)=>!f.includes(o)),m=new Map;for(let a=0;a<A.length;a++)m.set(e(A[a]),a);const d=t.filter((a,o)=>!h.includes(o));for(let a=0;a<d.length;a++){const o=e(d[a]),i=m.get(o);if(i==null||a===i)continue;const O=e(A[a]);m.delete(O),u.push({from:a,to:i})}return n},Q=(r,t)=>{const e=[...t];for(const{at:n,qt:s}of r.removals)e.splice(n,s);for(const{from:n,to:s}of r.swaps){const l=e[s];e[s]=e[n],e[n]=l}for(const n of r.inserts)e.splice(n.at,0,...n.values);return e},U=(r,t=" and ",e=", ")=>r.length===0?"":r.length===1?String(r[0]):`${r.slice(0,-1).join(e)}${t}${String(r[r.length-1])}`,X=(r,t,e=!0)=>{const n=r.map((c,f)=>[c,f]);n.sort((c,f)=>t(c[0],f[0]));const s=new Array(n.length);let l=0,u=n[0][0];for(let c=0;c<n.length;c++){const[f,y]=n[c];t(f,u)!==0&&(l=c,u=f),s[y]=l,e&&l++}return s};exports.allElements=D;exports.anyElement=_;exports.applyArrayDiffOperations=Q;exports.areArraysEqual=P;exports.arrayDiffOperations=J;exports.arrayHasValues=j;exports.arrayHead=w;exports.arrayOfIterableIterator=G;exports.arrayTail=B;exports.compareArrays=N;exports.concatArrays=H;exports.createFilledArray=L;exports.filterArray=g;exports.filterMapArray=M;exports.filterNullsFromArray=I;exports.flatMapArray=F;exports.flattenArray=S;exports.foldLeftArray=k;exports.forEachElement=T;exports.generateArray=p;exports.generateSequenceArray=C;exports.isArrayEmpty=b;exports.joinArrayWithConjunction=U;exports.mapArray=x;exports.rankArray=X;exports.removeAllFromArray=R;exports.removeAllFromArrayByPredicate=z;exports.removeOneFromArray=v;exports.removeOneFromArrayByPredicate=E;exports.sortArray=$;exports.uniqueByPrimitive=W;exports.uniquePrimitives=V;
|
package/array.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Compare, Maybe, Nothing, Primitive } from './domain';
|
|
|
10
10
|
* @returns The new array with the results of applying the function to each element.
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export declare
|
|
13
|
+
export declare const mapArray: <A, B>(arr: A[], f: (a: A, index: number) => B) => B[];
|
|
14
14
|
/**
|
|
15
15
|
* Applies a mapping function to each element of an array and flattens the result.
|
|
16
16
|
*
|
|
@@ -21,7 +21,7 @@ export declare function mapArray<A, B>(arr: A[], f: (a: A, index: number) => B):
|
|
|
21
21
|
* @typeParam B - The type of the elements in the resulting flattened array.
|
|
22
22
|
* @public
|
|
23
23
|
*/
|
|
24
|
-
export declare
|
|
24
|
+
export declare const flatMapArray: <A, B>(arr: A[], f: (a: A) => B[]) => B[];
|
|
25
25
|
/**
|
|
26
26
|
* Returns the first element of an array, or `undefined` if the array is empty.
|
|
27
27
|
*
|
|
@@ -30,7 +30,7 @@ export declare function flatMapArray<A, B>(arr: A[], f: (a: A) => B[]): B[];
|
|
|
30
30
|
* @typeParam A - The type of elements in the array.
|
|
31
31
|
* @public
|
|
32
32
|
*/
|
|
33
|
-
export declare
|
|
33
|
+
export declare const arrayHead: <A>(arr: A[]) => Maybe<A>;
|
|
34
34
|
/**
|
|
35
35
|
* Returns a new array containing all elements of the input array except for the first element.
|
|
36
36
|
*
|
|
@@ -38,7 +38,7 @@ export declare function arrayHead<A>(arr: A[]): Maybe<A>;
|
|
|
38
38
|
* @returns A new array containing all elements of the input array except for the first element.
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
|
-
export declare
|
|
41
|
+
export declare const arrayTail: <A>(arr: A[]) => A[];
|
|
42
42
|
/**
|
|
43
43
|
* Checks if two arrays are equal based on a custom equality function.
|
|
44
44
|
*
|
|
@@ -49,7 +49,7 @@ export declare function arrayTail<A>(arr: A[]): A[];
|
|
|
49
49
|
* @returns Returns `true` if the arrays are equal, `false` otherwise.
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
|
-
export declare
|
|
52
|
+
export declare const areArraysEqual: <T>(a: T[], b: T[], equality: (a: T, b: T) => boolean) => boolean;
|
|
53
53
|
/**
|
|
54
54
|
* Checks if an array is empty.
|
|
55
55
|
*
|
|
@@ -57,7 +57,7 @@ export declare function areArraysEqual<T>(a: T[], b: T[], equality: (a: T, b: T)
|
|
|
57
57
|
* @returns `true` if the array is empty, `false` otherwise.
|
|
58
58
|
* @public
|
|
59
59
|
*/
|
|
60
|
-
export declare
|
|
60
|
+
export declare const isArrayEmpty: <T>(arr: T[]) => arr is [];
|
|
61
61
|
/**
|
|
62
62
|
* Checks if an array has values.
|
|
63
63
|
*
|
|
@@ -65,7 +65,7 @@ export declare function isArrayEmpty<T>(arr: T[]): arr is [];
|
|
|
65
65
|
* @returns `true` if the array has values, `false` otherwise.
|
|
66
66
|
* @public
|
|
67
67
|
*/
|
|
68
|
-
export declare
|
|
68
|
+
export declare const arrayHasValues: <T>(arr: T[]) => arr is [T, ...T[]];
|
|
69
69
|
/**
|
|
70
70
|
* Filters the elements of an array based on a predicate function.
|
|
71
71
|
*
|
|
@@ -75,7 +75,7 @@ export declare function arrayHasValues<T>(arr: T[]): arr is [T, ...T[]];
|
|
|
75
75
|
* @returns The filtered array.
|
|
76
76
|
* @public
|
|
77
77
|
*/
|
|
78
|
-
export declare
|
|
78
|
+
export declare const filterArray: <T>(arr: T[], predicate: (v: T) => boolean) => T[];
|
|
79
79
|
/**
|
|
80
80
|
* Applies a mapping function to each element of an array and returns a new array
|
|
81
81
|
* containing the mapped values, excluding any `null` or `undefined` values.
|
|
@@ -87,7 +87,7 @@ export declare function filterArray<T>(arr: T[], predicate: (v: T) => boolean):
|
|
|
87
87
|
* @returns The new array containing the mapped values.
|
|
88
88
|
* @public
|
|
89
89
|
*/
|
|
90
|
-
export declare
|
|
90
|
+
export declare const filterMapArray: <A, B>(arr: A[], f: (a: A, index: number) => Maybe<B>) => B[];
|
|
91
91
|
/**
|
|
92
92
|
* Filters out null and undefined values from an array.
|
|
93
93
|
*
|
|
@@ -96,7 +96,7 @@ export declare function filterMapArray<A, B>(arr: A[], f: (a: A, index: number)
|
|
|
96
96
|
* @returns The filtered array.
|
|
97
97
|
* @public
|
|
98
98
|
*/
|
|
99
|
-
export declare
|
|
99
|
+
export declare const filterNullsFromArray: <T>(arr: Array<T | Nothing>) => T[];
|
|
100
100
|
/**
|
|
101
101
|
* Flattens a two-dimensional array into a one-dimensional array.
|
|
102
102
|
*
|
|
@@ -105,7 +105,7 @@ export declare function filterNullsFromArray<T>(arr: Array<T | Nothing>): T[];
|
|
|
105
105
|
* @typeParam T - The type of elements in the array.
|
|
106
106
|
* @public
|
|
107
107
|
*/
|
|
108
|
-
export declare
|
|
108
|
+
export declare const flattenArray: <T>(arr: T[][]) => T[];
|
|
109
109
|
/**
|
|
110
110
|
* Applies a function to each element of an array, accumulating the result from left to right.
|
|
111
111
|
*
|
|
@@ -117,7 +117,7 @@ export declare function flattenArray<T>(arr: T[][]): T[];
|
|
|
117
117
|
* @returns The accumulated result.
|
|
118
118
|
* @public
|
|
119
119
|
*/
|
|
120
|
-
export declare
|
|
120
|
+
export declare const foldLeftArray: <T, B>(arr: T[], f: (acc: B, curr: T) => B, b: B) => B;
|
|
121
121
|
/**
|
|
122
122
|
* Checks if all elements in an array satisfy a given predicate.
|
|
123
123
|
*
|
|
@@ -127,7 +127,7 @@ export declare function foldLeftArray<T, B>(arr: T[], f: (acc: B, curr: T) => B,
|
|
|
127
127
|
* @typeParam T - The type of elements in the array.
|
|
128
128
|
* @public
|
|
129
129
|
*/
|
|
130
|
-
export declare
|
|
130
|
+
export declare const allElements: <T>(arr: T[], predicate: (v: T) => boolean) => boolean;
|
|
131
131
|
/**
|
|
132
132
|
* Checks if any element in the array satisfies the given predicate.
|
|
133
133
|
*
|
|
@@ -137,7 +137,7 @@ export declare function allElements<T>(arr: T[], predicate: (v: T) => boolean):
|
|
|
137
137
|
* @typeParam T - The type of elements in the array.
|
|
138
138
|
* @public
|
|
139
139
|
*/
|
|
140
|
-
export declare
|
|
140
|
+
export declare const anyElement: <T>(arr: T[], predicate: (v: T) => boolean) => boolean;
|
|
141
141
|
/**
|
|
142
142
|
* Applies a function to each element in an array.
|
|
143
143
|
*
|
|
@@ -146,7 +146,7 @@ export declare function anyElement<T>(arr: T[], predicate: (v: T) => boolean): b
|
|
|
146
146
|
* @param f - The function to apply to each element.
|
|
147
147
|
* @public
|
|
148
148
|
*/
|
|
149
|
-
export declare
|
|
149
|
+
export declare const forEachElement: <T>(arr: T[], f: (v: T) => void) => void;
|
|
150
150
|
/**
|
|
151
151
|
* Concatenates multiple arrays into a single array.
|
|
152
152
|
*
|
|
@@ -155,7 +155,7 @@ export declare function forEachElement<T>(arr: T[], f: (v: T) => void): void;
|
|
|
155
155
|
* @typeParam A - The type of elements in the arrays.
|
|
156
156
|
* @public
|
|
157
157
|
*/
|
|
158
|
-
export declare
|
|
158
|
+
export declare const concatArrays: <A>(...arrs: A[][]) => A[];
|
|
159
159
|
/**
|
|
160
160
|
* Compares two arrays based on their lengths and element values.
|
|
161
161
|
*
|
|
@@ -163,11 +163,11 @@ export declare function concatArrays<A>(...arrs: A[][]): A[];
|
|
|
163
163
|
* @param a - The first array to compare.
|
|
164
164
|
* @param b - The second array to compare.
|
|
165
165
|
* @param comparef - The compare function to use for comparing the elements of the arrays.
|
|
166
|
-
* @param shorterFirst -
|
|
166
|
+
* @param shorterFirst - Specifies whether shorter arrays should be considered smaller. Defaults to true.
|
|
167
167
|
* @returns A compare function that can be used to compare arrays.
|
|
168
168
|
* @public
|
|
169
169
|
*/
|
|
170
|
-
export declare
|
|
170
|
+
export declare const compareArrays: <A>(a: A[], b: A[], comparef: Compare<A>, shorterFirst?: boolean) => number;
|
|
171
171
|
/**
|
|
172
172
|
* Sorts an array in place using the provided compare function.
|
|
173
173
|
*
|
|
@@ -177,7 +177,7 @@ export declare function compareArrays<A>(a: A[], b: A[], comparef: Compare<A>, s
|
|
|
177
177
|
* @returns The sorted array.
|
|
178
178
|
* @public
|
|
179
179
|
*/
|
|
180
|
-
export declare
|
|
180
|
+
export declare const sortArray: <A>(arr: A[], compare: Compare<A>) => A[];
|
|
181
181
|
/**
|
|
182
182
|
* Generates an array of values by applying a function to each index.
|
|
183
183
|
*
|
|
@@ -186,7 +186,7 @@ export declare function sortArray<A>(arr: A[], compare: Compare<A>): A[];
|
|
|
186
186
|
* @returns An array of values generated by applying the function to each index.
|
|
187
187
|
* @public
|
|
188
188
|
*/
|
|
189
|
-
export declare
|
|
189
|
+
export declare const generateArray: <A>(length: number, f: (index: number) => A) => A[];
|
|
190
190
|
/**
|
|
191
191
|
* Generates an array of numbers in a specified range.
|
|
192
192
|
*
|
|
@@ -195,7 +195,7 @@ export declare function generateArray<A>(length: number, f: (index: number) => A
|
|
|
195
195
|
* @returns An array of numbers in the specified range.
|
|
196
196
|
* @public
|
|
197
197
|
*/
|
|
198
|
-
export declare
|
|
198
|
+
export declare const generateSequenceArray: (length: number, startAt?: number) => number[];
|
|
199
199
|
/**
|
|
200
200
|
* Creates a new array with the specified length and fills it with the provided value.
|
|
201
201
|
*
|
|
@@ -205,7 +205,7 @@ export declare function generateSequenceArray(length: number, startAt?: number):
|
|
|
205
205
|
* @returns A new array filled with the specified value.
|
|
206
206
|
* @public
|
|
207
207
|
*/
|
|
208
|
-
export declare
|
|
208
|
+
export declare const createFilledArray: <A>(length: number, value: A) => A[];
|
|
209
209
|
/**
|
|
210
210
|
* Returns an array containing only the distinct primitive values from the input array.
|
|
211
211
|
*
|
|
@@ -214,7 +214,7 @@ export declare function createFilledArray<A>(length: number, value: A): A[];
|
|
|
214
214
|
* @returns An array containing only the distinct primitive values from the input array.
|
|
215
215
|
* @public
|
|
216
216
|
*/
|
|
217
|
-
export declare
|
|
217
|
+
export declare const uniquePrimitives: <T extends Primitive>(values: T[]) => T[];
|
|
218
218
|
/**
|
|
219
219
|
* Returns an array of distinct elements from the input array based on the provided predicate.
|
|
220
220
|
*
|
|
@@ -224,7 +224,7 @@ export declare function uniquePrimitives<T extends Primitive>(values: T[]): T[];
|
|
|
224
224
|
* @returns An array of distinct elements.
|
|
225
225
|
* @public
|
|
226
226
|
*/
|
|
227
|
-
export declare
|
|
227
|
+
export declare const uniqueByPrimitive: <T>(values: T[], predicate: (a: T) => string | number | symbol) => T[];
|
|
228
228
|
/**
|
|
229
229
|
* Removes the first occurrence of an item from an array.
|
|
230
230
|
*
|
|
@@ -234,7 +234,7 @@ export declare function uniqueByPredicate<T>(values: T[], predicate: (a: T) => s
|
|
|
234
234
|
* @returns `true` if the item was found and removed, `false` otherwise.
|
|
235
235
|
* @public
|
|
236
236
|
*/
|
|
237
|
-
export declare
|
|
237
|
+
export declare const removeOneFromArray: <A>(arr: A[], item: A) => boolean;
|
|
238
238
|
/**
|
|
239
239
|
* Removes all occurrences of an item from an array.
|
|
240
240
|
*
|
|
@@ -244,7 +244,7 @@ export declare function removeOneFromArray<A>(arr: A[], item: A): boolean;
|
|
|
244
244
|
* @returns `true` if at least one occurrence was found and removed, `false` otherwise.
|
|
245
245
|
* @public
|
|
246
246
|
*/
|
|
247
|
-
export declare
|
|
247
|
+
export declare const removeAllFromArray: <A>(arr: A[], item: A) => boolean;
|
|
248
248
|
/**
|
|
249
249
|
* Removes the first occurrence in an array that satisfy the given predicate.
|
|
250
250
|
*
|
|
@@ -254,7 +254,7 @@ export declare function removeAllFromArray<A>(arr: A[], item: A): boolean;
|
|
|
254
254
|
* @returns `true` if at least one element was removed, `false` otherwise.
|
|
255
255
|
* @public
|
|
256
256
|
*/
|
|
257
|
-
export declare
|
|
257
|
+
export declare const removeOneFromArrayByPredicate: <A>(arr: A[], predicate: (a: A) => boolean) => boolean;
|
|
258
258
|
/**
|
|
259
259
|
* Removes all occurrences in an array that satisfy the given predicate.
|
|
260
260
|
*
|
|
@@ -264,7 +264,7 @@ export declare function removeOneFromArrayByPredicate<A>(arr: A[], predicate: (a
|
|
|
264
264
|
* @returns `true` if at least one element was removed, `false` otherwise.
|
|
265
265
|
* @public
|
|
266
266
|
*/
|
|
267
|
-
export declare
|
|
267
|
+
export declare const removeAllFromArrayByPredicate: <A>(arr: A[], predicate: (a: A) => boolean) => boolean;
|
|
268
268
|
/**
|
|
269
269
|
* Converts an IterableIterator to an array.
|
|
270
270
|
*
|
|
@@ -272,13 +272,13 @@ export declare function removeAllFromArrayByPredicate<A>(arr: A[], predicate: (a
|
|
|
272
272
|
* @returns An array containing the values from the IterableIterator.
|
|
273
273
|
* @public
|
|
274
274
|
*/
|
|
275
|
-
export declare
|
|
275
|
+
export declare const arrayOfIterableIterator: <A>(it: IterableIterator<A>) => A[];
|
|
276
276
|
/**
|
|
277
277
|
* Represents the different operations that can be performed on an array.
|
|
278
278
|
*
|
|
279
279
|
* @public
|
|
280
280
|
*/
|
|
281
|
-
export
|
|
281
|
+
export type ArrayDiffOperations<T> = {
|
|
282
282
|
removals: Array<{
|
|
283
283
|
at: number;
|
|
284
284
|
qt: number;
|
|
@@ -291,7 +291,7 @@ export interface ArrayDiffOperations<T> {
|
|
|
291
291
|
at: number;
|
|
292
292
|
values: T[];
|
|
293
293
|
}>;
|
|
294
|
-
}
|
|
294
|
+
};
|
|
295
295
|
/**
|
|
296
296
|
* Calculates the difference operations between two arrays based on a key function.
|
|
297
297
|
*
|
|
@@ -303,7 +303,7 @@ export interface ArrayDiffOperations<T> {
|
|
|
303
303
|
* @returns The difference operations between the two arrays.
|
|
304
304
|
* @public
|
|
305
305
|
*/
|
|
306
|
-
export declare
|
|
306
|
+
export declare const arrayDiffOperations: <T, K>(from: T[], to: T[], getKey: (v: T) => K) => ArrayDiffOperations<T>;
|
|
307
307
|
/**
|
|
308
308
|
* Applies a series of operations to an array and returns the modified array.
|
|
309
309
|
*
|
|
@@ -313,7 +313,7 @@ export declare function arrayDiffOperations<T, K>(from: T[], to: T[], getKey: (v
|
|
|
313
313
|
* @returns The modified array after applying the operations.
|
|
314
314
|
* @public
|
|
315
315
|
*/
|
|
316
|
-
export declare
|
|
316
|
+
export declare const applyArrayDiffOperations: <T>(operations: ArrayDiffOperations<T>, start: T[]) => T[];
|
|
317
317
|
/**
|
|
318
318
|
* Joins an array of values into a string using a conjunction and separator.
|
|
319
319
|
*
|
|
@@ -323,7 +323,7 @@ export declare function applyArrayDiffOperations<T>(operations: ArrayDiffOperati
|
|
|
323
323
|
* @returns The joined string.
|
|
324
324
|
* @public
|
|
325
325
|
*/
|
|
326
|
-
export declare
|
|
326
|
+
export declare const joinArrayWithConjunction: <A>(arr: A[], conjunction?: string, separator?: string) => string;
|
|
327
327
|
/**
|
|
328
328
|
* Assigns ranks to the elements in the array based on the provided compare function.
|
|
329
329
|
* The ranks are assigned in ascending order, with the lowest value receiving a rank of 0.
|
|
@@ -336,4 +336,4 @@ export declare function joinArrayWithConjunction<A>(arr: A[], conjunction?: stri
|
|
|
336
336
|
* @returns An array of ranks corresponding to the elements in the input array.
|
|
337
337
|
* @public
|
|
338
338
|
*/
|
|
339
|
-
export declare
|
|
339
|
+
export declare const rankArray: <T>(array: T[], compare: (a: T, b: T) => number, incrementDuplicates?: boolean) => number[];
|
package/array.js
CHANGED
|
@@ -1,188 +1,129 @@
|
|
|
1
1
|
import { objectKeys as v } from "./object.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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:
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
for (let
|
|
138
|
-
const
|
|
139
|
-
i != null && i.at ===
|
|
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
|
-
|
|
143
|
-
const y =
|
|
144
|
-
for (const
|
|
145
|
-
const
|
|
146
|
-
|
|
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 =
|
|
149
|
-
for (let
|
|
150
|
-
m.set(
|
|
151
|
-
const A =
|
|
152
|
-
for (let
|
|
153
|
-
const
|
|
154
|
-
if (i == null ||
|
|
155
|
-
const d =
|
|
156
|
-
m.delete(d),
|
|
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
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
185
|
-
}
|
|
125
|
+
return l;
|
|
126
|
+
};
|
|
186
127
|
export {
|
|
187
128
|
S as allElements,
|
|
188
129
|
N as anyElement,
|
|
@@ -214,6 +155,6 @@ export {
|
|
|
214
155
|
E as removeOneFromArray,
|
|
215
156
|
w as removeOneFromArrayByPredicate,
|
|
216
157
|
C as sortArray,
|
|
217
|
-
W as
|
|
158
|
+
W as uniqueByPrimitive,
|
|
218
159
|
V as uniquePrimitives
|
|
219
160
|
};
|
package/async-result.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u={notAsked:{type:"NotAsked"},loading(e=void 0){return{type:"Loading",previousValue:e}},success(e){return{type:"AsyncSuccess",value:e}},failure(e){return{type:"AsyncFailure",error:e}},isSuccess(e){return e.type==="AsyncSuccess"},isFailure(e){return e.type==="AsyncFailure"},isNotAsked(e){return e.type==="NotAsked"},isLoading(e){return e.type==="Loading"},getOrElse(e,s){return u.isSuccess(e)?e.value:s},getOrElseLazy(e,s){return u.isSuccess(e)?e.value:s()},getOrNull(e){return u.isSuccess(e)?e.value:null},getOrUndefined(e){return u.isSuccess(e)?e.value:void 0},getUnsafe:e=>{if(u.isSuccess(e))return e.value;throw u.isFailure(e)?e.error:new Error("Cannot get value from a not-asked or loading result")},match:(e,{success:s,failure:r,loading:t,notAsked:l=t})=>u.isSuccess(e)?s(e.value):u.isFailure(e)?r(e.error):u.isNotAsked(e)?l():t(e.previousValue),whenSuccess:(e,s)=>(u.isSuccess(e)&&s(e.value),e),whenFailure:(e,s)=>(u.isFailure(e)&&s(e.error),e),equals:(e,s,r={valueEquals:(t,l)=>t===l,errorEquals:(t,l)=>t===l})=>e.type==="AsyncSuccess"&&s.type==="AsyncSuccess"?r.valueEquals(e.value,s.value):e.type==="AsyncFailure"&&s.type==="AsyncFailure"?r.errorEquals(e.error,s.error):e.type==="Loading"&&s.type==="Loading"?r.valueEquals(e.previousValue,s.previousValue):e.type==="NotAsked"&&s.type==="NotAsked",all:e=>{const s=[];for(const r of e)if(u.isSuccess(r))s.push(r.value);else return r;return u.success(s)}};exports.AsyncResult=u;
|