@tempots/std 0.14.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 +1 -1
- package/array.js +1 -1
- package/async-result.cjs +1 -1
- package/async-result.d.ts +23 -0
- package/async-result.js +40 -5
- package/index.cjs +1 -1
- package/index.js +13 -13
- package/package.json +1 -1
- package/{result-Czm7RKNP.js → result-CGd0jCdl.js} +54 -19
- package/result-CdwVhaAc.cjs +1 -0
- package/result.cjs +1 -1
- package/result.d.ts +23 -0
- package/result.js +1 -1
- package/validation.cjs +1 -1
- 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"),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.
|
|
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
|
@@ -224,7 +224,7 @@ export declare const uniquePrimitives: <T extends Primitive>(values: T[]) => T[]
|
|
|
224
224
|
* @returns An array of distinct elements.
|
|
225
225
|
* @public
|
|
226
226
|
*/
|
|
227
|
-
export declare const
|
|
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
|
*
|
package/array.js
CHANGED
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;
|
package/async-result.d.ts
CHANGED
|
@@ -139,6 +139,12 @@ export declare const AsyncResult: {
|
|
|
139
139
|
* @public
|
|
140
140
|
*/
|
|
141
141
|
getOrUndefined<V, E>(r: AsyncResult<V, E>): Maybe<V>;
|
|
142
|
+
/**
|
|
143
|
+
* Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
144
|
+
* @param r - The `AsyncResult` to get the value from.
|
|
145
|
+
* @returns The value of the `AsyncResult` if it is a `Success`.
|
|
146
|
+
*/
|
|
147
|
+
getUnsafe: <V, E>(r: AsyncResult<V, E>) => V;
|
|
142
148
|
/**
|
|
143
149
|
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
144
150
|
* @param success - The function to call if the result is a success.
|
|
@@ -172,4 +178,21 @@ export declare const AsyncResult: {
|
|
|
172
178
|
* @public
|
|
173
179
|
*/
|
|
174
180
|
whenFailure: <V, E>(r: AsyncResult<V, E>, apply: (e: E) => void) => AsyncResult<V, E>;
|
|
181
|
+
/**
|
|
182
|
+
* Compares two results for equality.
|
|
183
|
+
* @param r1 - The first result.
|
|
184
|
+
* @param r2 - The second result.
|
|
185
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
186
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
187
|
+
*/
|
|
188
|
+
equals: <V, E>(r1: AsyncResult<V, E>, r2: AsyncResult<V, E>, options?: {
|
|
189
|
+
valueEquals: (v1: V, v2: V) => boolean;
|
|
190
|
+
errorEquals: (e1: E, e2: E) => boolean;
|
|
191
|
+
}) => boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Combines multiple results into a single result.
|
|
194
|
+
* @param results - The results to combine.
|
|
195
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
196
|
+
*/
|
|
197
|
+
all: <V, E>(results: AsyncResult<V, E>[]) => AsyncResult<V[], E>;
|
|
175
198
|
};
|
package/async-result.js
CHANGED
|
@@ -108,6 +108,16 @@ const u = {
|
|
|
108
108
|
getOrUndefined(e) {
|
|
109
109
|
return u.isSuccess(e) ? e.value : void 0;
|
|
110
110
|
},
|
|
111
|
+
/**
|
|
112
|
+
* Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
113
|
+
* @param r - The `AsyncResult` to get the value from.
|
|
114
|
+
* @returns The value of the `AsyncResult` if it is a `Success`.
|
|
115
|
+
*/
|
|
116
|
+
getUnsafe: (e) => {
|
|
117
|
+
if (u.isSuccess(e))
|
|
118
|
+
return e.value;
|
|
119
|
+
throw u.isFailure(e) ? e.error : new Error("Cannot get value from a not-asked or loading result");
|
|
120
|
+
},
|
|
111
121
|
/**
|
|
112
122
|
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
113
123
|
* @param success - The function to call if the result is a success.
|
|
@@ -119,10 +129,10 @@ const u = {
|
|
|
119
129
|
*/
|
|
120
130
|
match: (e, {
|
|
121
131
|
success: s,
|
|
122
|
-
failure:
|
|
123
|
-
loading:
|
|
124
|
-
notAsked:
|
|
125
|
-
}) => u.isSuccess(e) ? s(e.value) : u.isFailure(e) ?
|
|
132
|
+
failure: r,
|
|
133
|
+
loading: t,
|
|
134
|
+
notAsked: l = t
|
|
135
|
+
}) => u.isSuccess(e) ? s(e.value) : u.isFailure(e) ? r(e.error) : u.isNotAsked(e) ? l() : t(e.previousValue),
|
|
126
136
|
/**
|
|
127
137
|
* When the result is a success, it applies the function to the value.
|
|
128
138
|
*
|
|
@@ -140,7 +150,32 @@ const u = {
|
|
|
140
150
|
* @returns The result that was passed in.
|
|
141
151
|
* @public
|
|
142
152
|
*/
|
|
143
|
-
whenFailure: (e, s) => (u.isFailure(e) && s(e.error), e)
|
|
153
|
+
whenFailure: (e, s) => (u.isFailure(e) && s(e.error), e),
|
|
154
|
+
/**
|
|
155
|
+
* Compares two results for equality.
|
|
156
|
+
* @param r1 - The first result.
|
|
157
|
+
* @param r2 - The second result.
|
|
158
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
159
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
160
|
+
*/
|
|
161
|
+
equals: (e, s, r = {
|
|
162
|
+
valueEquals: (t, l) => t === l,
|
|
163
|
+
errorEquals: (t, l) => t === l
|
|
164
|
+
}) => 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",
|
|
165
|
+
/**
|
|
166
|
+
* Combines multiple results into a single result.
|
|
167
|
+
* @param results - The results to combine.
|
|
168
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
169
|
+
*/
|
|
170
|
+
all: (e) => {
|
|
171
|
+
const s = [];
|
|
172
|
+
for (const r of e)
|
|
173
|
+
if (u.isSuccess(r))
|
|
174
|
+
s.push(r.value);
|
|
175
|
+
else
|
|
176
|
+
return r;
|
|
177
|
+
return u.success(s);
|
|
178
|
+
}
|
|
144
179
|
};
|
|
145
180
|
export {
|
|
146
181
|
u as AsyncResult
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./array.cjs"),l=require("./async-result.cjs"),i=require("./bigint.cjs"),a=require("./equal.cjs"),n=require("./function.cjs"),t=require("./number.cjs"),s=require("./object.cjs"),c=require("./promise.cjs"),p=require("./regexp.cjs"),o=require("./result-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./array.cjs"),l=require("./async-result.cjs"),i=require("./bigint.cjs"),a=require("./equal.cjs"),n=require("./function.cjs"),t=require("./number.cjs"),s=require("./object.cjs"),c=require("./promise.cjs"),p=require("./regexp.cjs"),o=require("./result-CdwVhaAc.cjs"),e=require("./string.cjs");exports.allElements=r.allElements;exports.anyElement=r.anyElement;exports.applyArrayDiffOperations=r.applyArrayDiffOperations;exports.areArraysEqual=r.areArraysEqual;exports.arrayDiffOperations=r.arrayDiffOperations;exports.arrayHasValues=r.arrayHasValues;exports.arrayHead=r.arrayHead;exports.arrayOfIterableIterator=r.arrayOfIterableIterator;exports.arrayTail=r.arrayTail;exports.compareArrays=r.compareArrays;exports.concatArrays=r.concatArrays;exports.createFilledArray=r.createFilledArray;exports.filterArray=r.filterArray;exports.filterMapArray=r.filterMapArray;exports.filterNullsFromArray=r.filterNullsFromArray;exports.flatMapArray=r.flatMapArray;exports.flattenArray=r.flattenArray;exports.foldLeftArray=r.foldLeftArray;exports.forEachElement=r.forEachElement;exports.generateArray=r.generateArray;exports.generateSequenceArray=r.generateSequenceArray;exports.isArrayEmpty=r.isArrayEmpty;exports.joinArrayWithConjunction=r.joinArrayWithConjunction;exports.mapArray=r.mapArray;exports.rankArray=r.rankArray;exports.removeAllFromArray=r.removeAllFromArray;exports.removeAllFromArrayByPredicate=r.removeAllFromArrayByPredicate;exports.removeOneFromArray=r.removeOneFromArray;exports.removeOneFromArrayByPredicate=r.removeOneFromArrayByPredicate;exports.sortArray=r.sortArray;exports.uniqueByPrimitive=r.uniqueByPrimitive;exports.uniquePrimitives=r.uniquePrimitives;exports.AsyncResult=l.AsyncResult;exports.biAbs=i.biAbs;exports.biCeilDiv=i.biCeilDiv;exports.biCompare=i.biCompare;exports.biFloorDiv=i.biFloorDiv;exports.biGcd=i.biGcd;exports.biIsEven=i.biIsEven;exports.biIsNegative=i.biIsNegative;exports.biIsOdd=i.biIsOdd;exports.biIsOne=i.biIsOne;exports.biIsPositive=i.biIsPositive;exports.biIsPrime=i.biIsPrime;exports.biIsZero=i.biIsZero;exports.biLcm=i.biLcm;exports.biMax=i.biMax;exports.biMin=i.biMin;exports.biNextPrime=i.biNextPrime;exports.biPow=i.biPow;exports.biPrevPrime=i.biPrevPrime;exports.deepEqual=a.deepEqual;exports.looseEqual=a.looseEqual;exports.strictEqual=a.strictEqual;exports.curryLeft=n.curryLeft;exports.identity=n.identity;exports.memoize=n.memoize;exports.EPSILON=t.EPSILON;exports.angleDifference=t.angleDifference;exports.ceilTo=t.ceilTo;exports.clamp=t.clamp;exports.clampInt=t.clampInt;exports.clampSym=t.clampSym;exports.compareNumbers=t.compareNumbers;exports.floorTo=t.floorTo;exports.interpolate=t.interpolate;exports.interpolateAngle=t.interpolateAngle;exports.interpolateAngleCCW=t.interpolateAngleCCW;exports.interpolateAngleCW=t.interpolateAngleCW;exports.interpolateWidestAngle=t.interpolateWidestAngle;exports.nearEqualAngles=t.nearEqualAngles;exports.nearEquals=t.nearEquals;exports.nearZero=t.nearZero;exports.root=t.root;exports.roundTo=t.roundTo;exports.sign=t.sign;exports.toHex=t.toHex;exports.widestAngleDifference=t.widestAngleDifference;exports.wrap=t.wrap;exports.wrapCircular=t.wrapCircular;exports.isEmptyObject=s.isEmptyObject;exports.isObject=s.isObject;exports.mergeObjects=s.mergeObjects;exports.objectKeys=s.objectKeys;exports.removeObjectFields=s.removeObjectFields;exports.sameObjectKeys=s.sameObjectKeys;exports.sleep=c.sleep;exports.mapRegExp=p.mapRegExp;exports.Result=o.Result;exports.Validation=o.Validation;exports.canonicalizeNewlines=e.canonicalizeNewlines;exports.capitalize=e.capitalize;exports.capitalizeWords=e.capitalizeWords;exports.chunkString=e.chunkString;exports.collapseText=e.collapseText;exports.compareCaseInsensitive=e.compareCaseInsensitive;exports.compareStrings=e.compareStrings;exports.containsAllText=e.containsAllText;exports.containsAllTextCaseInsensitive=e.containsAllTextCaseInsensitive;exports.containsAnyText=e.containsAnyText;exports.containsAnyTextCaseInsensitive=e.containsAnyTextCaseInsensitive;exports.countStringOccurrences=e.countStringOccurrences;exports.dasherize=e.dasherize;exports.decodeBase64=e.decodeBase64;exports.deleteFirstFromString=e.deleteFirstFromString;exports.deleteStringAfter=e.deleteStringAfter;exports.deleteStringBefore=e.deleteStringBefore;exports.deleteSubstring=e.deleteSubstring;exports.ellipsis=e.ellipsis;exports.ellipsisMiddle=e.ellipsisMiddle;exports.encodeBase64=e.encodeBase64;exports.filterCharcodes=e.filterCharcodes;exports.filterChars=e.filterChars;exports.humanize=e.humanize;exports.ifEmptyString=e.ifEmptyString;exports.isAlpha=e.isAlpha;exports.isAlphaNum=e.isAlphaNum;exports.isBreakingWhitespace=e.isBreakingWhitespace;exports.isDigitsOnly=e.isDigitsOnly;exports.isEmptyString=e.isEmptyString;exports.isLowerCase=e.isLowerCase;exports.isSpaceAt=e.isSpaceAt;exports.isUpperCase=e.isUpperCase;exports.jsQuote=e.jsQuote;exports.lowerCaseFirst=e.lowerCaseFirst;exports.lpad=e.lpad;exports.mapChars=e.mapChars;exports.quote=e.quote;exports.randomString=e.randomString;exports.randomStringSequence=e.randomStringSequence;exports.randomStringSequenceBase64=e.randomStringSequenceBase64;exports.repeatString=e.repeatString;exports.replaceAll=e.replaceAll;exports.reverseString=e.reverseString;exports.rpad=e.rpad;exports.smartQuote=e.smartQuote;exports.splitStringOnFirst=e.splitStringOnFirst;exports.splitStringOnLast=e.splitStringOnLast;exports.splitStringOnce=e.splitStringOnce;exports.stringContains=e.stringContains;exports.stringEndsWith=e.stringEndsWith;exports.stringEndsWithAny=e.stringEndsWithAny;exports.stringHasContent=e.stringHasContent;exports.stringHashCode=e.stringHashCode;exports.stringStartsWith=e.stringStartsWith;exports.stringStartsWithAny=e.stringStartsWithAny;exports.stringToCharcodes=e.stringToCharcodes;exports.stringToChars=e.stringToChars;exports.stringsDifferAtIndex=e.stringsDifferAtIndex;exports.substringAfter=e.substringAfter;exports.substringAfterLast=e.substringAfterLast;exports.substringBefore=e.substringBefore;exports.substringBeforeLast=e.substringBeforeLast;exports.surroundString=e.surroundString;exports.textContainsCaseInsensitive=e.textContainsCaseInsensitive;exports.textEndsWithAnyCaseInsensitive=e.textEndsWithAnyCaseInsensitive;exports.textEndsWithCaseInsensitive=e.textEndsWithCaseInsensitive;exports.textStartsWithAnyCaseInsensitive=e.textStartsWithAnyCaseInsensitive;exports.textStartsWithCaseInsensitive=e.textStartsWithCaseInsensitive;exports.textToLines=e.textToLines;exports.trimChars=e.trimChars;exports.trimCharsLeft=e.trimCharsLeft;exports.trimCharsRight=e.trimCharsRight;exports.trimStringSlice=e.trimStringSlice;exports.underscore=e.underscore;exports.upperCaseFirst=e.upperCaseFirst;exports.wrapColumns=e.wrapColumns;exports.wrapLine=e.wrapLine;
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { allElements as t, anyElement as i, applyArrayDiffOperations as a, areArraysEqual as s, arrayDiffOperations as n, arrayHasValues as o, arrayHead as l, arrayOfIterableIterator as p, arrayTail as m, compareArrays as c, concatArrays as g, createFilledArray as y, filterArray as A, filterMapArray as
|
|
1
|
+
import { allElements as t, anyElement as i, applyArrayDiffOperations as a, areArraysEqual as s, arrayDiffOperations as n, arrayHasValues as o, arrayHead as l, arrayOfIterableIterator as p, arrayTail as m, compareArrays as c, concatArrays as g, createFilledArray as y, filterArray as A, filterMapArray as f, filterNullsFromArray as d, flatMapArray as u, flattenArray as b, foldLeftArray as C, forEachElement as S, generateArray as x, generateSequenceArray as h, isArrayEmpty as v, joinArrayWithConjunction as E, mapArray as I, rankArray as O, removeAllFromArray as W, removeAllFromArrayByPredicate as F, removeOneFromArray as q, removeOneFromArrayByPredicate as T, sortArray as L, uniqueByPrimitive as P, uniquePrimitives as B } from "./array.js";
|
|
2
2
|
import { AsyncResult as w } from "./async-result.js";
|
|
3
3
|
import { biAbs as N, biCeilDiv as z, biCompare as H, biFloorDiv as M, biGcd as R, biIsEven as k, biIsNegative as V, biIsOdd as K, biIsOne as Q, biIsPositive as Z, biIsPrime as G, biIsZero as U, biLcm as J, biMax as X, biMin as Y, biNextPrime as _, biPow as $, biPrevPrime as ee } from "./bigint.js";
|
|
4
4
|
import { deepEqual as te, looseEqual as ie, strictEqual as ae } from "./equal.js";
|
|
5
5
|
import { curryLeft as ne, identity as oe, memoize as le } from "./function.js";
|
|
6
|
-
import { EPSILON as me, angleDifference as ce, ceilTo as ge, clamp as ye, clampInt as Ae, clampSym as
|
|
6
|
+
import { EPSILON as me, angleDifference as ce, ceilTo as ge, clamp as ye, clampInt as Ae, clampSym as fe, compareNumbers as de, floorTo as ue, interpolate as be, interpolateAngle as Ce, interpolateAngleCCW as Se, interpolateAngleCW as xe, interpolateWidestAngle as he, nearEqualAngles as ve, nearEquals as Ee, nearZero as Ie, root as Oe, roundTo as We, sign as Fe, toHex as qe, widestAngleDifference as Te, wrap as Le, wrapCircular as Pe } from "./number.js";
|
|
7
7
|
import { isEmptyObject as je, isObject as we, mergeObjects as De, objectKeys as Ne, removeObjectFields as ze, sameObjectKeys as He } from "./object.js";
|
|
8
8
|
import { sleep as Re } from "./promise.js";
|
|
9
9
|
import { mapRegExp as Ve } from "./regexp.js";
|
|
10
|
-
import { R as Qe, V as Ze } from "./result-
|
|
11
|
-
import { canonicalizeNewlines as Ue, capitalize as Je, capitalizeWords as Xe, chunkString as Ye, collapseText as _e, compareCaseInsensitive as $e, compareStrings as er, containsAllText as rr, containsAllTextCaseInsensitive as tr, containsAnyText as ir, containsAnyTextCaseInsensitive as ar, countStringOccurrences as sr, dasherize as nr, decodeBase64 as or, deleteFirstFromString as lr, deleteStringAfter as pr, deleteStringBefore as mr, deleteSubstring as cr, ellipsis as gr, ellipsisMiddle as yr, encodeBase64 as Ar, filterCharcodes as
|
|
10
|
+
import { R as Qe, V as Ze } from "./result-CGd0jCdl.js";
|
|
11
|
+
import { canonicalizeNewlines as Ue, capitalize as Je, capitalizeWords as Xe, chunkString as Ye, collapseText as _e, compareCaseInsensitive as $e, compareStrings as er, containsAllText as rr, containsAllTextCaseInsensitive as tr, containsAnyText as ir, containsAnyTextCaseInsensitive as ar, countStringOccurrences as sr, dasherize as nr, decodeBase64 as or, deleteFirstFromString as lr, deleteStringAfter as pr, deleteStringBefore as mr, deleteSubstring as cr, ellipsis as gr, ellipsisMiddle as yr, encodeBase64 as Ar, filterCharcodes as fr, filterChars as dr, humanize as ur, ifEmptyString as br, isAlpha as Cr, isAlphaNum as Sr, isBreakingWhitespace as xr, isDigitsOnly as hr, isEmptyString as vr, isLowerCase as Er, isSpaceAt as Ir, isUpperCase as Or, jsQuote as Wr, lowerCaseFirst as Fr, lpad as qr, mapChars as Tr, quote as Lr, randomString as Pr, randomStringSequence as Br, randomStringSequenceBase64 as jr, repeatString as wr, replaceAll as Dr, reverseString as Nr, rpad as zr, smartQuote as Hr, splitStringOnFirst as Mr, splitStringOnLast as Rr, splitStringOnce as kr, stringContains as Vr, stringEndsWith as Kr, stringEndsWithAny as Qr, stringHasContent as Zr, stringHashCode as Gr, stringStartsWith as Ur, stringStartsWithAny as Jr, stringToCharcodes as Xr, stringToChars as Yr, stringsDifferAtIndex as _r, substringAfter as $r, substringAfterLast as et, substringBefore as rt, substringBeforeLast as tt, surroundString as it, textContainsCaseInsensitive as at, textEndsWithAnyCaseInsensitive as st, textEndsWithCaseInsensitive as nt, textStartsWithAnyCaseInsensitive as ot, textStartsWithCaseInsensitive as lt, textToLines as pt, trimChars as mt, trimCharsLeft as ct, trimCharsRight as gt, trimStringSlice as yt, underscore as At, upperCaseFirst as ft, wrapColumns as dt, wrapLine as ut } from "./string.js";
|
|
12
12
|
export {
|
|
13
13
|
w as AsyncResult,
|
|
14
14
|
me as EPSILON,
|
|
@@ -49,11 +49,11 @@ export {
|
|
|
49
49
|
Ye as chunkString,
|
|
50
50
|
ye as clamp,
|
|
51
51
|
Ae as clampInt,
|
|
52
|
-
|
|
52
|
+
fe as clampSym,
|
|
53
53
|
_e as collapseText,
|
|
54
54
|
c as compareArrays,
|
|
55
55
|
$e as compareCaseInsensitive,
|
|
56
|
-
|
|
56
|
+
de as compareNumbers,
|
|
57
57
|
er as compareStrings,
|
|
58
58
|
g as concatArrays,
|
|
59
59
|
rr as containsAllText,
|
|
@@ -74,10 +74,10 @@ export {
|
|
|
74
74
|
yr as ellipsisMiddle,
|
|
75
75
|
Ar as encodeBase64,
|
|
76
76
|
A as filterArray,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
fr as filterCharcodes,
|
|
78
|
+
dr as filterChars,
|
|
79
|
+
f as filterMapArray,
|
|
80
|
+
d as filterNullsFromArray,
|
|
81
81
|
u as flatMapArray,
|
|
82
82
|
b as flattenArray,
|
|
83
83
|
ue as floorTo,
|
|
@@ -170,12 +170,12 @@ export {
|
|
|
170
170
|
gt as trimCharsRight,
|
|
171
171
|
yt as trimStringSlice,
|
|
172
172
|
At as underscore,
|
|
173
|
-
P as
|
|
173
|
+
P as uniqueByPrimitive,
|
|
174
174
|
B as uniquePrimitives,
|
|
175
|
-
|
|
175
|
+
ft as upperCaseFirst,
|
|
176
176
|
Te as widestAngleDifference,
|
|
177
177
|
Le as wrap,
|
|
178
178
|
Pe as wrapCircular,
|
|
179
|
-
|
|
179
|
+
dt as wrapColumns,
|
|
180
180
|
ut as wrapLine
|
|
181
181
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AsyncResult as
|
|
2
|
-
const
|
|
1
|
+
import { AsyncResult as c } from "./async-result.js";
|
|
2
|
+
const a = {
|
|
3
3
|
/**
|
|
4
4
|
* Creates a valid `Validation`.
|
|
5
5
|
* @returns A `Validation` that is `Valid`.
|
|
@@ -37,14 +37,14 @@ const t = {
|
|
|
37
37
|
* @param invalid - The mapping function for an invalid value.
|
|
38
38
|
* @returns The mapped value.
|
|
39
39
|
*/
|
|
40
|
-
match: (e, s, r) =>
|
|
40
|
+
match: (e, s, r) => a.isValid(e) ? s() : r(e.error),
|
|
41
41
|
/**
|
|
42
42
|
* Maps the value of a `Validation` to a new `Validation`.
|
|
43
43
|
* @param validation - The `Validation` to map.
|
|
44
44
|
* @param value - The value to map.
|
|
45
45
|
* @returns A new `Validation` with the mapped value.
|
|
46
46
|
*/
|
|
47
|
-
toResult: (e, s) =>
|
|
47
|
+
toResult: (e, s) => a.match(
|
|
48
48
|
e,
|
|
49
49
|
() => u.success(s),
|
|
50
50
|
(r) => u.failure(r)
|
|
@@ -56,7 +56,7 @@ const t = {
|
|
|
56
56
|
* @param apply - The function to execute when the `Validation` is valid.
|
|
57
57
|
* @returns The `Validation` object.
|
|
58
58
|
*/
|
|
59
|
-
whenValid: (e, s) => (
|
|
59
|
+
whenValid: (e, s) => (a.isValid(e) && s(), e),
|
|
60
60
|
/**
|
|
61
61
|
* Execute a function when the `Validation` is invalid.
|
|
62
62
|
*
|
|
@@ -64,7 +64,7 @@ const t = {
|
|
|
64
64
|
* @param apply - The function to execute when the `Validation` is invalid.
|
|
65
65
|
* @returns The `Validation` object.
|
|
66
66
|
*/
|
|
67
|
-
whenInvalid: (e, s) => (
|
|
67
|
+
whenInvalid: (e, s) => (a.isInvalid(e) && s(e.error), e)
|
|
68
68
|
}, u = {
|
|
69
69
|
/**
|
|
70
70
|
* Creates a successful `Result`.
|
|
@@ -111,8 +111,8 @@ const t = {
|
|
|
111
111
|
toAsync(e) {
|
|
112
112
|
return u.match(
|
|
113
113
|
e,
|
|
114
|
-
(s) =>
|
|
115
|
-
(s) =>
|
|
114
|
+
(s) => c.success(s),
|
|
115
|
+
(s) => c.failure(s)
|
|
116
116
|
);
|
|
117
117
|
},
|
|
118
118
|
/**
|
|
@@ -124,8 +124,8 @@ const t = {
|
|
|
124
124
|
toValidation(e) {
|
|
125
125
|
return u.match(
|
|
126
126
|
e,
|
|
127
|
-
() =>
|
|
128
|
-
(s) =>
|
|
127
|
+
() => a.valid,
|
|
128
|
+
(s) => a.invalid(s)
|
|
129
129
|
);
|
|
130
130
|
},
|
|
131
131
|
/**
|
|
@@ -184,6 +184,16 @@ const t = {
|
|
|
184
184
|
getOrUndefined(e) {
|
|
185
185
|
return u.isSuccess(e) ? e.value : void 0;
|
|
186
186
|
},
|
|
187
|
+
/**
|
|
188
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
189
|
+
* @param r - The `Result` to get the value from.
|
|
190
|
+
* @returns The value of the `Result` if it is a `Success`.
|
|
191
|
+
*/
|
|
192
|
+
getUnsafe: (e) => {
|
|
193
|
+
if (u.isSuccess(e))
|
|
194
|
+
return e.value;
|
|
195
|
+
throw e.error;
|
|
196
|
+
},
|
|
187
197
|
/**
|
|
188
198
|
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
189
199
|
* @param success - The function to call if the result is a success.
|
|
@@ -209,22 +219,47 @@ const t = {
|
|
|
209
219
|
* @returns The combined result.
|
|
210
220
|
* @public
|
|
211
221
|
*/
|
|
212
|
-
combine: (e, s, r,
|
|
222
|
+
combine: (e, s, r, i) => u.match(
|
|
213
223
|
e,
|
|
214
|
-
(
|
|
224
|
+
(t) => u.match(
|
|
215
225
|
s,
|
|
216
|
-
(
|
|
217
|
-
(
|
|
226
|
+
(l) => u.success(r(t, l)),
|
|
227
|
+
(l) => u.failure(l)
|
|
218
228
|
),
|
|
219
|
-
(
|
|
229
|
+
(t) => u.match(
|
|
220
230
|
s,
|
|
221
231
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
222
|
-
(
|
|
223
|
-
(
|
|
232
|
+
(l) => u.failure(t),
|
|
233
|
+
(l) => u.failure(i(t, l))
|
|
224
234
|
)
|
|
225
|
-
)
|
|
235
|
+
),
|
|
236
|
+
/**
|
|
237
|
+
* Compares two results for equality.
|
|
238
|
+
* @param r1 - The first result.
|
|
239
|
+
* @param r2 - The second result.
|
|
240
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
241
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
242
|
+
*/
|
|
243
|
+
equals: (e, s, r = {
|
|
244
|
+
valueEquals: (i, t) => i === t,
|
|
245
|
+
errorEquals: (i, t) => i === t
|
|
246
|
+
}) => e.type === "Success" && s.type === "Success" ? r.valueEquals(e.value, s.value) : e.type === "Failure" && s.type === "Failure" ? r.errorEquals(e.error, s.error) : !1,
|
|
247
|
+
/**
|
|
248
|
+
* Combines multiple results into a single result.
|
|
249
|
+
* @param results - The results to combine.
|
|
250
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
251
|
+
*/
|
|
252
|
+
all: (e) => {
|
|
253
|
+
const s = [];
|
|
254
|
+
for (const r of e)
|
|
255
|
+
if (u.isSuccess(r))
|
|
256
|
+
s.push(r.value);
|
|
257
|
+
else
|
|
258
|
+
return r;
|
|
259
|
+
return u.success(s);
|
|
260
|
+
}
|
|
226
261
|
};
|
|
227
262
|
export {
|
|
228
263
|
u as R,
|
|
229
|
-
|
|
264
|
+
a as V
|
|
230
265
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const c=require("./async-result.cjs"),l={valid:{type:"valid"},invalid(e){return{type:"invalid",error:e}},isValid(e){return e.type==="valid"},isInvalid(e){return e.type==="invalid"},match:(e,s,r)=>l.isValid(e)?s():r(e.error),toResult:(e,s)=>l.match(e,()=>u.success(s),r=>u.failure(r)),whenValid:(e,s)=>(l.isValid(e)&&s(),e),whenInvalid:(e,s)=>(l.isInvalid(e)&&s(e.error),e)},u={success(e){return{type:"Success",value:e}},failure(e){return{type:"Failure",error:e}},map:(e,s)=>e.type==="Success"?u.success(s(e.value)):e,flatMap:(e,s)=>e.type==="Success"?s(e.value):e,toAsync(e){return u.match(e,s=>c.AsyncResult.success(s),s=>c.AsyncResult.failure(s))},toValidation(e){return u.match(e,()=>l.valid,s=>l.invalid(s))},isSuccess(e){return e.type==="Success"},isFailure(e){return e.type==="Failure"},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 e.error},match:(e,s,r)=>u.isSuccess(e)?s(e.value):r(e.error),whenSuccess:(e,s)=>(u.isSuccess(e)&&s(e.value),e),whenFailure:(e,s)=>(u.isFailure(e)&&s(e.error),e),combine:(e,s,r,i)=>u.match(e,t=>u.match(s,a=>u.success(r(t,a)),a=>u.failure(a)),t=>u.match(s,a=>u.failure(t),a=>u.failure(i(t,a)))),equals:(e,s,r={valueEquals:(i,t)=>i===t,errorEquals:(i,t)=>i===t})=>e.type==="Success"&&s.type==="Success"?r.valueEquals(e.value,s.value):e.type==="Failure"&&s.type==="Failure"?r.errorEquals(e.error,s.error):!1,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.Result=u;exports.Validation=l;
|
package/result.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./async-result.cjs");const e=require("./result-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./async-result.cjs");const e=require("./result-CdwVhaAc.cjs");exports.Result=e.Result;
|
package/result.d.ts
CHANGED
|
@@ -127,6 +127,12 @@ export declare const Result: {
|
|
|
127
127
|
* @public
|
|
128
128
|
*/
|
|
129
129
|
getOrUndefined<V, E>(r: Result<V, E>): Maybe<V>;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
132
|
+
* @param r - The `Result` to get the value from.
|
|
133
|
+
* @returns The value of the `Result` if it is a `Success`.
|
|
134
|
+
*/
|
|
135
|
+
getUnsafe: <V, E>(r: Result<V, E>) => V;
|
|
130
136
|
/**
|
|
131
137
|
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
132
138
|
* @param success - The function to call if the result is a success.
|
|
@@ -153,4 +159,21 @@ export declare const Result: {
|
|
|
153
159
|
* @public
|
|
154
160
|
*/
|
|
155
161
|
combine: <V, E>(r1: Result<V, E>, r2: Result<V, E>, combineV: (v1: V, v2: V) => V, combineE: (e1: E, e2: E) => E) => Result<V, E>;
|
|
162
|
+
/**
|
|
163
|
+
* Compares two results for equality.
|
|
164
|
+
* @param r1 - The first result.
|
|
165
|
+
* @param r2 - The second result.
|
|
166
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
167
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
168
|
+
*/
|
|
169
|
+
equals: <V, E>(r1: Result<V, E>, r2: Result<V, E>, options?: {
|
|
170
|
+
valueEquals: (v1: V, v2: V) => boolean;
|
|
171
|
+
errorEquals: (e1: E, e2: E) => boolean;
|
|
172
|
+
}) => boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Combines multiple results into a single result.
|
|
175
|
+
* @param results - The results to combine.
|
|
176
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
177
|
+
*/
|
|
178
|
+
all: <V, E>(results: Result<V, E>[]) => Result<V[], E>;
|
|
156
179
|
};
|
package/result.js
CHANGED
package/validation.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./result-CdwVhaAc.cjs");exports.Validation=i.Validation;
|
package/validation.js
CHANGED
package/result-DzdZiQoR.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const a=require("./async-result.cjs"),i={valid:{type:"valid"},invalid(e){return{type:"invalid",error:e}},isValid(e){return e.type==="valid"},isInvalid(e){return e.type==="invalid"},match:(e,s,t)=>i.isValid(e)?s():t(e.error),toResult:(e,s)=>i.match(e,()=>u.success(s),t=>u.failure(t)),whenValid:(e,s)=>(i.isValid(e)&&s(),e),whenInvalid:(e,s)=>(i.isInvalid(e)&&s(e.error),e)},u={success(e){return{type:"Success",value:e}},failure(e){return{type:"Failure",error:e}},map:(e,s)=>e.type==="Success"?u.success(s(e.value)):e,flatMap:(e,s)=>e.type==="Success"?s(e.value):e,toAsync(e){return u.match(e,s=>a.AsyncResult.success(s),s=>a.AsyncResult.failure(s))},toValidation(e){return u.match(e,()=>i.valid,s=>i.invalid(s))},isSuccess(e){return e.type==="Success"},isFailure(e){return e.type==="Failure"},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},match:(e,s,t)=>u.isSuccess(e)?s(e.value):t(e.error),whenSuccess:(e,s)=>(u.isSuccess(e)&&s(e.value),e),whenFailure:(e,s)=>(u.isFailure(e)&&s(e.error),e),combine:(e,s,t,c)=>u.match(e,l=>u.match(s,r=>u.success(t(l,r)),r=>u.failure(r)),l=>u.match(s,r=>u.failure(l),r=>u.failure(c(l,r))))};exports.Result=u;exports.Validation=i;
|