es-toolkit 1.17.0 → 1.18.0-dev.573
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/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/dist/_chunk/{index-CoqN5B.js → index-BGZDR9.js} +4 -1
- package/dist/_chunk/{isTypedArray-BBEkFl.js → isTypedArray-Dsrnb1.js} +1 -11
- package/dist/_chunk/{isFunction-aCEz9d.js → isWeakSet-BerD1A.js} +12 -2
- package/dist/_chunk/rest-CXt9w3.js +182 -0
- package/dist/_chunk/{toMerged-BGwYW5.js → toMerged-DN1PPP.js} +1 -1
- package/dist/_chunk/{initial-Ci2bn_.js → zipWith-CYaH1Y.js} +46 -70
- package/dist/array/countBy.d.mts +10 -0
- package/dist/array/countBy.d.ts +10 -0
- package/dist/array/fill.d.mts +55 -2
- package/dist/array/fill.d.ts +55 -2
- package/dist/array/flatMapDeep.d.mts +18 -0
- package/dist/array/flatMapDeep.d.ts +18 -0
- package/dist/array/flatMapDeep.mjs +7 -0
- package/dist/array/flattenDeep.d.mts +1 -1
- package/dist/array/flattenDeep.d.ts +1 -1
- package/dist/array/head.d.mts +14 -3
- package/dist/array/head.d.ts +14 -3
- package/dist/array/index.d.mts +9 -8
- package/dist/array/index.d.ts +9 -8
- package/dist/array/index.js +87 -58
- package/dist/array/index.mjs +9 -8
- package/dist/array/last.d.mts +23 -1
- package/dist/array/last.d.ts +23 -1
- package/dist/array/maxBy.d.mts +13 -1
- package/dist/array/maxBy.d.ts +13 -1
- package/dist/array/minBy.d.mts +13 -1
- package/dist/array/minBy.d.ts +13 -1
- package/dist/array/toFilled.d.mts +59 -2
- package/dist/array/toFilled.d.ts +59 -2
- package/dist/array/zip.d.mts +65 -7
- package/dist/array/zip.d.ts +65 -7
- package/dist/array/zipObject.d.mts +2 -4
- package/dist/array/zipObject.d.ts +2 -4
- package/dist/array/zipWith.d.mts +39 -6
- package/dist/array/zipWith.d.ts +39 -6
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/compareValues.mjs +30 -5
- package/dist/compat/_internal/normalizeForCase.mjs +9 -0
- package/dist/compat/array/castArray.d.mts +29 -0
- package/dist/compat/array/castArray.d.ts +29 -0
- package/dist/compat/array/castArray.mjs +8 -0
- package/dist/compat/array/difference.d.mts +19 -0
- package/dist/compat/array/difference.d.ts +19 -0
- package/dist/compat/array/fill.d.mts +55 -2
- package/dist/compat/array/fill.d.ts +55 -2
- package/dist/compat/array/findLastIndex.d.mts +66 -0
- package/dist/compat/array/findLastIndex.d.ts +66 -0
- package/dist/compat/array/findLastIndex.mjs +33 -0
- package/dist/compat/array/join.d.mts +16 -0
- package/dist/compat/array/join.d.ts +16 -0
- package/dist/compat/array/join.mjs +5 -0
- package/dist/compat/array/orderBy.d.mts +6 -6
- package/dist/compat/array/orderBy.d.ts +6 -6
- package/dist/compat/array/orderBy.mjs +26 -18
- package/dist/compat/array/some.d.mts +86 -0
- package/dist/compat/array/some.d.ts +86 -0
- package/dist/compat/array/some.mjs +36 -0
- package/dist/compat/array/sortBy.d.mts +34 -0
- package/dist/compat/array/sortBy.d.ts +34 -0
- package/dist/compat/array/sortBy.mjs +7 -0
- package/dist/compat/function/ary.d.mts +11 -1
- package/dist/compat/function/ary.d.ts +11 -1
- package/dist/compat/function/attempt.d.mts +33 -0
- package/dist/compat/function/attempt.d.ts +33 -0
- package/dist/compat/function/attempt.mjs +10 -0
- package/dist/compat/function/bindKey.d.mts +45 -0
- package/dist/compat/function/bindKey.d.ts +45 -0
- package/dist/compat/function/bindKey.mjs +27 -0
- package/dist/compat/function/rearg.d.mts +18 -0
- package/dist/compat/function/rearg.d.ts +18 -0
- package/dist/compat/function/rearg.mjs +14 -0
- package/dist/compat/function/spread.d.mts +47 -0
- package/dist/compat/function/spread.d.ts +47 -0
- package/dist/compat/function/spread.mjs +16 -0
- package/dist/compat/index.d.mts +31 -10
- package/dist/compat/index.d.ts +31 -10
- package/dist/compat/index.js +401 -143
- package/dist/compat/index.mjs +32 -11
- package/dist/compat/math/max.d.mts +16 -5
- package/dist/compat/math/max.d.ts +16 -5
- package/dist/compat/math/min.d.mts +16 -4
- package/dist/compat/math/min.d.ts +16 -4
- package/dist/compat/math/parseInt.d.mts +20 -0
- package/dist/compat/math/parseInt.d.ts +20 -0
- package/dist/compat/math/parseInt.mjs +8 -0
- package/dist/compat/object/fromPairs.d.mts +29 -0
- package/dist/compat/object/fromPairs.d.ts +29 -0
- package/dist/compat/object/fromPairs.mjs +14 -0
- package/dist/compat/predicate/conforms.d.mts +22 -0
- package/dist/compat/predicate/conforms.d.ts +22 -0
- package/dist/compat/predicate/conforms.mjs +11 -0
- package/dist/compat/predicate/conformsTo.d.mts +29 -0
- package/dist/compat/predicate/conformsTo.d.ts +29 -0
- package/dist/compat/predicate/conformsTo.mjs +18 -0
- package/dist/compat/predicate/isObject.d.mts +26 -0
- package/dist/compat/predicate/isObject.d.ts +26 -0
- package/dist/compat/predicate/isObject.mjs +5 -0
- package/dist/compat/predicate/isRegExp.d.mts +7 -0
- package/dist/compat/predicate/isRegExp.d.ts +7 -0
- package/dist/compat/predicate/isTypedArray.d.mts +10 -0
- package/dist/compat/predicate/isTypedArray.d.ts +10 -0
- package/dist/compat/predicate/isWeakMap.d.mts +23 -0
- package/dist/compat/predicate/isWeakMap.d.ts +23 -0
- package/dist/compat/predicate/isWeakMap.mjs +7 -0
- package/dist/compat/predicate/isWeakSet.d.mts +23 -0
- package/dist/compat/predicate/isWeakSet.d.ts +23 -0
- package/dist/compat/predicate/isWeakSet.mjs +7 -0
- package/dist/compat/string/camelCase.d.mts +18 -0
- package/dist/compat/string/camelCase.d.ts +18 -0
- package/dist/compat/string/camelCase.mjs +8 -0
- package/dist/compat/string/endsWith.d.mts +1 -1
- package/dist/compat/string/endsWith.d.ts +1 -1
- package/dist/compat/string/endsWith.mjs +2 -2
- package/dist/compat/string/repeat.d.mts +17 -0
- package/dist/compat/string/repeat.d.ts +17 -0
- package/dist/compat/string/repeat.mjs +5 -0
- package/dist/compat/string/startsWith.d.mts +1 -1
- package/dist/compat/string/startsWith.d.ts +1 -1
- package/dist/compat/string/startsWith.mjs +2 -2
- package/dist/function/after.d.mts +1 -1
- package/dist/function/after.d.ts +1 -1
- package/dist/function/after.mjs +2 -2
- package/dist/function/before.d.mts +1 -1
- package/dist/function/before.d.ts +1 -1
- package/dist/function/before.mjs +2 -2
- package/dist/function/debounce.d.mts +3 -3
- package/dist/function/debounce.d.ts +3 -3
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +22 -180
- package/dist/function/index.mjs +1 -0
- package/dist/function/memoize.d.mts +37 -1
- package/dist/function/memoize.d.ts +37 -1
- package/dist/function/negate.d.mts +7 -1
- package/dist/function/negate.d.ts +7 -1
- package/dist/function/spread.d.mts +19 -0
- package/dist/function/spread.d.ts +19 -0
- package/dist/function/spread.mjs +7 -0
- package/dist/function/unary.d.mts +7 -0
- package/dist/function/unary.d.ts +7 -0
- package/dist/index.d.mts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +89 -80
- package/dist/index.mjs +16 -8
- package/dist/math/clamp.d.mts +14 -3
- package/dist/math/clamp.d.ts +14 -3
- package/dist/math/random.d.mts +13 -2
- package/dist/math/random.d.ts +13 -2
- package/dist/math/randomInt.d.mts +11 -3
- package/dist/math/randomInt.d.ts +11 -3
- package/dist/math/range.d.mts +25 -0
- package/dist/math/range.d.ts +25 -0
- package/dist/object/index.js +1 -1
- package/dist/object/invert.d.mts +2 -4
- package/dist/object/invert.d.ts +2 -4
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.d.ts +2 -0
- package/dist/predicate/index.js +11 -9
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isPrimitive.d.mts +14 -0
- package/dist/predicate/isPrimitive.d.ts +14 -0
- package/dist/predicate/isRegExp.d.mts +8 -1
- package/dist/predicate/isRegExp.d.ts +8 -1
- package/dist/predicate/isSymbol.d.mts +15 -0
- package/dist/predicate/isSymbol.d.ts +15 -0
- package/dist/predicate/isTypedArray.d.mts +10 -0
- package/dist/predicate/isTypedArray.d.ts +10 -0
- package/dist/predicate/isTypedArray.mjs +1 -11
- package/dist/predicate/isWeakMap.d.mts +23 -0
- package/dist/predicate/isWeakMap.d.ts +23 -0
- package/dist/predicate/isWeakMap.mjs +5 -0
- package/dist/predicate/isWeakSet.d.mts +23 -0
- package/dist/predicate/isWeakSet.d.ts +23 -0
- package/dist/predicate/isWeakSet.mjs +5 -0
- package/dist/promise/delay.mjs +4 -1
- package/dist/promise/index.js +1 -1
- package/dist/promise/timeout.d.mts +7 -0
- package/dist/promise/timeout.d.ts +7 -0
- package/dist/string/capitalize.d.mts +1 -1
- package/dist/string/capitalize.d.ts +1 -1
- package/dist/string/capitalize.mjs +2 -2
- package/dist/string/deburr.mjs +5 -5
- package/dist/string/escape.d.mts +16 -0
- package/dist/string/escape.d.ts +16 -0
- package/dist/string/escape.mjs +12 -0
- package/dist/string/escapeRegExp.d.mts +14 -0
- package/dist/string/escapeRegExp.d.ts +14 -0
- package/dist/string/escapeRegExp.mjs +5 -0
- package/dist/string/index.d.mts +4 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.js +53 -19
- package/dist/string/index.mjs +4 -0
- package/dist/string/kebabCase.d.mts +1 -1
- package/dist/string/kebabCase.d.ts +1 -1
- package/dist/string/kebabCase.mjs +2 -2
- package/dist/string/lowerCase.d.mts +1 -1
- package/dist/string/lowerCase.d.ts +1 -1
- package/dist/string/lowerCase.mjs +2 -2
- package/dist/string/lowerFirst.d.mts +1 -1
- package/dist/string/lowerFirst.d.ts +1 -1
- package/dist/string/lowerFirst.mjs +2 -2
- package/dist/string/pad.d.mts +19 -0
- package/dist/string/pad.d.ts +19 -0
- package/dist/string/pad.mjs +5 -0
- package/dist/string/pascalCase.d.mts +1 -1
- package/dist/string/pascalCase.d.ts +1 -1
- package/dist/string/pascalCase.mjs +2 -2
- package/dist/string/snakeCase.d.mts +1 -1
- package/dist/string/snakeCase.d.ts +1 -1
- package/dist/string/snakeCase.mjs +2 -2
- package/dist/string/unescape.d.mts +16 -0
- package/dist/string/unescape.d.ts +16 -0
- package/dist/string/unescape.mjs +12 -0
- package/dist/string/upperFirst.d.mts +1 -1
- package/dist/string/upperFirst.d.ts +1 -1
- package/dist/string/upperFirst.mjs +2 -2
- package/package.json +7 -2
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
if (
|
|
3
|
-
return
|
|
1
|
+
function getPriority(a) {
|
|
2
|
+
if (typeof a === 'symbol') {
|
|
3
|
+
return 1;
|
|
4
|
+
}
|
|
5
|
+
if (a === null) {
|
|
6
|
+
return 2;
|
|
7
|
+
}
|
|
8
|
+
if (a === undefined) {
|
|
9
|
+
return 3;
|
|
4
10
|
}
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
11
|
+
if (a !== a) {
|
|
12
|
+
return 4;
|
|
13
|
+
}
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const compareValues = (a, b, order) => {
|
|
17
|
+
if (a !== b) {
|
|
18
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
19
|
+
return order === 'desc' ? b.localeCompare(a) : a.localeCompare(b);
|
|
20
|
+
}
|
|
21
|
+
const aPriority = getPriority(a);
|
|
22
|
+
const bPriority = getPriority(b);
|
|
23
|
+
if (aPriority === bPriority && aPriority === 0) {
|
|
24
|
+
if (a < b) {
|
|
25
|
+
return order === 'desc' ? 1 : -1;
|
|
26
|
+
}
|
|
27
|
+
if (a > b) {
|
|
28
|
+
return order === 'desc' ? -1 : 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return order === 'desc' ? bPriority - aPriority : aPriority - bPriority;
|
|
7
32
|
}
|
|
8
33
|
return 0;
|
|
9
34
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Casts value as an array if it's not one.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of elements in the array.
|
|
5
|
+
* @param {T | readonly T[]} value The value to be cast to an array.
|
|
6
|
+
* @returns {T[]} An array containing the input value if it wasn't an array, or the original array if it was.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const arr1 = castArray(1);
|
|
10
|
+
* // Returns: [1]
|
|
11
|
+
*
|
|
12
|
+
* const arr2 = castArray([1]);
|
|
13
|
+
* // Returns: [1]
|
|
14
|
+
*
|
|
15
|
+
* const arr3 = castArray({'a': 1});
|
|
16
|
+
* // Returns: [{'a': 1}]
|
|
17
|
+
*
|
|
18
|
+
* const arr4 = castArray(null);
|
|
19
|
+
* // Returns: [null]
|
|
20
|
+
*
|
|
21
|
+
* const arr5 = castArray(undefined);
|
|
22
|
+
* // Returns: [undefined]
|
|
23
|
+
*
|
|
24
|
+
* const arr6 = castArray();
|
|
25
|
+
* // Returns: []
|
|
26
|
+
*/
|
|
27
|
+
declare function castArray<T>(value?: T | readonly T[]): T[];
|
|
28
|
+
|
|
29
|
+
export { castArray };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Casts value as an array if it's not one.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of elements in the array.
|
|
5
|
+
* @param {T | readonly T[]} value The value to be cast to an array.
|
|
6
|
+
* @returns {T[]} An array containing the input value if it wasn't an array, or the original array if it was.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const arr1 = castArray(1);
|
|
10
|
+
* // Returns: [1]
|
|
11
|
+
*
|
|
12
|
+
* const arr2 = castArray([1]);
|
|
13
|
+
* // Returns: [1]
|
|
14
|
+
*
|
|
15
|
+
* const arr3 = castArray({'a': 1});
|
|
16
|
+
* // Returns: [{'a': 1}]
|
|
17
|
+
*
|
|
18
|
+
* const arr4 = castArray(null);
|
|
19
|
+
* // Returns: [null]
|
|
20
|
+
*
|
|
21
|
+
* const arr5 = castArray(undefined);
|
|
22
|
+
* // Returns: [undefined]
|
|
23
|
+
*
|
|
24
|
+
* const arr6 = castArray();
|
|
25
|
+
* // Returns: []
|
|
26
|
+
*/
|
|
27
|
+
declare function castArray<T>(value?: T | readonly T[]): T[];
|
|
28
|
+
|
|
29
|
+
export { castArray };
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between an array and multiple arrays.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The primary array from which to derive the difference. This is the main array
|
|
6
|
+
* from which elements will be compared and filtered.
|
|
7
|
+
* @param {...T[]} values - Multiple arrays containing elements to be excluded from the primary array.
|
|
8
|
+
* These arrays will be flattened into a single array, and each element in this array will be checked against the primary array.
|
|
9
|
+
* If a match is found, that element will be excluded from the result.
|
|
10
|
+
* @returns {T[]} A new array containing the elements that are present in the primary array but not
|
|
11
|
+
* in the flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array1 = [1, 2, 3, 4, 5];
|
|
15
|
+
* const array2 = [2, 4];
|
|
16
|
+
* const array3 = [5, 6];
|
|
17
|
+
* const result = difference(array1, array2, array3);
|
|
18
|
+
* // result will be [1, 3] since 2, 4, and 5 are in the other arrays and are excluded from the result.
|
|
19
|
+
*/
|
|
1
20
|
declare function difference<T>(arr: readonly T[], ...values: Array<readonly T[]>): T[];
|
|
2
21
|
|
|
3
22
|
export { difference };
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between an array and multiple arrays.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The primary array from which to derive the difference. This is the main array
|
|
6
|
+
* from which elements will be compared and filtered.
|
|
7
|
+
* @param {...T[]} values - Multiple arrays containing elements to be excluded from the primary array.
|
|
8
|
+
* These arrays will be flattened into a single array, and each element in this array will be checked against the primary array.
|
|
9
|
+
* If a match is found, that element will be excluded from the result.
|
|
10
|
+
* @returns {T[]} A new array containing the elements that are present in the primary array but not
|
|
11
|
+
* in the flattened array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array1 = [1, 2, 3, 4, 5];
|
|
15
|
+
* const array2 = [2, 4];
|
|
16
|
+
* const array3 = [5, 6];
|
|
17
|
+
* const result = difference(array1, array2, array3);
|
|
18
|
+
* // result will be [1, 3] since 2, 4, and 5 are in the other arrays and are excluded from the result.
|
|
19
|
+
*/
|
|
1
20
|
declare function difference<T>(arr: readonly T[], ...values: Array<readonly T[]>): T[];
|
|
2
21
|
|
|
3
22
|
export { difference };
|
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills the whole array with a specified value.
|
|
3
|
+
*
|
|
4
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
5
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
6
|
+
* entire array.
|
|
7
|
+
*
|
|
8
|
+
* @template T, U, S, V
|
|
9
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
10
|
+
* @param {U} value - The value to fill the array with.
|
|
11
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3];
|
|
15
|
+
* const result = fill(array, 'a');
|
|
16
|
+
* // => ['a', 'a', 'a']
|
|
17
|
+
*
|
|
18
|
+
* const result = fill(Array(3), 2);
|
|
19
|
+
* // => [2, 2, 2]
|
|
20
|
+
*
|
|
21
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
22
|
+
* // => [4, '*', '*', 10]
|
|
23
|
+
*
|
|
24
|
+
* const result = fill(array, '*', -2, -1);
|
|
25
|
+
* // => [1, '*', 3]
|
|
26
|
+
*/
|
|
27
|
+
declare function fill<T>(array: unknown[], value?: T): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Fills elements of an array with a specified value from the start position to the end.
|
|
30
|
+
*
|
|
31
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
32
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
33
|
+
* entire array.
|
|
34
|
+
*
|
|
35
|
+
* @template T, U, S, V
|
|
36
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
37
|
+
* @param {U} value - The value to fill the array with.
|
|
38
|
+
* @param {S} [start=0] - The start position. Defaults to 0.
|
|
39
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const array = [1, 2, 3];
|
|
43
|
+
* const result = fill(array, 'a');
|
|
44
|
+
* // => ['a', 'a', 'a']
|
|
45
|
+
*
|
|
46
|
+
* const result = fill(Array(3), 2);
|
|
47
|
+
* // => [2, 2, 2]
|
|
48
|
+
*
|
|
49
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
50
|
+
* // => [4, '*', '*', 10]
|
|
51
|
+
*
|
|
52
|
+
* const result = fill(array, '*', -2, -1);
|
|
53
|
+
* // => [1, '*', 3]
|
|
54
|
+
*/
|
|
55
|
+
declare function fill<T, U, S>(array: Array<T | U>, value: U, start: S): Array<T | U>;
|
|
1
56
|
/**
|
|
2
57
|
* Fills elements of an array with a specified value from the start position up to, but not including, the end position.
|
|
3
58
|
*
|
|
@@ -26,8 +81,6 @@
|
|
|
26
81
|
* const result = fill(array, '*', -2, -1);
|
|
27
82
|
* // => [1, '*', 3]
|
|
28
83
|
*/
|
|
29
|
-
declare function fill<T>(array: unknown[], value?: T): T[];
|
|
30
|
-
declare function fill<T, U, S>(array: Array<T | U>, value: U, start: S): Array<T | U>;
|
|
31
84
|
declare function fill<T, U, S, V>(array: Array<T | U>, value: U, start: S, end: V): Array<T | U>;
|
|
32
85
|
|
|
33
86
|
export { fill };
|
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills the whole array with a specified value.
|
|
3
|
+
*
|
|
4
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
5
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
6
|
+
* entire array.
|
|
7
|
+
*
|
|
8
|
+
* @template T, U, S, V
|
|
9
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
10
|
+
* @param {U} value - The value to fill the array with.
|
|
11
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3];
|
|
15
|
+
* const result = fill(array, 'a');
|
|
16
|
+
* // => ['a', 'a', 'a']
|
|
17
|
+
*
|
|
18
|
+
* const result = fill(Array(3), 2);
|
|
19
|
+
* // => [2, 2, 2]
|
|
20
|
+
*
|
|
21
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
22
|
+
* // => [4, '*', '*', 10]
|
|
23
|
+
*
|
|
24
|
+
* const result = fill(array, '*', -2, -1);
|
|
25
|
+
* // => [1, '*', 3]
|
|
26
|
+
*/
|
|
27
|
+
declare function fill<T>(array: unknown[], value?: T): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Fills elements of an array with a specified value from the start position to the end.
|
|
30
|
+
*
|
|
31
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
32
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
33
|
+
* entire array.
|
|
34
|
+
*
|
|
35
|
+
* @template T, U, S, V
|
|
36
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
37
|
+
* @param {U} value - The value to fill the array with.
|
|
38
|
+
* @param {S} [start=0] - The start position. Defaults to 0.
|
|
39
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const array = [1, 2, 3];
|
|
43
|
+
* const result = fill(array, 'a');
|
|
44
|
+
* // => ['a', 'a', 'a']
|
|
45
|
+
*
|
|
46
|
+
* const result = fill(Array(3), 2);
|
|
47
|
+
* // => [2, 2, 2]
|
|
48
|
+
*
|
|
49
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
50
|
+
* // => [4, '*', '*', 10]
|
|
51
|
+
*
|
|
52
|
+
* const result = fill(array, '*', -2, -1);
|
|
53
|
+
* // => [1, '*', 3]
|
|
54
|
+
*/
|
|
55
|
+
declare function fill<T, U, S>(array: Array<T | U>, value: U, start: S): Array<T | U>;
|
|
1
56
|
/**
|
|
2
57
|
* Fills elements of an array with a specified value from the start position up to, but not including, the end position.
|
|
3
58
|
*
|
|
@@ -26,8 +81,6 @@
|
|
|
26
81
|
* const result = fill(array, '*', -2, -1);
|
|
27
82
|
* // => [1, '*', 3]
|
|
28
83
|
*/
|
|
29
|
-
declare function fill<T>(array: unknown[], value?: T): T[];
|
|
30
|
-
declare function fill<T, U, S>(array: Array<T | U>, value: U, start: S): Array<T | U>;
|
|
31
84
|
declare function fill<T, U, S, V>(array: Array<T | U>, value: U, start: S, end: V): Array<T | U>;
|
|
32
85
|
|
|
33
86
|
export { fill };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates through an array in reverse order and returns the index of the first item that matches the given predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The array to search through.
|
|
6
|
+
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
|
|
7
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
8
|
+
* @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Using a predicate function
|
|
12
|
+
* const items = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = findLastIndex(items, (item) => item > 3)
|
|
14
|
+
* console.log(result); // 4
|
|
15
|
+
*/
|
|
16
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Finds the index of the first item in an array that matches the given partial object.
|
|
19
|
+
*
|
|
20
|
+
* @template T
|
|
21
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
22
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
23
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
24
|
+
* @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using a partial object
|
|
28
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
29
|
+
* const result = findLastIndex(items, { name: 'Bob' });
|
|
30
|
+
* console.log(result); // 1
|
|
31
|
+
*/
|
|
32
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>, fromIndex?: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Finds the index of the first item in an array that matches a property with a specific value.
|
|
35
|
+
*
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
38
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
39
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
40
|
+
* @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Using a property-value pair
|
|
44
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
45
|
+
* const result = findLastIndex(items, ['name', 'Alice']);
|
|
46
|
+
* console.log(result); // 0
|
|
47
|
+
*/
|
|
48
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown], fromIndex?: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
|
|
51
|
+
*
|
|
52
|
+
* @template T
|
|
53
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
54
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
56
|
+
* @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Using a property name
|
|
60
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
61
|
+
* const result = findLastIndex(items, 'name');
|
|
62
|
+
* console.log(result); // 1
|
|
63
|
+
*/
|
|
64
|
+
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string, fromIndex?: number): number;
|
|
65
|
+
|
|
66
|
+
export { findLastIndex };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates through an array in reverse order and returns the index of the first item that matches the given predicate function.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arr - The array to search through.
|
|
6
|
+
* @param {(item: T, index: number, arr: T[]) => unknown} doesMatch - A function that takes an item, its index, and the array, and returns a truthy value if the item matches the criteria.
|
|
7
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
8
|
+
* @returns {number} - The index of the first item that matches the predicate, or `undefined` if no match is found.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Using a predicate function
|
|
12
|
+
* const items = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = findLastIndex(items, (item) => item > 3)
|
|
14
|
+
* console.log(result); // 4
|
|
15
|
+
*/
|
|
16
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: (item: T, index: number, arr: readonly T[]) => unknown, fromIndex?: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Finds the index of the first item in an array that matches the given partial object.
|
|
19
|
+
*
|
|
20
|
+
* @template T
|
|
21
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
22
|
+
* @param {Partial<T>} doesMatch - A partial object that specifies the properties to match.
|
|
23
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
24
|
+
* @returns {number} - The index of the first item that matches the partial object, or `undefined` if no match is found.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using a partial object
|
|
28
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
29
|
+
* const result = findLastIndex(items, { name: 'Bob' });
|
|
30
|
+
* console.log(result); // 1
|
|
31
|
+
*/
|
|
32
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatch: Partial<T>, fromIndex?: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Finds the index of the first item in an array that matches a property with a specific value.
|
|
35
|
+
*
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
38
|
+
* @param {[keyof T, unknown]} doesMatchProperty - An array where the first element is the property key and the second element is the value to match.
|
|
39
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
40
|
+
* @returns {number} - The index of the first item that has the specified property value, or `undefined` if no match is found.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Using a property-value pair
|
|
44
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
45
|
+
* const result = findLastIndex(items, ['name', 'Alice']);
|
|
46
|
+
* console.log(result); // 0
|
|
47
|
+
*/
|
|
48
|
+
declare function findLastIndex<T>(arr: readonly T[], doesMatchProperty: [keyof T, unknown], fromIndex?: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Finds the index of the first item in an array that has a specific property, where the property name is provided as a string.
|
|
51
|
+
*
|
|
52
|
+
* @template T
|
|
53
|
+
* @param {readonly T[]} arr - The array to search through.
|
|
54
|
+
* @param {string} propertyToCheck - The property name to check.
|
|
55
|
+
* @param {number} [fromIndex=arr.length - 1] - The index to start the search from, defaults to the last index of the array.
|
|
56
|
+
* @returns {number} - The index of the first item that has the specified property, or `undefined` if no match is found.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Using a property name
|
|
60
|
+
* const items = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
|
|
61
|
+
* const result = findLastIndex(items, 'name');
|
|
62
|
+
* console.log(result); // 1
|
|
63
|
+
*/
|
|
64
|
+
declare function findLastIndex<T>(arr: readonly T[], propertyToCheck: string, fromIndex?: number): number;
|
|
65
|
+
|
|
66
|
+
export { findLastIndex };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { property } from '../object/property.mjs';
|
|
2
|
+
import { matches } from '../predicate/matches.mjs';
|
|
3
|
+
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
4
|
+
|
|
5
|
+
function findLastIndex(source, doesMatch, fromIndex = source.length - 1) {
|
|
6
|
+
if (fromIndex < 0) {
|
|
7
|
+
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
fromIndex = Math.min(fromIndex, source.length - 1);
|
|
11
|
+
}
|
|
12
|
+
source = source.slice(0, fromIndex + 1);
|
|
13
|
+
switch (typeof doesMatch) {
|
|
14
|
+
case 'function': {
|
|
15
|
+
return source.findLastIndex(doesMatch);
|
|
16
|
+
}
|
|
17
|
+
case 'object': {
|
|
18
|
+
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
19
|
+
const key = doesMatch[0];
|
|
20
|
+
const value = doesMatch[1];
|
|
21
|
+
return source.findLastIndex(matchesProperty(key, value));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return source.findLastIndex(matches(doesMatch));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
case 'string': {
|
|
28
|
+
return source.findLastIndex(property(doesMatch));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { findLastIndex };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins elements of an array into a string.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of elements in the array.
|
|
5
|
+
* @param {T[]} array - The array to join.
|
|
6
|
+
* @param {string} separator - The separator used to join the elements, default is common separator `,`.
|
|
7
|
+
* @returns {string} - Returns a string containing all elements of the array joined by the specified separator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const arr = ["a", "b", "c"];
|
|
11
|
+
* const result = join(arr, "~");
|
|
12
|
+
* console.log(result); // Output: "a~b~c"
|
|
13
|
+
*/
|
|
14
|
+
declare function join<T>(array: readonly T[], separator?: string): string;
|
|
15
|
+
|
|
16
|
+
export { join };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins elements of an array into a string.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of elements in the array.
|
|
5
|
+
* @param {T[]} array - The array to join.
|
|
6
|
+
* @param {string} separator - The separator used to join the elements, default is common separator `,`.
|
|
7
|
+
* @returns {string} - Returns a string containing all elements of the array joined by the specified separator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const arr = ["a", "b", "c"];
|
|
11
|
+
* const result = join(arr, "~");
|
|
12
|
+
* console.log(result); // Output: "a~b~c"
|
|
13
|
+
*/
|
|
14
|
+
declare function join<T>(array: readonly T[], separator?: string): string;
|
|
15
|
+
|
|
16
|
+
export { join };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null | undefined;
|
|
1
2
|
/**
|
|
2
3
|
* Sorts an array of objects based on multiple properties and their corresponding order directions.
|
|
3
4
|
*
|
|
4
5
|
* This function takes an array of objects, an array of criteria to sort by, and an array of order directions.
|
|
5
|
-
* It returns the sorted array, ordering by each key according to its corresponding direction
|
|
6
|
-
*
|
|
7
|
-
* it moves to the next key to determine the order.
|
|
6
|
+
* It returns the sorted array, ordering by each key according to its corresponding direction ('asc' for ascending or 'desc' for descending).
|
|
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
10
|
* @param { T[] | object | null | undefined} collection - The array of objects to be sorted.
|
|
11
|
-
* @param {
|
|
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
13
|
* @returns {T[]} - The sorted array.
|
|
14
14
|
*
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
* // { user: 'fred', age: 40 },
|
|
30
30
|
* // ]
|
|
31
31
|
*/
|
|
32
|
-
declare function orderBy<T>(collection: T[] | object | null | undefined, criteria?:
|
|
32
|
+
declare function orderBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
|
|
33
33
|
|
|
34
|
-
export { orderBy };
|
|
34
|
+
export { type Criterion, orderBy };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null | undefined;
|
|
1
2
|
/**
|
|
2
3
|
* Sorts an array of objects based on multiple properties and their corresponding order directions.
|
|
3
4
|
*
|
|
4
5
|
* This function takes an array of objects, an array of criteria to sort by, and an array of order directions.
|
|
5
|
-
* It returns the sorted array, ordering by each key according to its corresponding direction
|
|
6
|
-
*
|
|
7
|
-
* it moves to the next key to determine the order.
|
|
6
|
+
* It returns the sorted array, ordering by each key according to its corresponding direction ('asc' for ascending or 'desc' for descending).
|
|
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
10
|
* @param { T[] | object | null | undefined} collection - The array of objects to be sorted.
|
|
11
|
-
* @param {
|
|
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
13
|
* @returns {T[]} - The sorted array.
|
|
14
14
|
*
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
* // { user: 'fred', age: 40 },
|
|
30
30
|
* // ]
|
|
31
31
|
*/
|
|
32
|
-
declare function orderBy<T>(collection: T[] | object | null | undefined, criteria?:
|
|
32
|
+
declare function orderBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
|
|
33
33
|
|
|
34
|
-
export { orderBy };
|
|
34
|
+
export { type Criterion, orderBy };
|
|
@@ -3,64 +3,72 @@ import { isKey } from '../_internal/isKey.mjs';
|
|
|
3
3
|
import { toPath } from '../_internal/toPath.mjs';
|
|
4
4
|
|
|
5
5
|
function orderBy(collection, criteria, orders) {
|
|
6
|
-
if (collection == null) {
|
|
6
|
+
if (collection == null || typeof collection === 'number') {
|
|
7
7
|
return [];
|
|
8
8
|
}
|
|
9
|
-
if (
|
|
9
|
+
if (typeof collection === 'object' && !Array.isArray(collection)) {
|
|
10
10
|
collection = Object.values(collection);
|
|
11
11
|
}
|
|
12
12
|
if (!Array.isArray(criteria)) {
|
|
13
|
-
criteria = criteria == null ? [] : [criteria];
|
|
13
|
+
criteria = criteria == null ? [null] : [criteria];
|
|
14
14
|
}
|
|
15
15
|
if (!Array.isArray(orders)) {
|
|
16
16
|
orders = orders == null ? [] : [orders];
|
|
17
17
|
}
|
|
18
|
+
orders = orders.map(order => String(order));
|
|
18
19
|
const getValueByNestedPath = (object, path) => {
|
|
19
20
|
let target = object;
|
|
20
|
-
for (let i = 0; i < path.length && target != null; i
|
|
21
|
+
for (let i = 0; i < path.length && target != null; ++i) {
|
|
21
22
|
target = target[path[i]];
|
|
22
23
|
}
|
|
23
24
|
return target;
|
|
24
25
|
};
|
|
25
26
|
const getValueByCriterion = (criterion, object) => {
|
|
26
|
-
if (object == null) {
|
|
27
|
+
if (object == null || criterion == null) {
|
|
27
28
|
return object;
|
|
28
29
|
}
|
|
30
|
+
if (typeof criterion === 'object' && 'key' in criterion) {
|
|
31
|
+
if (Object.hasOwn(object, criterion.key)) {
|
|
32
|
+
return object[criterion.key];
|
|
33
|
+
}
|
|
34
|
+
return getValueByNestedPath(object, criterion.path);
|
|
35
|
+
}
|
|
29
36
|
if (typeof criterion === 'function') {
|
|
30
37
|
return criterion(object);
|
|
31
38
|
}
|
|
32
39
|
if (Array.isArray(criterion)) {
|
|
33
40
|
return getValueByNestedPath(object, criterion);
|
|
34
41
|
}
|
|
35
|
-
if (typeof
|
|
42
|
+
if (typeof object === 'object') {
|
|
36
43
|
return object[criterion];
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
return object[criterion.key];
|
|
40
|
-
}
|
|
41
|
-
return getValueByNestedPath(object, criterion.path);
|
|
45
|
+
return object;
|
|
42
46
|
};
|
|
43
47
|
const preparedCriteria = criteria.map(criterion => {
|
|
44
48
|
if (Array.isArray(criterion) && criterion.length === 1) {
|
|
45
49
|
criterion = criterion[0];
|
|
46
50
|
}
|
|
47
|
-
if (typeof criterion === 'function' || Array.isArray(criterion) || isKey(criterion)) {
|
|
51
|
+
if (criterion == null || typeof criterion === 'function' || Array.isArray(criterion) || isKey(criterion)) {
|
|
48
52
|
return criterion;
|
|
49
53
|
}
|
|
50
54
|
return { key: criterion, path: toPath(criterion) };
|
|
51
55
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const preparedCollection = collection.map(item => ({
|
|
57
|
+
original: item,
|
|
58
|
+
criteria: preparedCriteria.map(criterion => getValueByCriterion(criterion, item)),
|
|
59
|
+
}));
|
|
60
|
+
return preparedCollection
|
|
61
|
+
.slice()
|
|
62
|
+
.sort((a, b) => {
|
|
63
|
+
for (let i = 0; i < preparedCriteria.length; i++) {
|
|
64
|
+
const comparedResult = compareValues(a.criteria[i], b.criteria[i], orders[i]);
|
|
58
65
|
if (comparedResult !== 0) {
|
|
59
66
|
return comparedResult;
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
return 0;
|
|
63
|
-
})
|
|
70
|
+
})
|
|
71
|
+
.map(item => item.original);
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
export { orderBy };
|