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/dist/index.mjs CHANGED
@@ -1,5 +1,8 @@
1
1
  import "./chunk-NKLIE2OI.mjs";
2
2
  import "./chunk-QKYYOLJ6.mjs";
3
+ import {
4
+ capitalize
5
+ } from "./chunk-U56ZOM7L.mjs";
3
6
  import {
4
7
  kebabCase
5
8
  } from "./chunk-EYYZQFOP.mjs";
@@ -17,10 +20,10 @@ import {
17
20
  camelCase
18
21
  } from "./chunk-XGCYC4YA.mjs";
19
22
  import "./chunk-WVQ7YVRK.mjs";
20
- import {
21
- capitalize
22
- } from "./chunk-U56ZOM7L.mjs";
23
23
  import "./chunk-OSOLEQLZ.mjs";
24
+ import {
25
+ clone
26
+ } from "./chunk-U4JGKZ56.mjs";
24
27
  import {
25
28
  invert
26
29
  } from "./chunk-74WWMNZS.mjs";
@@ -37,6 +40,9 @@ import {
37
40
  pickBy
38
41
  } from "./chunk-6CLH5YZ2.mjs";
39
42
  import "./chunk-ASJF5D6C.mjs";
43
+ import {
44
+ isEqual
45
+ } from "./chunk-JYSV56US.mjs";
40
46
  import {
41
47
  isNil
42
48
  } from "./chunk-WMM7TZLG.mjs";
@@ -49,26 +55,11 @@ import {
49
55
  import {
50
56
  isUndefined
51
57
  } from "./chunk-VH2PV426.mjs";
58
+ import "./chunk-FZEZH22H.mjs";
52
59
  import {
53
- isEqual
54
- } from "./chunk-JYSV56US.mjs";
55
- import {
56
- clone
57
- } from "./chunk-U4JGKZ56.mjs";
58
- import "./chunk-236H5JZJ.mjs";
59
- import {
60
- negate
61
- } from "./chunk-BOOQBJN2.mjs";
62
- import {
63
- noop
64
- } from "./chunk-LKXCOLNY.mjs";
65
- import {
66
- once
67
- } from "./chunk-CMBC4MXG.mjs";
68
- import {
69
- throttle
70
- } from "./chunk-QOJGMVVR.mjs";
71
- import "./chunk-TLVQSNOE.mjs";
60
+ AbortError
61
+ } from "./chunk-DXB7EZUQ.mjs";
62
+ import "./chunk-FUS75PJ7.mjs";
72
63
  import {
73
64
  meanBy
74
65
  } from "./chunk-IZAD2S7R.mjs";
@@ -81,6 +72,9 @@ import {
81
72
  import {
82
73
  round
83
74
  } from "./chunk-5PMKOZ2F.mjs";
75
+ import {
76
+ sumBy
77
+ } from "./chunk-5L4VWRFX.mjs";
84
78
  import {
85
79
  sum
86
80
  } from "./chunk-2SLTL4KL.mjs";
@@ -90,19 +84,23 @@ import {
90
84
  import {
91
85
  inRange
92
86
  } from "./chunk-BH6HLGBA.mjs";
87
+ import "./chunk-236H5JZJ.mjs";
88
+ import {
89
+ once
90
+ } from "./chunk-CMBC4MXG.mjs";
91
+ import {
92
+ throttle
93
+ } from "./chunk-QOJGMVVR.mjs";
93
94
  import {
94
95
  debounce
95
96
  } from "./chunk-3IP4JVLL.mjs";
96
- import "./chunk-2MRZANXZ.mjs";
97
- import {
98
- without
99
- } from "./chunk-PYEYV7BY.mjs";
100
97
  import {
101
- xor
102
- } from "./chunk-L7FQX5MN.mjs";
98
+ negate
99
+ } from "./chunk-BOOQBJN2.mjs";
103
100
  import {
104
- xorBy
105
- } from "./chunk-Q47NGNXT.mjs";
101
+ noop
102
+ } from "./chunk-LKXCOLNY.mjs";
103
+ import "./chunk-2MRZANXZ.mjs";
106
104
  import {
107
105
  xorWith
108
106
  } from "./chunk-QRSJBBFY.mjs";
@@ -115,24 +113,9 @@ import {
115
113
  import {
116
114
  zipWith
117
115
  } from "./chunk-4KYXHZ4R.mjs";
118
- import {
119
- union
120
- } from "./chunk-R6QA7PLZ.mjs";
121
- import {
122
- unionBy
123
- } from "./chunk-NFS7RWWE.mjs";
124
- import {
125
- unionWith
126
- } from "./chunk-2ZCITDMK.mjs";
127
- import {
128
- uniq
129
- } from "./chunk-DVK2N4KC.mjs";
130
116
  import {
131
117
  uniqBy
132
118
  } from "./chunk-OXAZEEGP.mjs";
133
- import {
134
- uniqWith
135
- } from "./chunk-237HGSZS.mjs";
136
119
  import {
137
120
  unzip
138
121
  } from "./chunk-UYZKMBDO.mjs";
@@ -140,20 +123,14 @@ import {
140
123
  unzipWith
141
124
  } from "./chunk-IFNXROZR.mjs";
142
125
  import {
143
- sampleSize
144
- } from "./chunk-EHSKB6DF.mjs";
145
- import {
146
- randomInt
147
- } from "./chunk-GIWAOOFY.mjs";
148
- import {
149
- random
150
- } from "./chunk-SYWMYQYJ.mjs";
126
+ without
127
+ } from "./chunk-PYEYV7BY.mjs";
151
128
  import {
152
- shuffle
153
- } from "./chunk-G7UQ5PUR.mjs";
129
+ xor
130
+ } from "./chunk-L7FQX5MN.mjs";
154
131
  import {
155
- tail
156
- } from "./chunk-OF6NM4G7.mjs";
132
+ xorBy
133
+ } from "./chunk-Q47NGNXT.mjs";
157
134
  import {
158
135
  take
159
136
  } from "./chunk-ME352XO7.mjs";
@@ -170,14 +147,20 @@ import {
170
147
  toFilled
171
148
  } from "./chunk-OP4OAKQJ.mjs";
172
149
  import {
173
- intersectionWith
174
- } from "./chunk-XI7KRD2C.mjs";
150
+ union
151
+ } from "./chunk-R6QA7PLZ.mjs";
175
152
  import {
176
- keyBy
177
- } from "./chunk-AJKZMN2V.mjs";
153
+ uniq
154
+ } from "./chunk-DVK2N4KC.mjs";
178
155
  import {
179
- last
180
- } from "./chunk-KPBQ7OUY.mjs";
156
+ unionBy
157
+ } from "./chunk-NFS7RWWE.mjs";
158
+ import {
159
+ unionWith
160
+ } from "./chunk-2ZCITDMK.mjs";
161
+ import {
162
+ uniqWith
163
+ } from "./chunk-237HGSZS.mjs";
181
164
  import {
182
165
  maxBy
183
166
  } from "./chunk-OOKNBU4V.mjs";
@@ -194,14 +177,20 @@ import {
194
177
  sample
195
178
  } from "./chunk-2KNLZB7V.mjs";
196
179
  import {
197
- flattenDeep
198
- } from "./chunk-ML727RRJ.mjs";
180
+ sampleSize
181
+ } from "./chunk-EHSKB6DF.mjs";
199
182
  import {
200
- forEachRight
201
- } from "./chunk-IEA53J7P.mjs";
183
+ randomInt
184
+ } from "./chunk-GIWAOOFY.mjs";
202
185
  import {
203
- groupBy
204
- } from "./chunk-E6E4RZLN.mjs";
186
+ random
187
+ } from "./chunk-SYWMYQYJ.mjs";
188
+ import {
189
+ shuffle
190
+ } from "./chunk-G7UQ5PUR.mjs";
191
+ import {
192
+ tail
193
+ } from "./chunk-OF6NM4G7.mjs";
205
194
  import {
206
195
  head
207
196
  } from "./chunk-HM2JT2RX.mjs";
@@ -215,14 +204,14 @@ import {
215
204
  intersectionBy
216
205
  } from "./chunk-O6UXZR3U.mjs";
217
206
  import {
218
- differenceBy
219
- } from "./chunk-LVWX5B43.mjs";
207
+ intersectionWith
208
+ } from "./chunk-XI7KRD2C.mjs";
220
209
  import {
221
- differenceWith
222
- } from "./chunk-6NVQAHXP.mjs";
210
+ keyBy
211
+ } from "./chunk-AJKZMN2V.mjs";
223
212
  import {
224
- drop
225
- } from "./chunk-S3CORED5.mjs";
213
+ last
214
+ } from "./chunk-KPBQ7OUY.mjs";
226
215
  import {
227
216
  dropRight
228
217
  } from "./chunk-JEKUA56R.mjs";
@@ -235,13 +224,18 @@ import {
235
224
  import {
236
225
  fill
237
226
  } from "./chunk-C4WE4GLC.mjs";
227
+ import {
228
+ flattenDeep
229
+ } from "./chunk-ML727RRJ.mjs";
238
230
  import {
239
231
  flatten
240
232
  } from "./chunk-33MSBDC6.mjs";
241
- import "./chunk-FZEZH22H.mjs";
242
233
  import {
243
- AbortError
244
- } from "./chunk-DXB7EZUQ.mjs";
234
+ forEachRight
235
+ } from "./chunk-IEA53J7P.mjs";
236
+ import {
237
+ groupBy
238
+ } from "./chunk-E6E4RZLN.mjs";
245
239
  import {
246
240
  chunk
247
241
  } from "./chunk-E6C5EZQA.mjs";
@@ -254,6 +248,15 @@ import {
254
248
  import {
255
249
  difference
256
250
  } from "./chunk-JPUKH67K.mjs";
251
+ import {
252
+ differenceBy
253
+ } from "./chunk-LVWX5B43.mjs";
254
+ import {
255
+ differenceWith
256
+ } from "./chunk-6NVQAHXP.mjs";
257
+ import {
258
+ drop
259
+ } from "./chunk-S3CORED5.mjs";
257
260
  import "./chunk-2HIMLZE3.mjs";
258
261
  export {
259
262
  AbortError,
@@ -316,6 +319,7 @@ export {
316
319
  shuffle,
317
320
  snakeCase,
318
321
  sum,
322
+ sumBy,
319
323
  tail,
320
324
  take,
321
325
  takeRight,
@@ -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,4 +1,4 @@
1
- import "../chunk-TLVQSNOE.mjs";
1
+ import "../chunk-FUS75PJ7.mjs";
2
2
  import {
3
3
  meanBy
4
4
  } from "../chunk-IZAD2S7R.mjs";
@@ -11,6 +11,9 @@ import {
11
11
  import {
12
12
  round
13
13
  } from "../chunk-5PMKOZ2F.mjs";
14
+ import {
15
+ sumBy
16
+ } from "../chunk-5L4VWRFX.mjs";
14
17
  import {
15
18
  sum
16
19
  } from "../chunk-2SLTL4KL.mjs";
@@ -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
@@ -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-2HIMLZE3.mjs";
6
+ export {
7
+ sumBy
8
+ };
9
+ //# sourceMappingURL=sumBy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,7 @@
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";
@@ -14,9 +17,6 @@ import {
14
17
  import {
15
18
  pickBy
16
19
  } from "../chunk-6CLH5YZ2.mjs";
17
- import {
18
- clone
19
- } from "../chunk-U4JGKZ56.mjs";
20
20
  import "../chunk-2HIMLZE3.mjs";
21
21
  export {
22
22
  clone,
@@ -1,4 +1,7 @@
1
1
  import "../chunk-ASJF5D6C.mjs";
2
+ import {
3
+ isEqual
4
+ } from "../chunk-JYSV56US.mjs";
2
5
  import {
3
6
  isNil
4
7
  } from "../chunk-WMM7TZLG.mjs";
@@ -11,9 +14,6 @@ import {
11
14
  import {
12
15
  isUndefined
13
16
  } from "../chunk-VH2PV426.mjs";
14
- import {
15
- isEqual
16
- } from "../chunk-JYSV56US.mjs";
17
17
  import "../chunk-R6QA7PLZ.mjs";
18
18
  import "../chunk-DVK2N4KC.mjs";
19
19
  import "../chunk-2HIMLZE3.mjs";
@@ -1,4 +1,7 @@
1
1
  import "../chunk-QKYYOLJ6.mjs";
2
+ import {
3
+ capitalize
4
+ } from "../chunk-U56ZOM7L.mjs";
2
5
  import {
3
6
  kebabCase
4
7
  } from "../chunk-EYYZQFOP.mjs";
@@ -12,9 +15,6 @@ import {
12
15
  camelCase
13
16
  } from "../chunk-XGCYC4YA.mjs";
14
17
  import "../chunk-WVQ7YVRK.mjs";
15
- import {
16
- capitalize
17
- } from "../chunk-U56ZOM7L.mjs";
18
18
  import "../chunk-2HIMLZE3.mjs";
19
19
  export {
20
20
  camelCase,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.10.0-dev.205+e3cd91f5",
4
+ "version": "1.10.0-dev.207+c1c3b3f7",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-TLVQSNOE.mjs.map