es-toolkit 1.25.2-dev.808 → 1.25.2-dev.809
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/_chunk/{sumBy-BkErWJ.js → sumBy-RVppiV.js} +21 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +2 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +3 -1
- package/dist/compat/index.mjs +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/index.mjs +2 -0
- package/dist/math/index.d.mts +2 -0
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.js +3 -1
- package/dist/math/index.mjs +2 -0
- package/dist/math/median.d.mts +25 -0
- package/dist/math/median.d.ts +25 -0
- package/dist/math/median.mjs +15 -0
- package/dist/math/medianBy.d.mts +23 -0
- package/dist/math/medianBy.d.ts +23 -0
- package/dist/math/medianBy.mjs +8 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.mjs';
|
|
|
45
45
|
export { unary } from '../function/unary.mjs';
|
|
46
46
|
export { mean } from '../math/mean.mjs';
|
|
47
47
|
export { meanBy } from '../math/meanBy.mjs';
|
|
48
|
+
export { median } from '../math/median.mjs';
|
|
49
|
+
export { medianBy } from '../math/medianBy.mjs';
|
|
48
50
|
export { randomInt } from '../math/randomInt.mjs';
|
|
49
51
|
export { range } from '../math/range.mjs';
|
|
50
52
|
export { rangeRight } from '../math/rangeRight.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.js';
|
|
|
45
45
|
export { unary } from '../function/unary.js';
|
|
46
46
|
export { mean } from '../math/mean.js';
|
|
47
47
|
export { meanBy } from '../math/meanBy.js';
|
|
48
|
+
export { median } from '../math/median.js';
|
|
49
|
+
export { medianBy } from '../math/medianBy.js';
|
|
48
50
|
export { randomInt } from '../math/randomInt.js';
|
|
49
51
|
export { range } from '../math/range.js';
|
|
50
52
|
export { rangeRight } from '../math/rangeRight.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const zipWith = require('../_chunk/zipWith-Dkv3D1.js');
|
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
7
|
const unary = require('../_chunk/unary-CMvKXy.js');
|
|
8
8
|
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
9
|
-
const sumBy = require('../_chunk/sumBy-
|
|
9
|
+
const sumBy = require('../_chunk/sumBy-RVppiV.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');
|
|
@@ -2298,6 +2298,8 @@ exports.unary = unary.unary;
|
|
|
2298
2298
|
exports.noop = noop.noop;
|
|
2299
2299
|
exports.mean = sumBy.mean;
|
|
2300
2300
|
exports.meanBy = sumBy.meanBy;
|
|
2301
|
+
exports.median = sumBy.median;
|
|
2302
|
+
exports.medianBy = sumBy.medianBy;
|
|
2301
2303
|
exports.range = sumBy.range;
|
|
2302
2304
|
exports.rangeRight = sumBy.rangeRight;
|
|
2303
2305
|
exports.sum = sumBy.sum;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.mjs';
|
|
|
45
45
|
export { unary } from '../function/unary.mjs';
|
|
46
46
|
export { mean } from '../math/mean.mjs';
|
|
47
47
|
export { meanBy } from '../math/meanBy.mjs';
|
|
48
|
+
export { median } from '../math/median.mjs';
|
|
49
|
+
export { medianBy } from '../math/medianBy.mjs';
|
|
48
50
|
export { randomInt } from '../math/randomInt.mjs';
|
|
49
51
|
export { range } from '../math/range.mjs';
|
|
50
52
|
export { rangeRight } from '../math/rangeRight.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -78,6 +78,8 @@ export { clamp } from './math/clamp.mjs';
|
|
|
78
78
|
export { inRange } from './math/inRange.mjs';
|
|
79
79
|
export { mean } from './math/mean.mjs';
|
|
80
80
|
export { meanBy } from './math/meanBy.mjs';
|
|
81
|
+
export { median } from './math/median.mjs';
|
|
82
|
+
export { medianBy } from './math/medianBy.mjs';
|
|
81
83
|
export { random } from './math/random.mjs';
|
|
82
84
|
export { randomInt } from './math/randomInt.mjs';
|
|
83
85
|
export { range } from './math/range.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export { clamp } from './math/clamp.js';
|
|
|
78
78
|
export { inRange } from './math/inRange.js';
|
|
79
79
|
export { mean } from './math/mean.js';
|
|
80
80
|
export { meanBy } from './math/meanBy.js';
|
|
81
|
+
export { median } from './math/median.js';
|
|
82
|
+
export { medianBy } from './math/medianBy.js';
|
|
81
83
|
export { random } from './math/random.js';
|
|
82
84
|
export { randomInt } from './math/randomInt.js';
|
|
83
85
|
export { range } from './math/range.js';
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
|
8
8
|
const unary = require('./_chunk/unary-CMvKXy.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-
|
|
11
|
+
const sumBy = require('./_chunk/sumBy-RVppiV.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');
|
|
@@ -104,6 +104,8 @@ exports.clamp = sumBy.clamp;
|
|
|
104
104
|
exports.inRange = sumBy.inRange;
|
|
105
105
|
exports.mean = sumBy.mean;
|
|
106
106
|
exports.meanBy = sumBy.meanBy;
|
|
107
|
+
exports.median = sumBy.median;
|
|
108
|
+
exports.medianBy = sumBy.medianBy;
|
|
107
109
|
exports.range = sumBy.range;
|
|
108
110
|
exports.rangeRight = sumBy.rangeRight;
|
|
109
111
|
exports.sum = sumBy.sum;
|
package/dist/index.mjs
CHANGED
|
@@ -78,6 +78,8 @@ export { clamp } from './math/clamp.mjs';
|
|
|
78
78
|
export { inRange } from './math/inRange.mjs';
|
|
79
79
|
export { mean } from './math/mean.mjs';
|
|
80
80
|
export { meanBy } from './math/meanBy.mjs';
|
|
81
|
+
export { median } from './math/median.mjs';
|
|
82
|
+
export { medianBy } from './math/medianBy.mjs';
|
|
81
83
|
export { random } from './math/random.mjs';
|
|
82
84
|
export { randomInt } from './math/randomInt.mjs';
|
|
83
85
|
export { range } from './math/range.mjs';
|
package/dist/math/index.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ export { clamp } from './clamp.mjs';
|
|
|
2
2
|
export { inRange } from './inRange.mjs';
|
|
3
3
|
export { mean } from './mean.mjs';
|
|
4
4
|
export { meanBy } from './meanBy.mjs';
|
|
5
|
+
export { median } from './median.mjs';
|
|
6
|
+
export { medianBy } from './medianBy.mjs';
|
|
5
7
|
export { random } from './random.mjs';
|
|
6
8
|
export { randomInt } from './randomInt.mjs';
|
|
7
9
|
export { range } from './range.mjs';
|
package/dist/math/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { clamp } from './clamp.js';
|
|
|
2
2
|
export { inRange } from './inRange.js';
|
|
3
3
|
export { mean } from './mean.js';
|
|
4
4
|
export { meanBy } from './meanBy.js';
|
|
5
|
+
export { median } from './median.js';
|
|
6
|
+
export { medianBy } from './medianBy.js';
|
|
5
7
|
export { random } from './random.js';
|
|
6
8
|
export { randomInt } from './randomInt.js';
|
|
7
9
|
export { range } from './range.js';
|
package/dist/math/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const sumBy = require('../_chunk/sumBy-
|
|
5
|
+
const sumBy = require('../_chunk/sumBy-RVppiV.js');
|
|
6
6
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
7
7
|
|
|
8
8
|
function round(value, precision = 0) {
|
|
@@ -17,6 +17,8 @@ exports.clamp = sumBy.clamp;
|
|
|
17
17
|
exports.inRange = sumBy.inRange;
|
|
18
18
|
exports.mean = sumBy.mean;
|
|
19
19
|
exports.meanBy = sumBy.meanBy;
|
|
20
|
+
exports.median = sumBy.median;
|
|
21
|
+
exports.medianBy = sumBy.medianBy;
|
|
20
22
|
exports.range = sumBy.range;
|
|
21
23
|
exports.rangeRight = sumBy.rangeRight;
|
|
22
24
|
exports.sum = sumBy.sum;
|
package/dist/math/index.mjs
CHANGED
|
@@ -2,6 +2,8 @@ export { clamp } from './clamp.mjs';
|
|
|
2
2
|
export { inRange } from './inRange.mjs';
|
|
3
3
|
export { mean } from './mean.mjs';
|
|
4
4
|
export { meanBy } from './meanBy.mjs';
|
|
5
|
+
export { median } from './median.mjs';
|
|
6
|
+
export { medianBy } from './medianBy.mjs';
|
|
5
7
|
export { random } from './random.mjs';
|
|
6
8
|
export { randomInt } from './randomInt.mjs';
|
|
7
9
|
export { range } from './range.mjs';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of numbers.
|
|
3
|
+
*
|
|
4
|
+
* The median is the middle value of a sorted array.
|
|
5
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
6
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
7
|
+
*
|
|
8
|
+
* If the array is empty, this function returns `NaN`.
|
|
9
|
+
*
|
|
10
|
+
* @param {number[]} nums - An array of numbers to calculate the median.
|
|
11
|
+
* @returns {number} The median of all the numbers in the array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const arrayWithOddNumberOfElements = [1, 2, 3, 4, 5];
|
|
15
|
+
* const result = median(arrayWithOddNumberOfElements);
|
|
16
|
+
* // result will be 3
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const arrayWithEvenNumberOfElements = [1, 2, 3, 4];
|
|
20
|
+
* const result = median(arrayWithEvenNumberOfElements);
|
|
21
|
+
* // result will be 2.5
|
|
22
|
+
*/
|
|
23
|
+
declare function median(nums: readonly number[]): number;
|
|
24
|
+
|
|
25
|
+
export { median };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of numbers.
|
|
3
|
+
*
|
|
4
|
+
* The median is the middle value of a sorted array.
|
|
5
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
6
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
7
|
+
*
|
|
8
|
+
* If the array is empty, this function returns `NaN`.
|
|
9
|
+
*
|
|
10
|
+
* @param {number[]} nums - An array of numbers to calculate the median.
|
|
11
|
+
* @returns {number} The median of all the numbers in the array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const arrayWithOddNumberOfElements = [1, 2, 3, 4, 5];
|
|
15
|
+
* const result = median(arrayWithOddNumberOfElements);
|
|
16
|
+
* // result will be 3
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const arrayWithEvenNumberOfElements = [1, 2, 3, 4];
|
|
20
|
+
* const result = median(arrayWithEvenNumberOfElements);
|
|
21
|
+
* // result will be 2.5
|
|
22
|
+
*/
|
|
23
|
+
declare function median(nums: readonly number[]): number;
|
|
24
|
+
|
|
25
|
+
export { median };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function median(nums) {
|
|
2
|
+
if (nums.length === 0) {
|
|
3
|
+
return NaN;
|
|
4
|
+
}
|
|
5
|
+
const sorted = nums.slice().sort((a, b) => a - b);
|
|
6
|
+
const middleIndex = Math.floor(sorted.length / 2);
|
|
7
|
+
if (sorted.length % 2 === 0) {
|
|
8
|
+
return (sorted[middleIndex - 1] + sorted[middleIndex]) / 2;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return sorted[middleIndex];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { median };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of elements when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* The median is the middle value of a sorted array.
|
|
6
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
7
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
8
|
+
*
|
|
9
|
+
* If the array is empty, this function returns `NaN`.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param {T[]} items An array to calculate the median.
|
|
13
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
14
|
+
* @returns {number} The median of all the numbers as determined by the `getValue` function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
|
|
18
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
|
|
19
|
+
* medianBy([], x => x.a); // Returns: NaN
|
|
20
|
+
*/
|
|
21
|
+
declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
|
|
22
|
+
|
|
23
|
+
export { medianBy };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the median of an array of elements when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* The median is the middle value of a sorted array.
|
|
6
|
+
* If the array has an odd number of elements, the median is the middle value.
|
|
7
|
+
* If the array has an even number of elements, it returns the average of the two middle values.
|
|
8
|
+
*
|
|
9
|
+
* If the array is empty, this function returns `NaN`.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of elements in the array.
|
|
12
|
+
* @param {T[]} items An array to calculate the median.
|
|
13
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
14
|
+
* @returns {number} The median of all the numbers as determined by the `getValue` function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
|
|
18
|
+
* medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
|
|
19
|
+
* medianBy([], x => x.a); // Returns: NaN
|
|
20
|
+
*/
|
|
21
|
+
declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
|
|
22
|
+
|
|
23
|
+
export { medianBy };
|
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.25.2-dev.
|
|
4
|
+
"version": "1.25.2-dev.809+e71f7064",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|