@zelgadis87/utils-core 5.2.3 → 5.2.5
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/CHANGELOG.md +14 -0
- package/dist/Optional.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +1 -2
- package/dist/utils/operations.d.ts +16 -6
- package/esbuild/index.cjs +23 -17
- package/esbuild/index.cjs.map +4 -4
- package/esbuild/index.mjs +21 -15
- package/esbuild/index.mjs.map +4 -4
- package/package.json +1 -1
- package/src/Optional.ts +7 -0
- package/src/utils/arrays.ts +5 -15
- package/src/utils/operations.ts +15 -6
package/esbuild/index.mjs
CHANGED
|
@@ -488,6 +488,11 @@ var Optional = class _Optional {
|
|
|
488
488
|
throw errorProducer();
|
|
489
489
|
return this;
|
|
490
490
|
}
|
|
491
|
+
throwIfPresent(errorProducer) {
|
|
492
|
+
if (this.isEmpty())
|
|
493
|
+
return this;
|
|
494
|
+
throw errorProducer(this.get());
|
|
495
|
+
}
|
|
491
496
|
mapTo(mapper) {
|
|
492
497
|
return this.flatMapTo((t) => _Optional.ofNullable(mapper(t)));
|
|
493
498
|
}
|
|
@@ -832,19 +837,6 @@ function listToDict(arr, mapFn) {
|
|
|
832
837
|
return { ...dict, [key]: value };
|
|
833
838
|
}, {});
|
|
834
839
|
}
|
|
835
|
-
function countArrayBy(arr, mapFn) {
|
|
836
|
-
return arr.reduce((dict, cur) => {
|
|
837
|
-
const value = mapFn(cur);
|
|
838
|
-
const count = (dict[value] ?? 0) + 1;
|
|
839
|
-
return { ...dict, [value]: count };
|
|
840
|
-
}, {});
|
|
841
|
-
}
|
|
842
|
-
function sumArrayBy(arr, mapFn) {
|
|
843
|
-
return arr.reduce((sum2, cur) => {
|
|
844
|
-
const value = mapFn(cur);
|
|
845
|
-
return sum2 + value;
|
|
846
|
-
}, 0);
|
|
847
|
-
}
|
|
848
840
|
function shallowArrayEquals(a, b) {
|
|
849
841
|
if (a === b) return true;
|
|
850
842
|
if (a.length !== b.length) return false;
|
|
@@ -856,6 +848,10 @@ function shallowArrayEquals(a, b) {
|
|
|
856
848
|
function findInArray(arr, predicate) {
|
|
857
849
|
return Optional_default.ofNullable(arr.find(predicate));
|
|
858
850
|
}
|
|
851
|
+
function findIndexInArray(arr, predicate) {
|
|
852
|
+
const idx = arr.findIndex(predicate);
|
|
853
|
+
return idx === -1 ? Optional_default.empty() : Optional_default.of(idx);
|
|
854
|
+
}
|
|
859
855
|
function zip(ts, rs) {
|
|
860
856
|
if (ts.length !== rs.length)
|
|
861
857
|
throw new Error(`Arrays must have the same length. Got ${ts.length} and ${rs.length}`);
|
|
@@ -1110,6 +1106,16 @@ function tryToParseNumber(numberStr) {
|
|
|
1110
1106
|
});
|
|
1111
1107
|
}
|
|
1112
1108
|
|
|
1109
|
+
// src/utils/operations.ts
|
|
1110
|
+
var Operation = {
|
|
1111
|
+
ok: (data) => {
|
|
1112
|
+
return { success: true, data };
|
|
1113
|
+
},
|
|
1114
|
+
ko: (error) => {
|
|
1115
|
+
return { success: false, error };
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1113
1119
|
// src/utils/promises.ts
|
|
1114
1120
|
function asPromise(promisable) {
|
|
1115
1121
|
return Promise.resolve(promisable);
|
|
@@ -2806,6 +2812,7 @@ export {
|
|
|
2806
2812
|
Logger,
|
|
2807
2813
|
NEVER,
|
|
2808
2814
|
NonExhaustiveSwitchError,
|
|
2815
|
+
Operation,
|
|
2809
2816
|
Optional,
|
|
2810
2817
|
PredicateBuilder,
|
|
2811
2818
|
RandomTimeDuration,
|
|
@@ -2836,7 +2843,6 @@ export {
|
|
|
2836
2843
|
constantTrue,
|
|
2837
2844
|
constantUndefined,
|
|
2838
2845
|
constantZero,
|
|
2839
|
-
countArrayBy,
|
|
2840
2846
|
cssDeclarationRulesDictionaryToCss,
|
|
2841
2847
|
decrement,
|
|
2842
2848
|
decrementBy,
|
|
@@ -2862,6 +2868,7 @@ export {
|
|
|
2862
2868
|
filterMapReduce,
|
|
2863
2869
|
filterWithTypePredicate,
|
|
2864
2870
|
findInArray,
|
|
2871
|
+
findIndexInArray,
|
|
2865
2872
|
first,
|
|
2866
2873
|
flatMapTruthys,
|
|
2867
2874
|
getCauseMessageFromError,
|
|
@@ -2952,7 +2959,6 @@ export {
|
|
|
2952
2959
|
stringToNumber,
|
|
2953
2960
|
stringifyJson,
|
|
2954
2961
|
sum,
|
|
2955
|
-
sumArrayBy,
|
|
2956
2962
|
sumBy,
|
|
2957
2963
|
tail,
|
|
2958
2964
|
throttle,
|