es-toolkit 1.25.2-dev.807 → 1.25.2-dev.808
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/orderBy.d.mts +3 -2
- package/dist/compat/array/orderBy.d.ts +3 -2
- package/dist/compat/array/orderBy.mjs +7 -3
- package/dist/compat/array/sortBy.d.mts +3 -3
- package/dist/compat/array/sortBy.d.ts +3 -3
- package/dist/compat/array/sortBy.mjs +11 -2
- package/dist/compat/index.js +16 -5
- package/package.json +1 -1
|
@@ -7,9 +7,10 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
|
|
|
7
7
|
* If values for a key are equal, it moves to the next key to determine the order.
|
|
8
8
|
*
|
|
9
9
|
* @template T - The type of elements in the array.
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
|
|
11
11
|
* @param {Criterion<T> | Array<Criterion<T>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
|
|
12
12
|
* @param {unknown | unknown[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).
|
|
13
|
+
* @param {unknown} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
|
13
14
|
* @returns {T[]} - The sorted array.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
@@ -29,6 +30,6 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
|
|
|
29
30
|
* // { user: 'fred', age: 40 },
|
|
30
31
|
* // ]
|
|
31
32
|
*/
|
|
32
|
-
declare function orderBy<T>(collection:
|
|
33
|
+
declare function orderBy<T = any>(collection: ArrayLike<T> | object | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[], guard?: unknown): T[];
|
|
33
34
|
|
|
34
35
|
export { type Criterion, orderBy };
|
|
@@ -7,9 +7,10 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
|
|
|
7
7
|
* If values for a key are equal, it moves to the next key to determine the order.
|
|
8
8
|
*
|
|
9
9
|
* @template T - The type of elements in the array.
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
|
|
11
11
|
* @param {Criterion<T> | Array<Criterion<T>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
|
|
12
12
|
* @param {unknown | unknown[]} orders - An array of order directions ('asc' for ascending or 'desc' for descending).
|
|
13
|
+
* @param {unknown} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
|
13
14
|
* @returns {T[]} - The sorted array.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
@@ -29,6 +30,6 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
|
|
|
29
30
|
* // { user: 'fred', age: 40 },
|
|
30
31
|
* // ]
|
|
31
32
|
*/
|
|
32
|
-
declare function orderBy<T>(collection:
|
|
33
|
+
declare function orderBy<T = any>(collection: ArrayLike<T> | object | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[], guard?: unknown): T[];
|
|
33
34
|
|
|
34
35
|
export { type Criterion, orderBy };
|
|
@@ -2,16 +2,20 @@ import { compareValues } from '../_internal/compareValues.mjs';
|
|
|
2
2
|
import { isKey } from '../_internal/isKey.mjs';
|
|
3
3
|
import { toPath } from '../util/toPath.mjs';
|
|
4
4
|
|
|
5
|
-
function orderBy(collection, criteria, orders) {
|
|
6
|
-
if (collection == null
|
|
5
|
+
function orderBy(collection, criteria, orders, guard) {
|
|
6
|
+
if (collection == null) {
|
|
7
7
|
return [];
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
orders = guard ? undefined : orders;
|
|
10
|
+
if (!Array.isArray(collection)) {
|
|
10
11
|
collection = Object.values(collection);
|
|
11
12
|
}
|
|
12
13
|
if (!Array.isArray(criteria)) {
|
|
13
14
|
criteria = criteria == null ? [null] : [criteria];
|
|
14
15
|
}
|
|
16
|
+
if (criteria.length === 0) {
|
|
17
|
+
criteria = [null];
|
|
18
|
+
}
|
|
15
19
|
if (!Array.isArray(orders)) {
|
|
16
20
|
orders = orders == null ? [] : [orders];
|
|
17
21
|
}
|
|
@@ -8,8 +8,8 @@ import { Criterion } from './orderBy.mjs';
|
|
|
8
8
|
* If values for a key are equal, it moves to the next key to determine the order.
|
|
9
9
|
*
|
|
10
10
|
* @template T - The type of elements in the array.
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {Criterion<T> |
|
|
11
|
+
* @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
|
|
12
|
+
* @param {Array<Array<Criterion<T> | Criterion<T>>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
|
|
13
13
|
* @returns {T[]} - The ascending sorted array.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -29,6 +29,6 @@ import { Criterion } from './orderBy.mjs';
|
|
|
29
29
|
* // { user: 'fred', age: 48 },
|
|
30
30
|
* // ]
|
|
31
31
|
*/
|
|
32
|
-
declare function sortBy<T>(collection:
|
|
32
|
+
declare function sortBy<T = any>(collection: ArrayLike<T> | object | null | undefined, ...criteria: Array<Criterion<T> | Array<Criterion<T>>>): T[];
|
|
33
33
|
|
|
34
34
|
export { sortBy };
|
|
@@ -8,8 +8,8 @@ import { Criterion } from './orderBy.js';
|
|
|
8
8
|
* If values for a key are equal, it moves to the next key to determine the order.
|
|
9
9
|
*
|
|
10
10
|
* @template T - The type of elements in the array.
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {Criterion<T> |
|
|
11
|
+
* @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
|
|
12
|
+
* @param {Array<Array<Criterion<T> | Criterion<T>>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
|
|
13
13
|
* @returns {T[]} - The ascending sorted array.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -29,6 +29,6 @@ import { Criterion } from './orderBy.js';
|
|
|
29
29
|
* // { user: 'fred', age: 48 },
|
|
30
30
|
* // ]
|
|
31
31
|
*/
|
|
32
|
-
declare function sortBy<T>(collection:
|
|
32
|
+
declare function sortBy<T = any>(collection: ArrayLike<T> | object | null | undefined, ...criteria: Array<Criterion<T> | Array<Criterion<T>>>): T[];
|
|
33
33
|
|
|
34
34
|
export { sortBy };
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { orderBy } from './orderBy.mjs';
|
|
2
|
+
import { flatten } from '../../array/flatten.mjs';
|
|
3
|
+
import { isIterateeCall } from '../_internal/isIterateeCall.mjs';
|
|
2
4
|
|
|
3
|
-
function sortBy(collection, criteria) {
|
|
4
|
-
|
|
5
|
+
function sortBy(collection, ...criteria) {
|
|
6
|
+
const length = criteria.length;
|
|
7
|
+
if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) {
|
|
8
|
+
criteria = [];
|
|
9
|
+
}
|
|
10
|
+
else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) {
|
|
11
|
+
criteria = [criteria[0]];
|
|
12
|
+
}
|
|
13
|
+
return orderBy(collection, flatten(criteria), ['asc']);
|
|
5
14
|
}
|
|
6
15
|
|
|
7
16
|
export { sortBy };
|
package/dist/compat/index.js
CHANGED
|
@@ -886,16 +886,20 @@ function isKey(value, object) {
|
|
|
886
886
|
(object != null));
|
|
887
887
|
}
|
|
888
888
|
|
|
889
|
-
function orderBy(collection, criteria, orders) {
|
|
890
|
-
if (collection == null
|
|
889
|
+
function orderBy(collection, criteria, orders, guard) {
|
|
890
|
+
if (collection == null) {
|
|
891
891
|
return [];
|
|
892
892
|
}
|
|
893
|
-
|
|
893
|
+
orders = guard ? undefined : orders;
|
|
894
|
+
if (!Array.isArray(collection)) {
|
|
894
895
|
collection = Object.values(collection);
|
|
895
896
|
}
|
|
896
897
|
if (!Array.isArray(criteria)) {
|
|
897
898
|
criteria = criteria == null ? [null] : [criteria];
|
|
898
899
|
}
|
|
900
|
+
if (criteria.length === 0) {
|
|
901
|
+
criteria = [null];
|
|
902
|
+
}
|
|
899
903
|
if (!Array.isArray(orders)) {
|
|
900
904
|
orders = orders == null ? [] : [orders];
|
|
901
905
|
}
|
|
@@ -1051,8 +1055,15 @@ function some(source, predicate, guard) {
|
|
|
1051
1055
|
}
|
|
1052
1056
|
}
|
|
1053
1057
|
|
|
1054
|
-
function sortBy(collection, criteria) {
|
|
1055
|
-
|
|
1058
|
+
function sortBy(collection, ...criteria) {
|
|
1059
|
+
const length = criteria.length;
|
|
1060
|
+
if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) {
|
|
1061
|
+
criteria = [];
|
|
1062
|
+
}
|
|
1063
|
+
else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) {
|
|
1064
|
+
criteria = [criteria[0]];
|
|
1065
|
+
}
|
|
1066
|
+
return orderBy(collection, zipWith.flatten(criteria), ['asc']);
|
|
1056
1067
|
}
|
|
1057
1068
|
|
|
1058
1069
|
function tail(arr) {
|
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.808+402f604b",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|