es-toolkit 1.26.1-dev.850 → 1.26.1-dev.852

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.
@@ -47,8 +47,6 @@ export { medianBy } from '../math/medianBy.mjs';
47
47
  export { randomInt } from '../math/randomInt.mjs';
48
48
  export { range } from '../math/range.mjs';
49
49
  export { rangeRight } from '../math/rangeRight.mjs';
50
- export { sum } from '../math/sum.mjs';
51
- export { sumBy } from '../math/sumBy.mjs';
52
50
  export { clone } from '../object/clone.mjs';
53
51
  export { flattenObject } from '../object/flattenObject.mjs';
54
52
  export { invert } from '../object/invert.mjs';
@@ -142,6 +140,8 @@ export { min } from './math/min.mjs';
142
140
  export { parseInt } from './math/parseInt.mjs';
143
141
  export { random } from './math/random.mjs';
144
142
  export { round } from './math/round.mjs';
143
+ export { sum } from './math/sum.mjs';
144
+ export { sumBy } from './math/sumBy.mjs';
145
145
  export { cloneDeep } from './object/cloneDeep.mjs';
146
146
  export { defaults } from './object/defaults.mjs';
147
147
  export { fromPairs } from './object/fromPairs.mjs';
@@ -47,8 +47,6 @@ export { medianBy } from '../math/medianBy.js';
47
47
  export { randomInt } from '../math/randomInt.js';
48
48
  export { range } from '../math/range.js';
49
49
  export { rangeRight } from '../math/rangeRight.js';
50
- export { sum } from '../math/sum.js';
51
- export { sumBy } from '../math/sumBy.js';
52
50
  export { clone } from '../object/clone.js';
53
51
  export { flattenObject } from '../object/flattenObject.js';
54
52
  export { invert } from '../object/invert.js';
@@ -142,6 +140,8 @@ export { min } from './math/min.js';
142
140
  export { parseInt } from './math/parseInt.js';
143
141
  export { random } from './math/random.js';
144
142
  export { round } from './math/round.js';
143
+ export { sum } from './math/sum.js';
144
+ export { sumBy } from './math/sumBy.js';
145
145
  export { cloneDeep } from './object/cloneDeep.js';
146
146
  export { defaults } from './object/defaults.js';
147
147
  export { fromPairs } from './object/fromPairs.js';
@@ -6,7 +6,7 @@ const zipWith = require('../_chunk/zipWith-Dx_q4f.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
7
  const unary = require('../_chunk/unary-CcTNuC.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
- const sumBy = require('../_chunk/sumBy-wtGD37.js');
9
+ const rangeRight = require('../_chunk/rangeRight-w3WrXN.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
11
  const toMerged = require('../_chunk/toMerged-wNz52b.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
@@ -1567,7 +1567,7 @@ function clamp(value, bound1, bound2) {
1567
1567
  if (Number.isNaN(bound2)) {
1568
1568
  bound2 = 0;
1569
1569
  }
1570
- return sumBy.clamp(value, bound1, bound2);
1570
+ return rangeRight.clamp(value, bound1, bound2);
1571
1571
  }
1572
1572
 
1573
1573
  function floor(number, precision = 0) {
@@ -1596,7 +1596,7 @@ function inRange(value, minimum, maximum) {
1596
1596
  if (minimum === maximum) {
1597
1597
  return false;
1598
1598
  }
1599
- return sumBy.inRange(value, minimum, maximum);
1599
+ return rangeRight.inRange(value, minimum, maximum);
1600
1600
  }
1601
1601
 
1602
1602
  function max(items = []) {
@@ -1701,6 +1701,27 @@ function round(number, precision = 0) {
1701
1701
  return decimalAdjust('round', number, precision);
1702
1702
  }
1703
1703
 
1704
+ function sumBy(array, iteratee$1) {
1705
+ if (!array || !array.length) {
1706
+ return 0;
1707
+ }
1708
+ if (iteratee$1 != null) {
1709
+ iteratee$1 = iteratee(iteratee$1);
1710
+ }
1711
+ let result = iteratee$1 ? iteratee$1(array[0]) : array[0];
1712
+ for (let i = 1; i < array.length; i++) {
1713
+ const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
1714
+ if (current !== undefined) {
1715
+ result += current;
1716
+ }
1717
+ }
1718
+ return result;
1719
+ }
1720
+
1721
+ function sum(array) {
1722
+ return sumBy(array);
1723
+ }
1724
+
1704
1725
  function defaults(object, ...sources) {
1705
1726
  object = Object(object);
1706
1727
  const objectProto = Object.prototype;
@@ -2498,14 +2519,12 @@ exports.partial = unary.partial;
2498
2519
  exports.partialRight = unary.partialRight;
2499
2520
  exports.unary = unary.unary;
2500
2521
  exports.noop = noop.noop;
2501
- exports.mean = sumBy.mean;
2502
- exports.meanBy = sumBy.meanBy;
2503
- exports.median = sumBy.median;
2504
- exports.medianBy = sumBy.medianBy;
2505
- exports.range = sumBy.range;
2506
- exports.rangeRight = sumBy.rangeRight;
2507
- exports.sum = sumBy.sum;
2508
- exports.sumBy = sumBy.sumBy;
2522
+ exports.mean = rangeRight.mean;
2523
+ exports.meanBy = rangeRight.meanBy;
2524
+ exports.median = rangeRight.median;
2525
+ exports.medianBy = rangeRight.medianBy;
2526
+ exports.range = rangeRight.range;
2527
+ exports.rangeRight = rangeRight.rangeRight;
2509
2528
  exports.randomInt = randomInt.randomInt;
2510
2529
  exports.clone = toMerged.clone;
2511
2530
  exports.flattenObject = toMerged.flattenObject;
@@ -2654,6 +2673,8 @@ exports.sortBy = sortBy;
2654
2673
  exports.spread = spread;
2655
2674
  exports.startCase = startCase;
2656
2675
  exports.startsWith = startsWith;
2676
+ exports.sum = sum;
2677
+ exports.sumBy = sumBy;
2657
2678
  exports.tail = tail;
2658
2679
  exports.take = take;
2659
2680
  exports.takeRight = takeRight;
@@ -47,8 +47,6 @@ export { medianBy } from '../math/medianBy.mjs';
47
47
  export { randomInt } from '../math/randomInt.mjs';
48
48
  export { range } from '../math/range.mjs';
49
49
  export { rangeRight } from '../math/rangeRight.mjs';
50
- export { sum } from '../math/sum.mjs';
51
- export { sumBy } from '../math/sumBy.mjs';
52
50
  export { clone } from '../object/clone.mjs';
53
51
  export { isPrimitive } from '../predicate/isPrimitive.mjs';
54
52
  export { flattenObject } from '../object/flattenObject.mjs';
@@ -144,6 +142,8 @@ export { min } from './math/min.mjs';
144
142
  export { parseInt } from './math/parseInt.mjs';
145
143
  export { random } from './math/random.mjs';
146
144
  export { round } from './math/round.mjs';
145
+ export { sum } from './math/sum.mjs';
146
+ export { sumBy } from './math/sumBy.mjs';
147
147
  export { cloneDeep } from './object/cloneDeep.mjs';
148
148
  export { defaults } from './object/defaults.mjs';
149
149
  export { fromPairs } from './object/fromPairs.mjs';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Computes the sum of the `number` values in `array`.
3
+ *
4
+ * @param {ArrayLike<number> | null | undefined} array - The array to iterate over.
5
+ * @returns {number} Returns the sum.
6
+ *
7
+ * @example
8
+ * sum([1, 2, 3]); // => 6
9
+ * sum(null); // => 0
10
+ * sum(undefined); // => 0
11
+ */
12
+ declare function sum(array: ArrayLike<number> | null | undefined): number;
13
+ /**
14
+ * Computes the sum of the `bigint` values in `array`.
15
+ *
16
+ * @param {ArrayLike<bigint>} array - The array to iterate over.
17
+ * @returns {bigint} Returns the sum.
18
+ *
19
+ * @example
20
+ * sum([1n, 2n, 3n]); // => 6n
21
+ */
22
+ declare function sum(array: ArrayLike<bigint>): bigint;
23
+ /**
24
+ * Computes the sum of the values in `array`.
25
+ *
26
+ * It does not coerce values to `number`.
27
+ *
28
+ * @param {ArrayLike<unknown> | null | undefined} array - The array to iterate over.
29
+ * @returns {unknown} Returns the sum.
30
+ *
31
+ * @example
32
+ * sum(["1", "2"]); // => "12"
33
+ * sum([1, undefined, 2]); // => 3
34
+ */
35
+ declare function sum(array: ArrayLike<unknown> | null | undefined): unknown;
36
+
37
+ export { sum };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Computes the sum of the `number` values in `array`.
3
+ *
4
+ * @param {ArrayLike<number> | null | undefined} array - The array to iterate over.
5
+ * @returns {number} Returns the sum.
6
+ *
7
+ * @example
8
+ * sum([1, 2, 3]); // => 6
9
+ * sum(null); // => 0
10
+ * sum(undefined); // => 0
11
+ */
12
+ declare function sum(array: ArrayLike<number> | null | undefined): number;
13
+ /**
14
+ * Computes the sum of the `bigint` values in `array`.
15
+ *
16
+ * @param {ArrayLike<bigint>} array - The array to iterate over.
17
+ * @returns {bigint} Returns the sum.
18
+ *
19
+ * @example
20
+ * sum([1n, 2n, 3n]); // => 6n
21
+ */
22
+ declare function sum(array: ArrayLike<bigint>): bigint;
23
+ /**
24
+ * Computes the sum of the values in `array`.
25
+ *
26
+ * It does not coerce values to `number`.
27
+ *
28
+ * @param {ArrayLike<unknown> | null | undefined} array - The array to iterate over.
29
+ * @returns {unknown} Returns the sum.
30
+ *
31
+ * @example
32
+ * sum(["1", "2"]); // => "12"
33
+ * sum([1, undefined, 2]); // => 3
34
+ */
35
+ declare function sum(array: ArrayLike<unknown> | null | undefined): unknown;
36
+
37
+ export { sum };
@@ -0,0 +1,7 @@
1
+ import { sumBy } from './sumBy.mjs';
2
+
3
+ function sum(array) {
4
+ return sumBy(array);
5
+ }
6
+
7
+ export { sum };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Computes the sum of the `number` values in `array`.
3
+ *
4
+ * @param {ArrayLike<number> | null | undefined} array - The array to iterate over.
5
+ * @returns {number} Returns the sum.
6
+ *
7
+ * @example
8
+ * sumBy([1, 2, 3]); // => 6
9
+ * sumBy(null); // => 0
10
+ * sumBy(undefined); // => 0
11
+ */
12
+ declare function sumBy(array: ArrayLike<number> | null | undefined): number;
13
+ /**
14
+ * Computes the sum of the `bigint` values in `array`.
15
+ *
16
+ * @param {ArrayLike<bigint>} array - The array to iterate over.
17
+ * @returns {bigint} Returns the sum.
18
+ *
19
+ * @example
20
+ * sumBy([1n, 2n, 3n]); // => 6n
21
+ */
22
+ declare function sumBy(array: ArrayLike<bigint>): bigint;
23
+ /**
24
+ * Computes the sum of the values in `array`.
25
+ *
26
+ * It does not coerce values to `number`.
27
+ *
28
+ * @param {ArrayLike<unknown> | null | undefined} array - The array to iterate over.
29
+ * @returns {unknown} Returns the sum.
30
+ *
31
+ * @example
32
+ * sumBy(["1", "2"]); // => "12"
33
+ * sumBy([1, undefined, 2]); // => 3
34
+ */
35
+ declare function sumBy(array: ArrayLike<unknown> | null | undefined): unknown;
36
+ /**
37
+ * Compmutes the sum of the `number` values that are returned by the `iteratee` function.
38
+ *
39
+ * @template T - The type of the array elements.
40
+ * @param {ArrayLike<T>} array - The array to iterate over.
41
+ * @param {(value: T) => number} iteratee - The function invoked per iteration.
42
+ * @returns {number} Returns the sum.
43
+ *
44
+ * @example
45
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], object => object.a); // => 6
46
+ */
47
+ declare function sumBy<T>(array: ArrayLike<T>, iteratee: (value: T) => number): number;
48
+ /**
49
+ * Compmutes the sum of the `bigint` values that are returned by the `iteratee` function.
50
+ *
51
+ * NOTE: If the `array` is empty, the function returns `0`.
52
+ *
53
+ * @template T - The type of the array elements.
54
+ * @param {ArrayLike<T>} array - The array to iterate over.
55
+ * @param {(value: T) => bigint} iteratee - The function invoked per iteration.
56
+ * @returns {bigint | number} Returns the sum.
57
+ *
58
+ * @example
59
+ * sumBy([{ a: 1n }, { a: 2n }, { a: 3n }], object => object.a); // => 6n
60
+ * sumBy([], (item: { a: bigint }) => item.a); // => 0
61
+ */
62
+ declare function sumBy<T>(array: ArrayLike<T>, iteratee: (value: T) => bigint): bigint | number;
63
+
64
+ export { sumBy };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Computes the sum of the `number` values in `array`.
3
+ *
4
+ * @param {ArrayLike<number> | null | undefined} array - The array to iterate over.
5
+ * @returns {number} Returns the sum.
6
+ *
7
+ * @example
8
+ * sumBy([1, 2, 3]); // => 6
9
+ * sumBy(null); // => 0
10
+ * sumBy(undefined); // => 0
11
+ */
12
+ declare function sumBy(array: ArrayLike<number> | null | undefined): number;
13
+ /**
14
+ * Computes the sum of the `bigint` values in `array`.
15
+ *
16
+ * @param {ArrayLike<bigint>} array - The array to iterate over.
17
+ * @returns {bigint} Returns the sum.
18
+ *
19
+ * @example
20
+ * sumBy([1n, 2n, 3n]); // => 6n
21
+ */
22
+ declare function sumBy(array: ArrayLike<bigint>): bigint;
23
+ /**
24
+ * Computes the sum of the values in `array`.
25
+ *
26
+ * It does not coerce values to `number`.
27
+ *
28
+ * @param {ArrayLike<unknown> | null | undefined} array - The array to iterate over.
29
+ * @returns {unknown} Returns the sum.
30
+ *
31
+ * @example
32
+ * sumBy(["1", "2"]); // => "12"
33
+ * sumBy([1, undefined, 2]); // => 3
34
+ */
35
+ declare function sumBy(array: ArrayLike<unknown> | null | undefined): unknown;
36
+ /**
37
+ * Compmutes the sum of the `number` values that are returned by the `iteratee` function.
38
+ *
39
+ * @template T - The type of the array elements.
40
+ * @param {ArrayLike<T>} array - The array to iterate over.
41
+ * @param {(value: T) => number} iteratee - The function invoked per iteration.
42
+ * @returns {number} Returns the sum.
43
+ *
44
+ * @example
45
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], object => object.a); // => 6
46
+ */
47
+ declare function sumBy<T>(array: ArrayLike<T>, iteratee: (value: T) => number): number;
48
+ /**
49
+ * Compmutes the sum of the `bigint` values that are returned by the `iteratee` function.
50
+ *
51
+ * NOTE: If the `array` is empty, the function returns `0`.
52
+ *
53
+ * @template T - The type of the array elements.
54
+ * @param {ArrayLike<T>} array - The array to iterate over.
55
+ * @param {(value: T) => bigint} iteratee - The function invoked per iteration.
56
+ * @returns {bigint | number} Returns the sum.
57
+ *
58
+ * @example
59
+ * sumBy([{ a: 1n }, { a: 2n }, { a: 3n }], object => object.a); // => 6n
60
+ * sumBy([], (item: { a: bigint }) => item.a); // => 0
61
+ */
62
+ declare function sumBy<T>(array: ArrayLike<T>, iteratee: (value: T) => bigint): bigint | number;
63
+
64
+ export { sumBy };
@@ -0,0 +1,20 @@
1
+ import { iteratee } from '../util/iteratee.mjs';
2
+
3
+ function sumBy(array, iteratee$1) {
4
+ if (!array || !array.length) {
5
+ return 0;
6
+ }
7
+ if (iteratee$1 != null) {
8
+ iteratee$1 = iteratee(iteratee$1);
9
+ }
10
+ let result = iteratee$1 ? iteratee$1(array[0]) : array[0];
11
+ for (let i = 1; i < array.length; i++) {
12
+ const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
13
+ if (current !== undefined) {
14
+ result += current;
15
+ }
16
+ }
17
+ return result;
18
+ }
19
+
20
+ export { sumBy };
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ const promise_index = require('./_chunk/index-BGZDR9.js');
8
8
  const unary = require('./_chunk/unary-CcTNuC.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const noop = require('./_chunk/noop-2IwLUk.js');
11
- const sumBy = require('./_chunk/sumBy-wtGD37.js');
11
+ const rangeRight = require('./_chunk/rangeRight-w3WrXN.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
14
  const toMerged = require('./_chunk/toMerged-wNz52b.js');
@@ -102,19 +102,19 @@ exports.curryRight = function_index.curryRight;
102
102
  exports.spread = function_index.spread;
103
103
  exports.throttle = function_index.throttle;
104
104
  exports.noop = noop.noop;
105
- exports.clamp = sumBy.clamp;
106
- exports.inRange = sumBy.inRange;
107
- exports.mean = sumBy.mean;
108
- exports.meanBy = sumBy.meanBy;
109
- exports.median = sumBy.median;
110
- exports.medianBy = sumBy.medianBy;
111
- exports.range = sumBy.range;
112
- exports.rangeRight = sumBy.rangeRight;
113
- exports.sum = sumBy.sum;
114
- exports.sumBy = sumBy.sumBy;
105
+ exports.clamp = rangeRight.clamp;
106
+ exports.inRange = rangeRight.inRange;
107
+ exports.mean = rangeRight.mean;
108
+ exports.meanBy = rangeRight.meanBy;
109
+ exports.median = rangeRight.median;
110
+ exports.medianBy = rangeRight.medianBy;
111
+ exports.range = rangeRight.range;
112
+ exports.rangeRight = rangeRight.rangeRight;
113
+ exports.sum = rangeRight.sum;
115
114
  exports.random = randomInt.random;
116
115
  exports.randomInt = randomInt.randomInt;
117
116
  exports.round = math_index.round;
117
+ exports.sumBy = math_index.sumBy;
118
118
  exports.clone = toMerged.clone;
119
119
  exports.cloneDeep = toMerged.cloneDeep;
120
120
  exports.flattenObject = toMerged.flattenObject;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const sumBy = require('../_chunk/sumBy-wtGD37.js');
5
+ const rangeRight = require('../_chunk/rangeRight-w3WrXN.js');
6
6
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
7
7
 
8
8
  function round(value, precision = 0) {
@@ -13,16 +13,24 @@ function round(value, precision = 0) {
13
13
  return Math.round(value * multiplier) / multiplier;
14
14
  }
15
15
 
16
- exports.clamp = sumBy.clamp;
17
- exports.inRange = sumBy.inRange;
18
- exports.mean = sumBy.mean;
19
- exports.meanBy = sumBy.meanBy;
20
- exports.median = sumBy.median;
21
- exports.medianBy = sumBy.medianBy;
22
- exports.range = sumBy.range;
23
- exports.rangeRight = sumBy.rangeRight;
24
- exports.sum = sumBy.sum;
25
- exports.sumBy = sumBy.sumBy;
16
+ function sumBy(items, getValue) {
17
+ let result = 0;
18
+ for (let i = 0; i < items.length; i++) {
19
+ result += getValue(items[i]);
20
+ }
21
+ return result;
22
+ }
23
+
24
+ exports.clamp = rangeRight.clamp;
25
+ exports.inRange = rangeRight.inRange;
26
+ exports.mean = rangeRight.mean;
27
+ exports.meanBy = rangeRight.meanBy;
28
+ exports.median = rangeRight.median;
29
+ exports.medianBy = rangeRight.medianBy;
30
+ exports.range = rangeRight.range;
31
+ exports.rangeRight = rangeRight.rangeRight;
32
+ exports.sum = rangeRight.sum;
26
33
  exports.random = randomInt.random;
27
34
  exports.randomInt = randomInt.randomInt;
28
35
  exports.round = round;
36
+ exports.sumBy = sumBy;
@@ -1,11 +1,8 @@
1
- function rangeRight(start, end, step) {
1
+ function rangeRight(start, end, step = 1) {
2
2
  if (end == null) {
3
3
  end = start;
4
4
  start = 0;
5
5
  }
6
- if (step == null) {
7
- step = 1;
8
- }
9
6
  if (!Number.isInteger(step) || step === 0) {
10
7
  throw new Error(`The step value must be a non-zero integer.`);
11
8
  }
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.26.1-dev.850+7dbf58a9",
4
+ "version": "1.26.1-dev.852+9d13669f",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {