@zelgadis87/utils-core 5.2.4 → 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 +8 -0
- package/dist/Optional.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +0 -2
- package/dist/utils/operations.d.ts +16 -6
- package/esbuild/index.cjs +17 -17
- package/esbuild/index.cjs.map +4 -4
- package/esbuild/index.mjs +16 -15
- package/esbuild/index.mjs.map +4 -4
- package/package.json +1 -1
- package/src/Optional.ts +7 -0
- package/src/utils/arrays.ts +0 -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;
|
|
@@ -1114,6 +1106,16 @@ function tryToParseNumber(numberStr) {
|
|
|
1114
1106
|
});
|
|
1115
1107
|
}
|
|
1116
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
|
+
|
|
1117
1119
|
// src/utils/promises.ts
|
|
1118
1120
|
function asPromise(promisable) {
|
|
1119
1121
|
return Promise.resolve(promisable);
|
|
@@ -2810,6 +2812,7 @@ export {
|
|
|
2810
2812
|
Logger,
|
|
2811
2813
|
NEVER,
|
|
2812
2814
|
NonExhaustiveSwitchError,
|
|
2815
|
+
Operation,
|
|
2813
2816
|
Optional,
|
|
2814
2817
|
PredicateBuilder,
|
|
2815
2818
|
RandomTimeDuration,
|
|
@@ -2840,7 +2843,6 @@ export {
|
|
|
2840
2843
|
constantTrue,
|
|
2841
2844
|
constantUndefined,
|
|
2842
2845
|
constantZero,
|
|
2843
|
-
countArrayBy,
|
|
2844
2846
|
cssDeclarationRulesDictionaryToCss,
|
|
2845
2847
|
decrement,
|
|
2846
2848
|
decrementBy,
|
|
@@ -2957,7 +2959,6 @@ export {
|
|
|
2957
2959
|
stringToNumber,
|
|
2958
2960
|
stringifyJson,
|
|
2959
2961
|
sum,
|
|
2960
|
-
sumArrayBy,
|
|
2961
2962
|
sumBy,
|
|
2962
2963
|
tail,
|
|
2963
2964
|
throttle,
|