es-toolkit 1.52.0-dev.2132 → 1.52.0-dev.2133
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/fp/array/head.d.mts +3 -16
- package/dist/fp/array/head.d.ts +3 -16
- package/dist/fp/array/head.js +18 -0
- package/dist/fp/array/head.mjs +18 -0
- package/dist/fp/array/last.d.mts +3 -16
- package/dist/fp/array/last.d.ts +3 -16
- package/dist/fp/array/last.js +18 -0
- package/dist/fp/array/last.mjs +18 -0
- package/dist/fp/array/maxBy.d.mts +3 -17
- package/dist/fp/array/maxBy.d.ts +3 -17
- package/dist/fp/array/maxBy.js +19 -0
- package/dist/fp/array/maxBy.mjs +19 -0
- package/dist/fp/array/minBy.d.mts +3 -17
- package/dist/fp/array/minBy.d.ts +3 -17
- package/dist/fp/array/minBy.js +19 -0
- package/dist/fp/array/minBy.mjs +19 -0
- package/package.json +1 -1
package/dist/fp/array/head.d.mts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/head.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the first element of a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
-
* always returns T when the piped array has at least one element.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @returns A function that maps a non-empty readonly array to its first element.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { head, pipe } from 'es-toolkit/fp';
|
|
13
|
-
*
|
|
14
|
-
* pipe([1, 2, 3] as const, head());
|
|
15
|
-
* // => 1
|
|
16
|
-
*/
|
|
17
|
-
declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
18
2
|
/**
|
|
19
3
|
* Creates a function that returns the first element of an array, or undefined.
|
|
20
4
|
*
|
|
@@ -27,6 +11,9 @@ declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
|
27
11
|
* @example
|
|
28
12
|
* import { head, pipe } from 'es-toolkit/fp';
|
|
29
13
|
*
|
|
14
|
+
* pipe([1, 2, 3], head());
|
|
15
|
+
* // => 1
|
|
16
|
+
*
|
|
30
17
|
* pipe([] as number[], head());
|
|
31
18
|
* // => undefined
|
|
32
19
|
*/
|
package/dist/fp/array/head.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/head.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the first element of a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
-
* always returns T when the piped array has at least one element.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @returns A function that maps a non-empty readonly array to its first element.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { head, pipe } from 'es-toolkit/fp';
|
|
13
|
-
*
|
|
14
|
-
* pipe([1, 2, 3] as const, head());
|
|
15
|
-
* // => 1
|
|
16
|
-
*/
|
|
17
|
-
declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
18
2
|
/**
|
|
19
3
|
* Creates a function that returns the first element of an array, or undefined.
|
|
20
4
|
*
|
|
@@ -27,6 +11,9 @@ declare function head<T>(): (array: readonly [T, ...T[]]) => T;
|
|
|
27
11
|
* @example
|
|
28
12
|
* import { head, pipe } from 'es-toolkit/fp';
|
|
29
13
|
*
|
|
14
|
+
* pipe([1, 2, 3], head());
|
|
15
|
+
* // => 1
|
|
16
|
+
*
|
|
30
17
|
* pipe([] as number[], head());
|
|
31
18
|
* // => undefined
|
|
32
19
|
*/
|
package/dist/fp/array/head.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
const require_head = require("../../array/head.js");
|
|
2
2
|
//#region src/fp/array/head.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the first element of an array, or undefined.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined, matching the main {@link head} behavior. Use
|
|
7
|
+
* the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @returns A function that maps a readonly array to its first element, or undefined.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3], head());
|
|
16
|
+
* // => 1
|
|
17
|
+
*
|
|
18
|
+
* pipe([] as number[], head());
|
|
19
|
+
* // => undefined
|
|
20
|
+
*/
|
|
3
21
|
function head() {
|
|
4
22
|
return function(array) {
|
|
5
23
|
return require_head.head(array);
|
package/dist/fp/array/head.mjs
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { head as head$1 } from "../../array/head.mjs";
|
|
2
2
|
//#region src/fp/array/head.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the first element of an array, or undefined.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined, matching the main {@link head} behavior. Use
|
|
7
|
+
* the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @returns A function that maps a readonly array to its first element, or undefined.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { head, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3], head());
|
|
16
|
+
* // => 1
|
|
17
|
+
*
|
|
18
|
+
* pipe([] as number[], head());
|
|
19
|
+
* // => undefined
|
|
20
|
+
*/
|
|
3
21
|
function head() {
|
|
4
22
|
return function(array) {
|
|
5
23
|
return head$1(array);
|
package/dist/fp/array/last.d.mts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/last.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the last element of a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
-
* always returns T when the piped array has at least one element.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @returns A function that maps a non-empty readonly array to its last element.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { last, pipe } from 'es-toolkit/fp';
|
|
13
|
-
*
|
|
14
|
-
* pipe([1, 2, 3] as const, last());
|
|
15
|
-
* // => 3
|
|
16
|
-
*/
|
|
17
|
-
declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
18
2
|
/**
|
|
19
3
|
* Creates a function that returns the last element of an array, or undefined.
|
|
20
4
|
*
|
|
@@ -27,6 +11,9 @@ declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
|
27
11
|
* @example
|
|
28
12
|
* import { last, pipe } from 'es-toolkit/fp';
|
|
29
13
|
*
|
|
14
|
+
* pipe([1, 2, 3], last());
|
|
15
|
+
* // => 3
|
|
16
|
+
*
|
|
30
17
|
* pipe([] as number[], last());
|
|
31
18
|
* // => undefined
|
|
32
19
|
*/
|
package/dist/fp/array/last.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/last.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the last element of a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* This overload preserves the non-empty tuple guarantee: the returned function
|
|
6
|
-
* always returns T when the piped array has at least one element.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @returns A function that maps a non-empty readonly array to its last element.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { last, pipe } from 'es-toolkit/fp';
|
|
13
|
-
*
|
|
14
|
-
* pipe([1, 2, 3] as const, last());
|
|
15
|
-
* // => 3
|
|
16
|
-
*/
|
|
17
|
-
declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
18
2
|
/**
|
|
19
3
|
* Creates a function that returns the last element of an array, or undefined.
|
|
20
4
|
*
|
|
@@ -27,6 +11,9 @@ declare function last<T>(): (array: readonly [...T[], T]) => T;
|
|
|
27
11
|
* @example
|
|
28
12
|
* import { last, pipe } from 'es-toolkit/fp';
|
|
29
13
|
*
|
|
14
|
+
* pipe([1, 2, 3], last());
|
|
15
|
+
* // => 3
|
|
16
|
+
*
|
|
30
17
|
* pipe([] as number[], last());
|
|
31
18
|
* // => undefined
|
|
32
19
|
*/
|
package/dist/fp/array/last.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
const require_last = require("../../array/last.js");
|
|
2
2
|
//#region src/fp/array/last.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the last element of an array, or undefined.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined, matching the main {@link last} behavior. Use
|
|
7
|
+
* the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @returns A function that maps a readonly array to its last element, or undefined.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3], last());
|
|
16
|
+
* // => 3
|
|
17
|
+
*
|
|
18
|
+
* pipe([] as number[], last());
|
|
19
|
+
* // => undefined
|
|
20
|
+
*/
|
|
3
21
|
function last() {
|
|
4
22
|
return function(array) {
|
|
5
23
|
return require_last.last(array);
|
package/dist/fp/array/last.mjs
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { last as last$1 } from "../../array/last.mjs";
|
|
2
2
|
//#region src/fp/array/last.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the last element of an array, or undefined.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined, matching the main {@link last} behavior. Use
|
|
7
|
+
* the returned function with {@link pipe}.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @returns A function that maps a readonly array to its last element, or undefined.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { last, pipe } from 'es-toolkit/fp';
|
|
14
|
+
*
|
|
15
|
+
* pipe([1, 2, 3], last());
|
|
16
|
+
* // => 3
|
|
17
|
+
*
|
|
18
|
+
* pipe([] as number[], last());
|
|
19
|
+
* // => undefined
|
|
20
|
+
*/
|
|
3
21
|
function last() {
|
|
4
22
|
return function(array) {
|
|
5
23
|
return last$1(array);
|
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/maxBy.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the element with the maximum selected number from a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
-
* the main {@link maxBy} behavior.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
-
* @returns A function that maps a non-empty readonly array to the maximum element.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
14
|
-
*
|
|
15
|
-
* pipe([{ score: 10 }, { score: 20 }] as const, maxBy(item => item.score));
|
|
16
|
-
* // => { score: 20 }
|
|
17
|
-
*/
|
|
18
|
-
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
2
|
/**
|
|
20
3
|
* Creates a function that returns the element with the maximum selected number.
|
|
21
4
|
*
|
|
@@ -29,6 +12,9 @@ declare function maxBy<T>(getValue: (element: T, index: number, array: readonly
|
|
|
29
12
|
* @example
|
|
30
13
|
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
31
14
|
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }], maxBy(item => item.score));
|
|
16
|
+
* // => { score: 20 }
|
|
17
|
+
*
|
|
32
18
|
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
33
19
|
* // => undefined
|
|
34
20
|
*/
|
package/dist/fp/array/maxBy.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/maxBy.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the element with the maximum selected number from a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
-
* the main {@link maxBy} behavior.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
-
* @returns A function that maps a non-empty readonly array to the maximum element.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
14
|
-
*
|
|
15
|
-
* pipe([{ score: 10 }, { score: 20 }] as const, maxBy(item => item.score));
|
|
16
|
-
* // => { score: 20 }
|
|
17
|
-
*/
|
|
18
|
-
declare function maxBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
2
|
/**
|
|
20
3
|
* Creates a function that returns the element with the maximum selected number.
|
|
21
4
|
*
|
|
@@ -29,6 +12,9 @@ declare function maxBy<T>(getValue: (element: T, index: number, array: readonly
|
|
|
29
12
|
* @example
|
|
30
13
|
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
31
14
|
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }], maxBy(item => item.score));
|
|
16
|
+
* // => { score: 20 }
|
|
17
|
+
*
|
|
32
18
|
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
33
19
|
* // => undefined
|
|
34
20
|
*/
|
package/dist/fp/array/maxBy.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
const require_maxBy = require("../../array/maxBy.js");
|
|
2
2
|
//#region src/fp/array/maxBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the element with the maximum selected number.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
7
|
+
* produced NaN is returned, matching the main {@link maxBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
11
|
+
* @returns A function that maps a readonly array to the maximum element, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ score: 10 }, { score: 20 }], maxBy(item => item.score));
|
|
17
|
+
* // => { score: 20 }
|
|
18
|
+
*
|
|
19
|
+
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
20
|
+
* // => undefined
|
|
21
|
+
*/
|
|
3
22
|
function maxBy(getValue) {
|
|
4
23
|
return function(array) {
|
|
5
24
|
return require_maxBy.maxBy(array, getValue);
|
package/dist/fp/array/maxBy.mjs
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { maxBy as maxBy$1 } from "../../array/maxBy.mjs";
|
|
2
2
|
//#region src/fp/array/maxBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the element with the maximum selected number.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
7
|
+
* produced NaN is returned, matching the main {@link maxBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
11
|
+
* @returns A function that maps a readonly array to the maximum element, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { maxBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ score: 10 }, { score: 20 }], maxBy(item => item.score));
|
|
17
|
+
* // => { score: 20 }
|
|
18
|
+
*
|
|
19
|
+
* pipe([] as Array<{ score: number }>, maxBy(item => item.score));
|
|
20
|
+
* // => undefined
|
|
21
|
+
*/
|
|
3
22
|
function maxBy(getValue) {
|
|
4
23
|
return function(array) {
|
|
5
24
|
return maxBy$1(array, getValue);
|
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/minBy.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the element with the minimum selected number from a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
-
* the main {@link minBy} behavior.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
-
* @returns A function that maps a non-empty readonly array to the minimum element.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
14
|
-
*
|
|
15
|
-
* pipe([{ score: 10 }, { score: 20 }] as const, minBy(item => item.score));
|
|
16
|
-
* // => { score: 10 }
|
|
17
|
-
*/
|
|
18
|
-
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
2
|
/**
|
|
20
3
|
* Creates a function that returns the element with the minimum selected number.
|
|
21
4
|
*
|
|
@@ -29,6 +12,9 @@ declare function minBy<T>(getValue: (element: T, index: number, array: readonly
|
|
|
29
12
|
* @example
|
|
30
13
|
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
31
14
|
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }], minBy(item => item.score));
|
|
16
|
+
* // => { score: 10 }
|
|
17
|
+
*
|
|
32
18
|
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
33
19
|
* // => undefined
|
|
34
20
|
*/
|
package/dist/fp/array/minBy.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
//#region src/fp/array/minBy.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a function that returns the element with the minimum selected number from a non-empty array.
|
|
4
|
-
*
|
|
5
|
-
* If the selector returns NaN, the element that produced NaN is returned, matching
|
|
6
|
-
* the main {@link minBy} behavior.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of elements in the array.
|
|
9
|
-
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
10
|
-
* @returns A function that maps a non-empty readonly array to the minimum element.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
14
|
-
*
|
|
15
|
-
* pipe([{ score: 10 }, { score: 20 }] as const, minBy(item => item.score));
|
|
16
|
-
* // => { score: 10 }
|
|
17
|
-
*/
|
|
18
|
-
declare function minBy<T>(getValue: (element: T, index: number, array: readonly T[]) => number): (array: readonly [T, ...T[]]) => T;
|
|
19
2
|
/**
|
|
20
3
|
* Creates a function that returns the element with the minimum selected number.
|
|
21
4
|
*
|
|
@@ -29,6 +12,9 @@ declare function minBy<T>(getValue: (element: T, index: number, array: readonly
|
|
|
29
12
|
* @example
|
|
30
13
|
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
31
14
|
*
|
|
15
|
+
* pipe([{ score: 10 }, { score: 20 }], minBy(item => item.score));
|
|
16
|
+
* // => { score: 10 }
|
|
17
|
+
*
|
|
32
18
|
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
33
19
|
* // => undefined
|
|
34
20
|
*/
|
package/dist/fp/array/minBy.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
const require_minBy = require("../../array/minBy.js");
|
|
2
2
|
//#region src/fp/array/minBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the element with the minimum selected number.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
7
|
+
* produced NaN is returned, matching the main {@link minBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
11
|
+
* @returns A function that maps a readonly array to the minimum element, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ score: 10 }, { score: 20 }], minBy(item => item.score));
|
|
17
|
+
* // => { score: 10 }
|
|
18
|
+
*
|
|
19
|
+
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
20
|
+
* // => undefined
|
|
21
|
+
*/
|
|
3
22
|
function minBy(getValue) {
|
|
4
23
|
return function(array) {
|
|
5
24
|
return require_minBy.minBy(array, getValue);
|
package/dist/fp/array/minBy.mjs
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { minBy as minBy$1 } from "../../array/minBy.mjs";
|
|
2
2
|
//#region src/fp/array/minBy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that returns the element with the minimum selected number.
|
|
5
|
+
*
|
|
6
|
+
* Empty arrays return undefined. If the selector returns NaN, the element that
|
|
7
|
+
* produced NaN is returned, matching the main {@link minBy} behavior.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @param getValue - Selects a numeric value from each element, index, and array.
|
|
11
|
+
* @returns A function that maps a readonly array to the minimum element, or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { minBy, pipe } from 'es-toolkit/fp';
|
|
15
|
+
*
|
|
16
|
+
* pipe([{ score: 10 }, { score: 20 }], minBy(item => item.score));
|
|
17
|
+
* // => { score: 10 }
|
|
18
|
+
*
|
|
19
|
+
* pipe([] as Array<{ score: number }>, minBy(item => item.score));
|
|
20
|
+
* // => undefined
|
|
21
|
+
*/
|
|
3
22
|
function minBy(getValue) {
|
|
4
23
|
return function(array) {
|
|
5
24
|
return minBy$1(array, getValue);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.52.0-dev.
|
|
3
|
+
"version": "1.52.0-dev.2133+1708d315",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|