es-toolkit 1.10.0 → 1.10.1-dev.211

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.
Files changed (134) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/LICENSE +7 -1
  3. package/dist/array/chunk.mjs +1 -1
  4. package/dist/array/compact.mjs +1 -1
  5. package/dist/array/countBy.mjs +1 -1
  6. package/dist/array/difference.mjs +1 -1
  7. package/dist/array/differenceBy.mjs +1 -1
  8. package/dist/array/differenceWith.mjs +1 -1
  9. package/dist/array/drop.mjs +1 -1
  10. package/dist/array/dropRight.mjs +1 -1
  11. package/dist/array/dropRightWhile.mjs +1 -1
  12. package/dist/array/dropWhile.mjs +1 -1
  13. package/dist/array/fill.mjs +1 -1
  14. package/dist/array/flatten.mjs +1 -1
  15. package/dist/array/flattenDeep.mjs +1 -1
  16. package/dist/array/forEachRight.mjs +1 -1
  17. package/dist/array/groupBy.mjs +1 -1
  18. package/dist/array/head.mjs +1 -1
  19. package/dist/array/index.mjs +17 -17
  20. package/dist/array/initial.mjs +1 -1
  21. package/dist/array/intersection.mjs +1 -1
  22. package/dist/array/intersectionBy.mjs +1 -1
  23. package/dist/array/intersectionWith.mjs +1 -1
  24. package/dist/array/keyBy.mjs +1 -1
  25. package/dist/array/last.mjs +1 -1
  26. package/dist/array/maxBy.mjs +1 -1
  27. package/dist/array/minBy.mjs +1 -1
  28. package/dist/array/orderBy.mjs +1 -1
  29. package/dist/array/partition.mjs +1 -1
  30. package/dist/array/sample.mjs +1 -1
  31. package/dist/array/sampleSize.mjs +1 -1
  32. package/dist/array/shuffle.mjs +1 -1
  33. package/dist/array/tail.mjs +1 -1
  34. package/dist/array/take.mjs +1 -1
  35. package/dist/array/takeRight.mjs +1 -1
  36. package/dist/array/takeRightWhile.mjs +1 -1
  37. package/dist/array/takeWhile.mjs +1 -1
  38. package/dist/array/toFilled.mjs +1 -1
  39. package/dist/array/union.mjs +1 -1
  40. package/dist/array/unionBy.mjs +1 -1
  41. package/dist/array/unionWith.mjs +1 -1
  42. package/dist/array/uniq.mjs +1 -1
  43. package/dist/array/uniqBy.mjs +1 -1
  44. package/dist/array/uniqWith.mjs +1 -1
  45. package/dist/array/unzip.mjs +1 -1
  46. package/dist/array/unzipWith.mjs +1 -1
  47. package/dist/array/without.mjs +1 -1
  48. package/dist/array/xor.mjs +1 -1
  49. package/dist/array/xorBy.mjs +1 -1
  50. package/dist/array/xorWith.mjs +1 -1
  51. package/dist/array/zip.mjs +1 -1
  52. package/dist/array/zipObject.mjs +1 -1
  53. package/dist/array/zipWith.mjs +1 -1
  54. package/dist/chunk-2MM5EJJX.mjs +21 -0
  55. package/dist/chunk-5L4VWRFX.mjs +14 -0
  56. package/dist/chunk-5L4VWRFX.mjs.map +1 -0
  57. package/dist/chunk-FUS75PJ7.mjs +1 -0
  58. package/dist/chunk-NKLIE2OI.mjs +1 -0
  59. package/dist/chunk-NKLIE2OI.mjs.map +1 -0
  60. package/dist/{chunk-4E4D3BMI.mjs → chunk-QZITBKWX.mjs} +2 -2
  61. package/dist/chunk-Y5V7UAZZ.mjs +21 -0
  62. package/dist/chunk-Y5V7UAZZ.mjs.map +1 -0
  63. package/dist/compat/index.d.mts +109 -0
  64. package/dist/compat/index.d.ts +109 -0
  65. package/dist/compat/index.js +1077 -0
  66. package/dist/compat/index.js.map +1 -0
  67. package/dist/compat/index.mjs +355 -0
  68. package/dist/compat/index.mjs.map +1 -0
  69. package/dist/error/AbortError.mjs +1 -1
  70. package/dist/error/index.mjs +1 -1
  71. package/dist/function/debounce.mjs +1 -1
  72. package/dist/function/index.mjs +4 -4
  73. package/dist/function/negate.mjs +1 -1
  74. package/dist/function/noop.mjs +1 -1
  75. package/dist/function/once.mjs +1 -1
  76. package/dist/function/throttle.mjs +1 -1
  77. package/dist/index.d.mts +1 -0
  78. package/dist/index.d.ts +1 -0
  79. package/dist/index.js +14 -5515
  80. package/dist/index.js.map +1 -1
  81. package/dist/index.mjs +75 -70
  82. package/dist/math/clamp.mjs +1 -1
  83. package/dist/math/inRange.mjs +1 -1
  84. package/dist/math/index.d.mts +1 -0
  85. package/dist/math/index.d.ts +1 -0
  86. package/dist/math/index.js +10 -2
  87. package/dist/math/index.js.map +1 -1
  88. package/dist/math/index.mjs +19 -15
  89. package/dist/math/mean.mjs +1 -1
  90. package/dist/math/meanBy.mjs +1 -1
  91. package/dist/math/random.mjs +1 -1
  92. package/dist/math/randomInt.mjs +1 -1
  93. package/dist/math/range.mjs +1 -1
  94. package/dist/math/round.mjs +1 -1
  95. package/dist/math/sum.mjs +1 -1
  96. package/dist/math/sumBy.d.mts +18 -0
  97. package/dist/math/sumBy.d.ts +18 -0
  98. package/dist/math/sumBy.js +45 -0
  99. package/dist/math/sumBy.js.map +1 -0
  100. package/dist/math/sumBy.mjs +9 -0
  101. package/dist/math/sumBy.mjs.map +1 -0
  102. package/dist/object/clone.mjs +1 -1
  103. package/dist/object/index.mjs +5 -5
  104. package/dist/object/invert.mjs +1 -1
  105. package/dist/object/omit.mjs +2 -2
  106. package/dist/object/omitBy.mjs +1 -1
  107. package/dist/object/pick.mjs +1 -1
  108. package/dist/object/pickBy.mjs +1 -1
  109. package/dist/predicate/index.mjs +7 -7
  110. package/dist/predicate/isEqual.mjs +1 -1
  111. package/dist/predicate/isNil.mjs +1 -1
  112. package/dist/predicate/isNotNil.mjs +1 -1
  113. package/dist/predicate/isNull.mjs +1 -1
  114. package/dist/predicate/isUndefined.mjs +1 -1
  115. package/dist/promise/delay.mjs +1 -1
  116. package/dist/promise/index.mjs +1 -1
  117. package/dist/string/camelCase.js +6 -5508
  118. package/dist/string/camelCase.js.map +1 -1
  119. package/dist/string/camelCase.mjs +3 -2
  120. package/dist/string/capitalize.mjs +1 -1
  121. package/dist/string/index.js +6 -5515
  122. package/dist/string/index.js.map +1 -1
  123. package/dist/string/index.mjs +3 -3
  124. package/dist/string/kebabCase.mjs +1 -1
  125. package/dist/string/lowerCase.mjs +1 -1
  126. package/dist/string/snakeCase.mjs +1 -1
  127. package/package.json +1 -1
  128. package/dist/chunk-2HIMLZE3.mjs +0 -46
  129. package/dist/chunk-TLVQSNOE.mjs +0 -1
  130. package/dist/chunk-XGCYC4YA.mjs +0 -5516
  131. package/dist/chunk-XGCYC4YA.mjs.map +0 -1
  132. /package/dist/{chunk-2HIMLZE3.mjs.map → chunk-2MM5EJJX.mjs.map} +0 -0
  133. /package/dist/{chunk-TLVQSNOE.mjs.map → chunk-FUS75PJ7.mjs.map} +0 -0
  134. /package/dist/{chunk-4E4D3BMI.mjs.map → chunk-QZITBKWX.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,7 +1,4 @@
1
- import "./chunk-ARZ5BDR6.mjs";
2
- import {
3
- delay
4
- } from "./chunk-O64NE2P4.mjs";
1
+ import "./chunk-NKLIE2OI.mjs";
5
2
  import "./chunk-QKYYOLJ6.mjs";
6
3
  import {
7
4
  kebabCase
@@ -12,14 +9,43 @@ import {
12
9
  import {
13
10
  snakeCase
14
11
  } from "./chunk-F3WCQQET.mjs";
12
+ import "./chunk-ARZ5BDR6.mjs";
13
+ import {
14
+ delay
15
+ } from "./chunk-O64NE2P4.mjs";
15
16
  import {
16
17
  camelCase
17
- } from "./chunk-XGCYC4YA.mjs";
18
- import "./chunk-WVQ7YVRK.mjs";
18
+ } from "./chunk-Y5V7UAZZ.mjs";
19
19
  import {
20
20
  capitalize
21
21
  } from "./chunk-U56ZOM7L.mjs";
22
+ import "./chunk-WVQ7YVRK.mjs";
23
+ import "./chunk-OSOLEQLZ.mjs";
24
+ import {
25
+ clone
26
+ } from "./chunk-U4JGKZ56.mjs";
27
+ import {
28
+ invert
29
+ } from "./chunk-74WWMNZS.mjs";
30
+ import {
31
+ omit
32
+ } from "./chunk-QZITBKWX.mjs";
33
+ import {
34
+ omitBy
35
+ } from "./chunk-BCTYOXT7.mjs";
36
+ import {
37
+ pick
38
+ } from "./chunk-HPFDYUGP.mjs";
39
+ import {
40
+ pickBy
41
+ } from "./chunk-6CLH5YZ2.mjs";
22
42
  import "./chunk-ASJF5D6C.mjs";
43
+ import {
44
+ isEqual
45
+ } from "./chunk-JYSV56US.mjs";
46
+ import {
47
+ isNil
48
+ } from "./chunk-WMM7TZLG.mjs";
23
49
  import {
24
50
  isNotNil
25
51
  } from "./chunk-BMRTZMRE.mjs";
@@ -29,35 +55,32 @@ import {
29
55
  import {
30
56
  isUndefined
31
57
  } from "./chunk-VH2PV426.mjs";
58
+ import "./chunk-FUS75PJ7.mjs";
32
59
  import {
33
- isEqual
34
- } from "./chunk-JYSV56US.mjs";
60
+ meanBy
61
+ } from "./chunk-IZAD2S7R.mjs";
35
62
  import {
36
- isNil
37
- } from "./chunk-WMM7TZLG.mjs";
38
- import "./chunk-OSOLEQLZ.mjs";
63
+ mean
64
+ } from "./chunk-GDC64SYJ.mjs";
39
65
  import {
40
- invert
41
- } from "./chunk-74WWMNZS.mjs";
66
+ range
67
+ } from "./chunk-DPH2KE6O.mjs";
42
68
  import {
43
- omit
44
- } from "./chunk-4E4D3BMI.mjs";
69
+ round
70
+ } from "./chunk-5PMKOZ2F.mjs";
45
71
  import {
46
- omitBy
47
- } from "./chunk-BCTYOXT7.mjs";
72
+ sumBy
73
+ } from "./chunk-5L4VWRFX.mjs";
48
74
  import {
49
- pick
50
- } from "./chunk-HPFDYUGP.mjs";
75
+ sum
76
+ } from "./chunk-2SLTL4KL.mjs";
51
77
  import {
52
- pickBy
53
- } from "./chunk-6CLH5YZ2.mjs";
78
+ clamp
79
+ } from "./chunk-MLCL773E.mjs";
54
80
  import {
55
- clone
56
- } from "./chunk-U4JGKZ56.mjs";
81
+ inRange
82
+ } from "./chunk-BH6HLGBA.mjs";
57
83
  import "./chunk-2MRZANXZ.mjs";
58
- import {
59
- xor
60
- } from "./chunk-L7FQX5MN.mjs";
61
84
  import {
62
85
  xorBy
63
86
  } from "./chunk-Q47NGNXT.mjs";
@@ -73,9 +96,6 @@ import {
73
96
  import {
74
97
  zipWith
75
98
  } from "./chunk-4KYXHZ4R.mjs";
76
- import {
77
- unionBy
78
- } from "./chunk-NFS7RWWE.mjs";
79
99
  import {
80
100
  unionWith
81
101
  } from "./chunk-2ZCITDMK.mjs";
@@ -95,8 +115,8 @@ import {
95
115
  without
96
116
  } from "./chunk-PYEYV7BY.mjs";
97
117
  import {
98
- shuffle
99
- } from "./chunk-G7UQ5PUR.mjs";
118
+ xor
119
+ } from "./chunk-L7FQX5MN.mjs";
100
120
  import {
101
121
  tail
102
122
  } from "./chunk-OF6NM4G7.mjs";
@@ -122,8 +142,8 @@ import {
122
142
  uniq
123
143
  } from "./chunk-DVK2N4KC.mjs";
124
144
  import {
125
- keyBy
126
- } from "./chunk-AJKZMN2V.mjs";
145
+ unionBy
146
+ } from "./chunk-NFS7RWWE.mjs";
127
147
  import {
128
148
  last
129
149
  } from "./chunk-KPBQ7OUY.mjs";
@@ -146,8 +166,14 @@ import {
146
166
  sampleSize
147
167
  } from "./chunk-EHSKB6DF.mjs";
148
168
  import {
149
- forEachRight
150
- } from "./chunk-IEA53J7P.mjs";
169
+ randomInt
170
+ } from "./chunk-GIWAOOFY.mjs";
171
+ import {
172
+ random
173
+ } from "./chunk-SYWMYQYJ.mjs";
174
+ import {
175
+ shuffle
176
+ } from "./chunk-G7UQ5PUR.mjs";
151
177
  import {
152
178
  groupBy
153
179
  } from "./chunk-E6E4RZLN.mjs";
@@ -167,8 +193,8 @@ import {
167
193
  intersectionWith
168
194
  } from "./chunk-XI7KRD2C.mjs";
169
195
  import {
170
- differenceWith
171
- } from "./chunk-6NVQAHXP.mjs";
196
+ keyBy
197
+ } from "./chunk-AJKZMN2V.mjs";
172
198
  import {
173
199
  drop
174
200
  } from "./chunk-S3CORED5.mjs";
@@ -190,10 +216,9 @@ import {
190
216
  import {
191
217
  flatten
192
218
  } from "./chunk-33MSBDC6.mjs";
193
- import "./chunk-FZEZH22H.mjs";
194
219
  import {
195
- AbortError
196
- } from "./chunk-DXB7EZUQ.mjs";
220
+ forEachRight
221
+ } from "./chunk-IEA53J7P.mjs";
197
222
  import {
198
223
  chunk
199
224
  } from "./chunk-E6C5EZQA.mjs";
@@ -209,32 +234,17 @@ import {
209
234
  import {
210
235
  differenceBy
211
236
  } from "./chunk-LVWX5B43.mjs";
212
- import "./chunk-TLVQSNOE.mjs";
213
- import {
214
- inRange
215
- } from "./chunk-BH6HLGBA.mjs";
216
237
  import {
217
- meanBy
218
- } from "./chunk-IZAD2S7R.mjs";
219
- import {
220
- mean
221
- } from "./chunk-GDC64SYJ.mjs";
222
- import {
223
- sum
224
- } from "./chunk-2SLTL4KL.mjs";
225
- import {
226
- randomInt
227
- } from "./chunk-GIWAOOFY.mjs";
228
- import {
229
- random
230
- } from "./chunk-SYWMYQYJ.mjs";
231
- import {
232
- range
233
- } from "./chunk-DPH2KE6O.mjs";
238
+ differenceWith
239
+ } from "./chunk-6NVQAHXP.mjs";
240
+ import "./chunk-FZEZH22H.mjs";
234
241
  import {
235
- round
236
- } from "./chunk-5PMKOZ2F.mjs";
242
+ AbortError
243
+ } from "./chunk-DXB7EZUQ.mjs";
237
244
  import "./chunk-236H5JZJ.mjs";
245
+ import {
246
+ throttle
247
+ } from "./chunk-QOJGMVVR.mjs";
238
248
  import {
239
249
  debounce
240
250
  } from "./chunk-3IP4JVLL.mjs";
@@ -247,13 +257,7 @@ import {
247
257
  import {
248
258
  once
249
259
  } from "./chunk-CMBC4MXG.mjs";
250
- import {
251
- throttle
252
- } from "./chunk-QOJGMVVR.mjs";
253
- import {
254
- clamp
255
- } from "./chunk-MLCL773E.mjs";
256
- import "./chunk-2HIMLZE3.mjs";
260
+ import "./chunk-2MM5EJJX.mjs";
257
261
  export {
258
262
  AbortError,
259
263
  camelCase,
@@ -315,6 +319,7 @@ export {
315
319
  shuffle,
316
320
  snakeCase,
317
321
  sum,
322
+ sumBy,
318
323
  tail,
319
324
  take,
320
325
  takeRight,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  clamp
3
3
  } from "../chunk-MLCL773E.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  clamp
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  inRange
3
3
  } from "../chunk-BH6HLGBA.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  inRange
7
7
  };
@@ -6,4 +6,5 @@ export { random } from './random.mjs';
6
6
  export { randomInt } from './randomInt.mjs';
7
7
  export { round } from './round.mjs';
8
8
  export { sum } from './sum.mjs';
9
+ export { sumBy } from './sumBy.mjs';
9
10
  export { range } from './range.mjs';
@@ -6,4 +6,5 @@ export { random } from './random.js';
6
6
  export { randomInt } from './randomInt.js';
7
7
  export { round } from './round.js';
8
8
  export { sum } from './sum.js';
9
+ export { sumBy } from './sumBy.js';
9
10
  export { range } from './range.js';
@@ -28,7 +28,8 @@ __export(math_exports, {
28
28
  randomInt: () => randomInt,
29
29
  range: () => range,
30
30
  round: () => round,
31
- sum: () => sum
31
+ sum: () => sum,
32
+ sumBy: () => sumBy
32
33
  });
33
34
  module.exports = __toCommonJS(math_exports);
34
35
 
@@ -98,6 +99,12 @@ function round(value, precision = 0) {
98
99
  return Math.round(value * multiplier) / multiplier;
99
100
  }
100
101
 
102
+ // src/math/sumBy.ts
103
+ function sumBy(items, getValue) {
104
+ const nums = items.map((x) => getValue(x));
105
+ return sum(nums);
106
+ }
107
+
101
108
  // src/math/range.ts
102
109
  function range(start, end, step) {
103
110
  if (end == null) {
@@ -127,6 +134,7 @@ function range(start, end, step) {
127
134
  randomInt,
128
135
  range,
129
136
  round,
130
- sum
137
+ sum,
138
+ sumBy
131
139
  });
132
140
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/inRange.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { inRange } from './inRange.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { range } from './range.ts';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","export function inRange(value: number, maximum: number): boolean;\nexport function inRange(value: number, minimum: number, maximum: number): boolean;\n/**\n * Checks if the value is within a specified range.\n *\n * @param {number} value The value to check.\n * @param {number} minimum The lower bound of the range (inclusive).\n * @param {number} maximum The upper bound of the range (exclusive).\n * @returns {boolean} `true` if the value is within the specified range, otherwise `false`.\n * @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.\n *\n * @example\n * const result1 = inRange(3, 5); // result1 will be true.\n * const result2 = inRange(1, 2, 5); // result2 will be false.\n * const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.\n */\nexport function inRange(value: number, minimum: number, maximum?: number): boolean {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('The maximum value must be greater than the minimum value.');\n }\n\n return minimum <= value && value < maximum;\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the average.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\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 * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\n}\n","/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random.ts';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1`.\n *\n * @param {number} start - The starting number of the range (inclusive).\n * @param {number} [end] - The end number of the range (exclusive).\n * @param {number} [step] - The step value for the range. (default: 1)\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns [0, -1, -2, -3]\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACTO,SAAS,QAAQ,OAAe,SAAiB,SAA2B;AACjF,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AAEA,SAAO,WAAW,SAAS,QAAQ;AACrC;;;ACdO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;;;ACHO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACMO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/inRange.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sumBy.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { inRange } from './inRange.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { sumBy } from './sumBy.ts';\nexport { range } from './range.ts';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","export function inRange(value: number, maximum: number): boolean;\nexport function inRange(value: number, minimum: number, maximum: number): boolean;\n/**\n * Checks if the value is within a specified range.\n *\n * @param {number} value The value to check.\n * @param {number} minimum The lower bound of the range (inclusive).\n * @param {number} maximum The upper bound of the range (exclusive).\n * @returns {boolean} `true` if the value is within the specified range, otherwise `false`.\n * @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.\n *\n * @example\n * const result1 = inRange(3, 5); // result1 will be true.\n * const result2 = inRange(1, 2, 5); // result2 will be false.\n * const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.\n */\nexport function inRange(value: number, minimum: number, maximum?: number): boolean {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('The maximum value must be greater than the minimum value.');\n }\n\n return minimum <= value && value < maximum;\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the average.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\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 * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\n}\n","/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random.ts';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","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","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1`.\n *\n * @param {number} start - The starting number of the range (inclusive).\n * @param {number} [end] - The end number of the range (exclusive).\n * @param {number} [step] - The step value for the range. (default: 1)\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns [0, -1, -2, -3]\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACTO,SAAS,QAAQ,OAAe,SAAiB,SAA2B;AACjF,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AAEA,SAAO,WAAW,SAAS,QAAQ;AACrC;;;ACdO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;;;ACHO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACNO,SAAS,MAAS,OAAqB,UAA0C;AACtF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,IAAI,IAAI;AACjB;;;ACQO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
@@ -1,32 +1,35 @@
1
- import "../chunk-TLVQSNOE.mjs";
2
- import {
3
- inRange
4
- } from "../chunk-BH6HLGBA.mjs";
1
+ import "../chunk-FUS75PJ7.mjs";
5
2
  import {
6
3
  meanBy
7
4
  } from "../chunk-IZAD2S7R.mjs";
8
5
  import {
9
6
  mean
10
7
  } from "../chunk-GDC64SYJ.mjs";
11
- import {
12
- sum
13
- } from "../chunk-2SLTL4KL.mjs";
14
- import {
15
- randomInt
16
- } from "../chunk-GIWAOOFY.mjs";
17
- import {
18
- random
19
- } from "../chunk-SYWMYQYJ.mjs";
20
8
  import {
21
9
  range
22
10
  } from "../chunk-DPH2KE6O.mjs";
23
11
  import {
24
12
  round
25
13
  } from "../chunk-5PMKOZ2F.mjs";
14
+ import {
15
+ sumBy
16
+ } from "../chunk-5L4VWRFX.mjs";
17
+ import {
18
+ sum
19
+ } from "../chunk-2SLTL4KL.mjs";
26
20
  import {
27
21
  clamp
28
22
  } from "../chunk-MLCL773E.mjs";
29
- import "../chunk-2HIMLZE3.mjs";
23
+ import {
24
+ inRange
25
+ } from "../chunk-BH6HLGBA.mjs";
26
+ import {
27
+ randomInt
28
+ } from "../chunk-GIWAOOFY.mjs";
29
+ import {
30
+ random
31
+ } from "../chunk-SYWMYQYJ.mjs";
32
+ import "../chunk-2MM5EJJX.mjs";
30
33
  export {
31
34
  clamp,
32
35
  inRange,
@@ -36,6 +39,7 @@ export {
36
39
  randomInt,
37
40
  range,
38
41
  round,
39
- sum
42
+ sum,
43
+ sumBy
40
44
  };
41
45
  //# sourceMappingURL=index.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  mean
3
3
  } from "../chunk-GDC64SYJ.mjs";
4
4
  import "../chunk-2SLTL4KL.mjs";
5
- import "../chunk-2HIMLZE3.mjs";
5
+ import "../chunk-2MM5EJJX.mjs";
6
6
  export {
7
7
  mean
8
8
  };
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-IZAD2S7R.mjs";
4
4
  import "../chunk-GDC64SYJ.mjs";
5
5
  import "../chunk-2SLTL4KL.mjs";
6
- import "../chunk-2HIMLZE3.mjs";
6
+ import "../chunk-2MM5EJJX.mjs";
7
7
  export {
8
8
  meanBy
9
9
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  random
3
3
  } from "../chunk-SYWMYQYJ.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  random
7
7
  };
@@ -2,7 +2,7 @@ import {
2
2
  randomInt
3
3
  } from "../chunk-GIWAOOFY.mjs";
4
4
  import "../chunk-SYWMYQYJ.mjs";
5
- import "../chunk-2HIMLZE3.mjs";
5
+ import "../chunk-2MM5EJJX.mjs";
6
6
  export {
7
7
  randomInt
8
8
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  range
3
3
  } from "../chunk-DPH2KE6O.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  range
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  round
3
3
  } from "../chunk-5PMKOZ2F.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  round
7
7
  };
package/dist/math/sum.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  sum
3
3
  } from "../chunk-2SLTL4KL.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  sum
7
7
  };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Calculates the sum of an array of numbers when applying
3
+ * the `getValue` function to each element.
4
+ *
5
+ * If the array is empty, this function returns `0`.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[]} items An array to calculate the average.
9
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
10
+ * @returns {number} The average of all the numbers as determined by the `getValue` function.
11
+ *
12
+ * @example
13
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
+ * sumBy([], x => x.a); // Returns: 0
15
+ */
16
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+
18
+ export { sumBy };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Calculates the sum of an array of numbers when applying
3
+ * the `getValue` function to each element.
4
+ *
5
+ * If the array is empty, this function returns `0`.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[]} items An array to calculate the average.
9
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
10
+ * @returns {number} The average of all the numbers as determined by the `getValue` function.
11
+ *
12
+ * @example
13
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
+ * sumBy([], x => x.a); // Returns: 0
15
+ */
16
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+
18
+ export { sumBy };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/math/sumBy.ts
21
+ var sumBy_exports = {};
22
+ __export(sumBy_exports, {
23
+ sumBy: () => sumBy
24
+ });
25
+ module.exports = __toCommonJS(sumBy_exports);
26
+
27
+ // src/math/sum.ts
28
+ function sum(nums) {
29
+ let result = 0;
30
+ for (let i = 0; i < nums.length; i++) {
31
+ result += nums[i];
32
+ }
33
+ return result;
34
+ }
35
+
36
+ // src/math/sumBy.ts
37
+ function sumBy(items, getValue) {
38
+ const nums = items.map((x) => getValue(x));
39
+ return sum(nums);
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ sumBy
44
+ });
45
+ //# sourceMappingURL=sumBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/math/sumBy.ts","../../src/math/sum.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","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ADJO,SAAS,MAAS,OAAqB,UAA0C;AACtF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,IAAI,IAAI;AACjB;","names":[]}
@@ -0,0 +1,9 @@
1
+ import {
2
+ sumBy
3
+ } from "../chunk-5L4VWRFX.mjs";
4
+ import "../chunk-2SLTL4KL.mjs";
5
+ import "../chunk-2MM5EJJX.mjs";
6
+ export {
7
+ sumBy
8
+ };
9
+ //# sourceMappingURL=sumBy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  clone
3
3
  } from "../chunk-U4JGKZ56.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  clone
7
7
  };
@@ -1,10 +1,13 @@
1
1
  import "../chunk-OSOLEQLZ.mjs";
2
+ import {
3
+ clone
4
+ } from "../chunk-U4JGKZ56.mjs";
2
5
  import {
3
6
  invert
4
7
  } from "../chunk-74WWMNZS.mjs";
5
8
  import {
6
9
  omit
7
- } from "../chunk-4E4D3BMI.mjs";
10
+ } from "../chunk-QZITBKWX.mjs";
8
11
  import {
9
12
  omitBy
10
13
  } from "../chunk-BCTYOXT7.mjs";
@@ -14,10 +17,7 @@ import {
14
17
  import {
15
18
  pickBy
16
19
  } from "../chunk-6CLH5YZ2.mjs";
17
- import {
18
- clone
19
- } from "../chunk-U4JGKZ56.mjs";
20
- import "../chunk-2HIMLZE3.mjs";
20
+ import "../chunk-2MM5EJJX.mjs";
21
21
  export {
22
22
  clone,
23
23
  invert,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  invert
3
3
  } from "../chunk-74WWMNZS.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  invert
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  omit
3
- } from "../chunk-4E4D3BMI.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
3
+ } from "../chunk-QZITBKWX.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  omit
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  omitBy
3
3
  } from "../chunk-BCTYOXT7.mjs";
4
- import "../chunk-2HIMLZE3.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  omitBy
7
7
  };