es-toolkit 1.10.0-dev.205 → 1.10.0-dev.207

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/LICENSE CHANGED
@@ -18,4 +18,10 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Some of the test code in this software comes from the lodash library (https://github.com/lodash/lodash).
26
+
27
+ The copyright for this imported test code from lodash is owned by the JS Foundation and other contributors <https://js.foundation/>.
@@ -1,13 +1,4 @@
1
1
  import "../chunk-2MRZANXZ.mjs";
2
- import {
3
- without
4
- } from "../chunk-PYEYV7BY.mjs";
5
- import {
6
- xor
7
- } from "../chunk-L7FQX5MN.mjs";
8
- import {
9
- xorBy
10
- } from "../chunk-Q47NGNXT.mjs";
11
2
  import {
12
3
  xorWith
13
4
  } from "../chunk-QRSJBBFY.mjs";
@@ -20,24 +11,9 @@ import {
20
11
  import {
21
12
  zipWith
22
13
  } from "../chunk-4KYXHZ4R.mjs";
23
- import {
24
- union
25
- } from "../chunk-R6QA7PLZ.mjs";
26
- import {
27
- unionBy
28
- } from "../chunk-NFS7RWWE.mjs";
29
- import {
30
- unionWith
31
- } from "../chunk-2ZCITDMK.mjs";
32
- import {
33
- uniq
34
- } from "../chunk-DVK2N4KC.mjs";
35
14
  import {
36
15
  uniqBy
37
16
  } from "../chunk-OXAZEEGP.mjs";
38
- import {
39
- uniqWith
40
- } from "../chunk-237HGSZS.mjs";
41
17
  import {
42
18
  unzip
43
19
  } from "../chunk-UYZKMBDO.mjs";
@@ -45,16 +21,14 @@ import {
45
21
  unzipWith
46
22
  } from "../chunk-IFNXROZR.mjs";
47
23
  import {
48
- sampleSize
49
- } from "../chunk-EHSKB6DF.mjs";
50
- import "../chunk-GIWAOOFY.mjs";
51
- import "../chunk-SYWMYQYJ.mjs";
24
+ without
25
+ } from "../chunk-PYEYV7BY.mjs";
52
26
  import {
53
- shuffle
54
- } from "../chunk-G7UQ5PUR.mjs";
27
+ xor
28
+ } from "../chunk-L7FQX5MN.mjs";
55
29
  import {
56
- tail
57
- } from "../chunk-OF6NM4G7.mjs";
30
+ xorBy
31
+ } from "../chunk-Q47NGNXT.mjs";
58
32
  import {
59
33
  take
60
34
  } from "../chunk-ME352XO7.mjs";
@@ -71,14 +45,20 @@ import {
71
45
  toFilled
72
46
  } from "../chunk-OP4OAKQJ.mjs";
73
47
  import {
74
- intersectionWith
75
- } from "../chunk-XI7KRD2C.mjs";
48
+ union
49
+ } from "../chunk-R6QA7PLZ.mjs";
76
50
  import {
77
- keyBy
78
- } from "../chunk-AJKZMN2V.mjs";
51
+ uniq
52
+ } from "../chunk-DVK2N4KC.mjs";
79
53
  import {
80
- last
81
- } from "../chunk-KPBQ7OUY.mjs";
54
+ unionBy
55
+ } from "../chunk-NFS7RWWE.mjs";
56
+ import {
57
+ unionWith
58
+ } from "../chunk-2ZCITDMK.mjs";
59
+ import {
60
+ uniqWith
61
+ } from "../chunk-237HGSZS.mjs";
82
62
  import {
83
63
  maxBy
84
64
  } from "../chunk-OOKNBU4V.mjs";
@@ -95,14 +75,16 @@ import {
95
75
  sample
96
76
  } from "../chunk-2KNLZB7V.mjs";
97
77
  import {
98
- flattenDeep
99
- } from "../chunk-ML727RRJ.mjs";
78
+ sampleSize
79
+ } from "../chunk-EHSKB6DF.mjs";
80
+ import "../chunk-GIWAOOFY.mjs";
81
+ import "../chunk-SYWMYQYJ.mjs";
100
82
  import {
101
- forEachRight
102
- } from "../chunk-IEA53J7P.mjs";
83
+ shuffle
84
+ } from "../chunk-G7UQ5PUR.mjs";
103
85
  import {
104
- groupBy
105
- } from "../chunk-E6E4RZLN.mjs";
86
+ tail
87
+ } from "../chunk-OF6NM4G7.mjs";
106
88
  import {
107
89
  head
108
90
  } from "../chunk-HM2JT2RX.mjs";
@@ -116,14 +98,14 @@ import {
116
98
  intersectionBy
117
99
  } from "../chunk-O6UXZR3U.mjs";
118
100
  import {
119
- differenceBy
120
- } from "../chunk-LVWX5B43.mjs";
101
+ intersectionWith
102
+ } from "../chunk-XI7KRD2C.mjs";
121
103
  import {
122
- differenceWith
123
- } from "../chunk-6NVQAHXP.mjs";
104
+ keyBy
105
+ } from "../chunk-AJKZMN2V.mjs";
124
106
  import {
125
- drop
126
- } from "../chunk-S3CORED5.mjs";
107
+ last
108
+ } from "../chunk-KPBQ7OUY.mjs";
127
109
  import {
128
110
  dropRight
129
111
  } from "../chunk-JEKUA56R.mjs";
@@ -136,9 +118,18 @@ import {
136
118
  import {
137
119
  fill
138
120
  } from "../chunk-C4WE4GLC.mjs";
121
+ import {
122
+ flattenDeep
123
+ } from "../chunk-ML727RRJ.mjs";
139
124
  import {
140
125
  flatten
141
126
  } from "../chunk-33MSBDC6.mjs";
127
+ import {
128
+ forEachRight
129
+ } from "../chunk-IEA53J7P.mjs";
130
+ import {
131
+ groupBy
132
+ } from "../chunk-E6E4RZLN.mjs";
142
133
  import {
143
134
  chunk
144
135
  } from "../chunk-E6C5EZQA.mjs";
@@ -151,6 +142,15 @@ import {
151
142
  import {
152
143
  difference
153
144
  } from "../chunk-JPUKH67K.mjs";
145
+ import {
146
+ differenceBy
147
+ } from "../chunk-LVWX5B43.mjs";
148
+ import {
149
+ differenceWith
150
+ } from "../chunk-6NVQAHXP.mjs";
151
+ import {
152
+ drop
153
+ } from "../chunk-S3CORED5.mjs";
154
154
  import "../chunk-2HIMLZE3.mjs";
155
155
  export {
156
156
  chunk,
@@ -0,0 +1,14 @@
1
+ import {
2
+ sum
3
+ } from "./chunk-2SLTL4KL.mjs";
4
+
5
+ // src/math/sumBy.ts
6
+ function sumBy(items, getValue) {
7
+ const nums = items.map((x) => getValue(x));
8
+ return sum(nums);
9
+ }
10
+
11
+ export {
12
+ sumBy
13
+ };
14
+ //# sourceMappingURL=chunk-5L4VWRFX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/sumBy.ts"],"sourcesContent":["import { sum } from './sum.ts';\n\n/**\n * Calculates the sum of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `0`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6\n * sumBy([], x => x.a); // Returns: 0\n */\nexport function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return sum(nums);\n}\n"],"mappings":";;;;;AAiBO,SAAS,MAAS,OAAqB,UAA0C;AACtF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,IAAI,IAAI;AACjB;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-FUS75PJ7.mjs.map
@@ -61,6 +61,7 @@ export { random } from '../math/random.mjs';
61
61
  export { randomInt } from '../math/randomInt.mjs';
62
62
  export { round } from '../math/round.mjs';
63
63
  export { sum } from '../math/sum.mjs';
64
+ export { sumBy } from '../math/sumBy.mjs';
64
65
  export { range } from '../math/range.mjs';
65
66
  export { omit } from '../object/omit.mjs';
66
67
  export { omitBy } from '../object/omitBy.mjs';
@@ -61,6 +61,7 @@ export { random } from '../math/random.js';
61
61
  export { randomInt } from '../math/randomInt.js';
62
62
  export { round } from '../math/round.js';
63
63
  export { sum } from '../math/sum.js';
64
+ export { sumBy } from '../math/sumBy.js';
64
65
  export { range } from '../math/range.js';
65
66
  export { omit } from '../object/omit.js';
66
67
  export { omitBy } from '../object/omitBy.js';
@@ -5031,7 +5031,7 @@ var require_lodash = __commonJS({
5031
5031
  function sum2(array) {
5032
5032
  return array && array.length ? baseSum(array, identity) : 0;
5033
5033
  }
5034
- function sumBy(array, iteratee2) {
5034
+ function sumBy2(array, iteratee2) {
5035
5035
  return array && array.length ? baseSum(array, getIteratee(iteratee2, 2)) : 0;
5036
5036
  }
5037
5037
  lodash.after = after;
@@ -5318,7 +5318,7 @@ var require_lodash = __commonJS({
5318
5318
  lodash.startsWith = startsWith;
5319
5319
  lodash.subtract = subtract;
5320
5320
  lodash.sum = sum2;
5321
- lodash.sumBy = sumBy;
5321
+ lodash.sumBy = sumBy2;
5322
5322
  lodash.template = template;
5323
5323
  lodash.times = times;
5324
5324
  lodash.toFinite = toFinite;
@@ -5588,6 +5588,7 @@ __export(compat_exports, {
5588
5588
  shuffle: () => shuffle,
5589
5589
  snakeCase: () => snakeCase,
5590
5590
  sum: () => sum,
5591
+ sumBy: () => sumBy,
5591
5592
  tail: () => tail,
5592
5593
  take: () => take,
5593
5594
  takeRight: () => takeRight,
@@ -6247,6 +6248,12 @@ function round(value, precision = 0) {
6247
6248
  return Math.round(value * multiplier) / multiplier;
6248
6249
  }
6249
6250
 
6251
+ // src/math/sumBy.ts
6252
+ function sumBy(items, getValue) {
6253
+ const nums = items.map((x) => getValue(x));
6254
+ return sum(nums);
6255
+ }
6256
+
6250
6257
  // src/math/range.ts
6251
6258
  function range(start, end, step) {
6252
6259
  if (end == null) {
@@ -6540,6 +6547,7 @@ function chunk2(arr, size = 1) {
6540
6547
  shuffle,
6541
6548
  snakeCase,
6542
6549
  sum,
6550
+ sumBy,
6543
6551
  tail,
6544
6552
  take,
6545
6553
  takeRight,