@zelgadis87/utils-core 5.0.4 → 5.1.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/esbuild/index.mjs CHANGED
@@ -644,8 +644,24 @@ function mapFirstTruthy(arr, mapFn) {
644
644
  }
645
645
  return null;
646
646
  }
647
- function makeArrayEmpty(arr) {
648
- arr.splice(0, arr.length);
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
@@ -2714,6 +2730,7 @@ export {
2714
2730
  constantTrue,
2715
2731
  constantUndefined,
2716
2732
  constantZero,
2733
+ countArrayBy,
2717
2734
  cssDeclarationRulesDictionaryToCss,
2718
2735
  decrement,
2719
2736
  decrementBy,
@@ -2779,7 +2796,7 @@ export {
2779
2796
  isZero,
2780
2797
  jsonCloneDeep,
2781
2798
  last,
2782
- makeArrayEmpty,
2799
+ listToDict,
2783
2800
  mapDefined,
2784
2801
  mapEntries,
2785
2802
  mapFirstTruthy,
@@ -2817,6 +2834,7 @@ export {
2817
2834
  splitWords,
2818
2835
  stringToNumber,
2819
2836
  sum,
2837
+ sumArrayBy,
2820
2838
  sumBy,
2821
2839
  tail,
2822
2840
  throttle,