@zelgadis87/utils-core 5.0.4 → 5.1.1
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/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/arrays.d.ts +3 -1
- package/dist/utils/records/entries.d.ts +4 -1
- package/esbuild/index.cjs +33 -5
- package/esbuild/index.cjs.map +3 -3
- package/esbuild/index.mjs +28 -4
- package/esbuild/index.mjs.map +3 -3
- package/package.json +1 -1
- package/src/utils/arrays.ts +24 -6
- package/src/utils/records/entries.ts +11 -4
package/esbuild/index.mjs
CHANGED
|
@@ -644,8 +644,24 @@ function mapFirstTruthy(arr, mapFn) {
|
|
|
644
644
|
}
|
|
645
645
|
return null;
|
|
646
646
|
}
|
|
647
|
-
function
|
|
648
|
-
arr.
|
|
647
|
+
function listToDict(arr, mapFn) {
|
|
648
|
+
return arr.reduce((dict, cur) => {
|
|
649
|
+
const [key, value] = mapFn(cur);
|
|
650
|
+
return { ...dict, [key]: value };
|
|
651
|
+
}, {});
|
|
652
|
+
}
|
|
653
|
+
function countArrayBy(arr, mapFn) {
|
|
654
|
+
return arr.reduce((dict, cur) => {
|
|
655
|
+
const value = mapFn(cur);
|
|
656
|
+
const count = (dict[value] ?? 0) + 1;
|
|
657
|
+
return { ...dict, [value]: count };
|
|
658
|
+
}, {});
|
|
659
|
+
}
|
|
660
|
+
function sumArrayBy(arr, mapFn) {
|
|
661
|
+
return arr.reduce((sum2, cur) => {
|
|
662
|
+
const value = mapFn(cur);
|
|
663
|
+
return sum2 + value;
|
|
664
|
+
}, 0);
|
|
649
665
|
}
|
|
650
666
|
|
|
651
667
|
// src/utils/booleans.ts
|
|
@@ -917,9 +933,13 @@ function dictToEntries(obj) {
|
|
|
917
933
|
function entriesToDict(entries) {
|
|
918
934
|
return Object.fromEntries(entries);
|
|
919
935
|
}
|
|
920
|
-
function
|
|
936
|
+
function entriesToEntries(dict, mapper) {
|
|
921
937
|
return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
|
|
922
938
|
}
|
|
939
|
+
var mapEntries = entriesToEntries;
|
|
940
|
+
function mapEntriesToList(dict, mapper) {
|
|
941
|
+
return dictToEntries(dict).map((entry) => mapper(entry));
|
|
942
|
+
}
|
|
923
943
|
|
|
924
944
|
// src/utils/records.ts
|
|
925
945
|
function dictToList(obj) {
|
|
@@ -2714,6 +2734,7 @@ export {
|
|
|
2714
2734
|
constantTrue,
|
|
2715
2735
|
constantUndefined,
|
|
2716
2736
|
constantZero,
|
|
2737
|
+
countArrayBy,
|
|
2717
2738
|
cssDeclarationRulesDictionaryToCss,
|
|
2718
2739
|
decrement,
|
|
2719
2740
|
decrementBy,
|
|
@@ -2730,6 +2751,7 @@ export {
|
|
|
2730
2751
|
ensurePositiveNumber,
|
|
2731
2752
|
ensureReadableArray,
|
|
2732
2753
|
entriesToDict,
|
|
2754
|
+
entriesToEntries,
|
|
2733
2755
|
extendArray,
|
|
2734
2756
|
extendArrayWith,
|
|
2735
2757
|
fill,
|
|
@@ -2779,9 +2801,10 @@ export {
|
|
|
2779
2801
|
isZero,
|
|
2780
2802
|
jsonCloneDeep,
|
|
2781
2803
|
last,
|
|
2782
|
-
|
|
2804
|
+
listToDict,
|
|
2783
2805
|
mapDefined,
|
|
2784
2806
|
mapEntries,
|
|
2807
|
+
mapEntriesToList,
|
|
2785
2808
|
mapFirstTruthy,
|
|
2786
2809
|
mapTruthys,
|
|
2787
2810
|
max,
|
|
@@ -2817,6 +2840,7 @@ export {
|
|
|
2817
2840
|
splitWords,
|
|
2818
2841
|
stringToNumber,
|
|
2819
2842
|
sum,
|
|
2843
|
+
sumArrayBy,
|
|
2820
2844
|
sumBy,
|
|
2821
2845
|
tail,
|
|
2822
2846
|
throttle,
|