es-toolkit 1.27.0-dev.888 → 1.27.0-dev.889
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/array/differenceBy.d.mts +10 -3
- package/dist/array/differenceBy.d.ts +10 -3
- package/dist/array/differenceWith.d.mts +11 -4
- package/dist/array/differenceWith.d.ts +11 -4
- package/dist/array/intersectionBy.d.mts +16 -5
- package/dist/array/intersectionBy.d.ts +16 -5
- package/dist/browser.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @template T, U
|
|
12
12
|
* @param {T[]} firstArr - The primary array from which to derive the difference.
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {(value: T) =>
|
|
13
|
+
* @param {U[]} secondArr - The array containing elements to be excluded from the first array.
|
|
14
|
+
* @param {(value: T | U) => unknown} mapper - The function to map the elements of both arrays. This function
|
|
15
15
|
* is applied to each element in both arrays, and the comparison is made based on the mapped values.
|
|
16
16
|
* @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
|
|
17
17
|
* mapped identity in the second array.
|
|
@@ -22,7 +22,14 @@
|
|
|
22
22
|
* const mapper = item => item.id;
|
|
23
23
|
* const result = differenceBy(array1, array2, mapper);
|
|
24
24
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
28
|
+
* const array2 = [2, 4];
|
|
29
|
+
* const mapper = item => (typeof item === 'object' ? item.id : item);
|
|
30
|
+
* const result = differenceBy(array1, array2, mapper);
|
|
31
|
+
* // result will be [{ id: 1 }, { id: 3 }] since 2 is present in both arrays after mapping, and is excluded from the result.
|
|
25
32
|
*/
|
|
26
|
-
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly
|
|
33
|
+
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly U[], mapper: (value: T | U) => unknown): T[];
|
|
27
34
|
|
|
28
35
|
export { differenceBy };
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @template T, U
|
|
12
12
|
* @param {T[]} firstArr - The primary array from which to derive the difference.
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {(value: T) =>
|
|
13
|
+
* @param {U[]} secondArr - The array containing elements to be excluded from the first array.
|
|
14
|
+
* @param {(value: T | U) => unknown} mapper - The function to map the elements of both arrays. This function
|
|
15
15
|
* is applied to each element in both arrays, and the comparison is made based on the mapped values.
|
|
16
16
|
* @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
|
|
17
17
|
* mapped identity in the second array.
|
|
@@ -22,7 +22,14 @@
|
|
|
22
22
|
* const mapper = item => item.id;
|
|
23
23
|
* const result = differenceBy(array1, array2, mapper);
|
|
24
24
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
28
|
+
* const array2 = [2, 4];
|
|
29
|
+
* const mapper = item => (typeof item === 'object' ? item.id : item);
|
|
30
|
+
* const result = differenceBy(array1, array2, mapper);
|
|
31
|
+
* // result will be [{ id: 1 }, { id: 3 }] since 2 is present in both arrays after mapping, and is excluded from the result.
|
|
25
32
|
*/
|
|
26
|
-
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly
|
|
33
|
+
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly U[], mapper: (value: T | U) => unknown): T[];
|
|
27
34
|
|
|
28
35
|
export { differenceBy };
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* the elements that are present in the first array but not in the second array. The comparison to determine
|
|
6
6
|
* if elements are equal is made using the provided custom function.
|
|
7
7
|
*
|
|
8
|
-
* @template T
|
|
8
|
+
* @template T, U
|
|
9
9
|
* @param {T[]} firstArr - The array from which to get the difference.
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {(x: T, y:
|
|
10
|
+
* @param {U[]} secondArr - The array containing elements to exclude from the first array.
|
|
11
|
+
* @param {(x: T, y: U) => boolean} areItemsEqual - A function to determine if two items are equal.
|
|
12
12
|
* @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
|
|
13
13
|
* according to the custom equality function.
|
|
14
14
|
*
|
|
@@ -18,7 +18,14 @@
|
|
|
18
18
|
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
19
19
|
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
20
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
24
|
+
* const array2 = [2, 4];
|
|
25
|
+
* const areItemsEqual = (a, b) => a.id === b;
|
|
26
|
+
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
27
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the element with id 2 is considered equal to the second array's element and is excluded from the result.
|
|
21
28
|
*/
|
|
22
|
-
declare function differenceWith<T>(firstArr: readonly T[], secondArr: readonly
|
|
29
|
+
declare function differenceWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
|
|
23
30
|
|
|
24
31
|
export { differenceWith };
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* the elements that are present in the first array but not in the second array. The comparison to determine
|
|
6
6
|
* if elements are equal is made using the provided custom function.
|
|
7
7
|
*
|
|
8
|
-
* @template T
|
|
8
|
+
* @template T, U
|
|
9
9
|
* @param {T[]} firstArr - The array from which to get the difference.
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {(x: T, y:
|
|
10
|
+
* @param {U[]} secondArr - The array containing elements to exclude from the first array.
|
|
11
|
+
* @param {(x: T, y: U) => boolean} areItemsEqual - A function to determine if two items are equal.
|
|
12
12
|
* @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
|
|
13
13
|
* according to the custom equality function.
|
|
14
14
|
*
|
|
@@ -18,7 +18,14 @@
|
|
|
18
18
|
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
19
19
|
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
20
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
24
|
+
* const array2 = [2, 4];
|
|
25
|
+
* const areItemsEqual = (a, b) => a.id === b;
|
|
26
|
+
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
27
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the element with id 2 is considered equal to the second array's element and is excluded from the result.
|
|
21
28
|
*/
|
|
22
|
-
declare function differenceWith<T>(firstArr: readonly T[], secondArr: readonly
|
|
29
|
+
declare function differenceWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
|
|
23
30
|
|
|
24
31
|
export { differenceWith };
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* mapped elements in the second array. It effectively filters out any elements from the first array
|
|
7
7
|
* that do not have corresponding mapped values in the second array.
|
|
8
8
|
*
|
|
9
|
-
* @template T - The type of elements in the array.
|
|
10
|
-
* @template U - The type of
|
|
9
|
+
* @template T - The type of elements in the first array.
|
|
10
|
+
* @template U - The type of elements in the second array.
|
|
11
11
|
* @param {T[]} firstArr - The first array to compare.
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {(item: T) =>
|
|
12
|
+
* @param {U[]} secondArr - The second array to compare.
|
|
13
|
+
* @param {(item: T | U) => unknown} mapper - A function to map the elements of both arrays for comparison.
|
|
14
14
|
* @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
@@ -19,7 +19,18 @@
|
|
|
19
19
|
* const mapper = item => item.id;
|
|
20
20
|
* const result = intersectionBy(array1, array2, mapper);
|
|
21
21
|
* // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const array1 = [
|
|
25
|
+
* { id: 1, name: 'jane' },
|
|
26
|
+
* { id: 2, name: 'amy' },
|
|
27
|
+
* { id: 3, name: 'michael' },
|
|
28
|
+
* ];
|
|
29
|
+
* const array2 = [2, 4];
|
|
30
|
+
* const mapper = item => (typeof item === 'object' ? item.id : item);
|
|
31
|
+
* const result = intersectionBy(array1, array2, mapper);
|
|
32
|
+
* // result will be [{ id: 2, name: 'amy' }] since only this element has a matching id that is equal to seconds array's element.
|
|
22
33
|
*/
|
|
23
|
-
declare function intersectionBy<T, U>(firstArr: readonly T[], secondArr: readonly
|
|
34
|
+
declare function intersectionBy<T, U>(firstArr: readonly T[], secondArr: readonly U[], mapper: (item: T | U) => unknown): T[];
|
|
24
35
|
|
|
25
36
|
export { intersectionBy };
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* mapped elements in the second array. It effectively filters out any elements from the first array
|
|
7
7
|
* that do not have corresponding mapped values in the second array.
|
|
8
8
|
*
|
|
9
|
-
* @template T - The type of elements in the array.
|
|
10
|
-
* @template U - The type of
|
|
9
|
+
* @template T - The type of elements in the first array.
|
|
10
|
+
* @template U - The type of elements in the second array.
|
|
11
11
|
* @param {T[]} firstArr - The first array to compare.
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {(item: T) =>
|
|
12
|
+
* @param {U[]} secondArr - The second array to compare.
|
|
13
|
+
* @param {(item: T | U) => unknown} mapper - A function to map the elements of both arrays for comparison.
|
|
14
14
|
* @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
@@ -19,7 +19,18 @@
|
|
|
19
19
|
* const mapper = item => item.id;
|
|
20
20
|
* const result = intersectionBy(array1, array2, mapper);
|
|
21
21
|
* // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const array1 = [
|
|
25
|
+
* { id: 1, name: 'jane' },
|
|
26
|
+
* { id: 2, name: 'amy' },
|
|
27
|
+
* { id: 3, name: 'michael' },
|
|
28
|
+
* ];
|
|
29
|
+
* const array2 = [2, 4];
|
|
30
|
+
* const mapper = item => (typeof item === 'object' ? item.id : item);
|
|
31
|
+
* const result = intersectionBy(array1, array2, mapper);
|
|
32
|
+
* // result will be [{ id: 2, name: 'amy' }] since only this element has a matching id that is equal to seconds array's element.
|
|
22
33
|
*/
|
|
23
|
-
declare function intersectionBy<T, U>(firstArr: readonly T[], secondArr: readonly
|
|
34
|
+
declare function intersectionBy<T, U>(firstArr: readonly T[], secondArr: readonly U[], mapper: (item: T | U) => unknown): T[];
|
|
24
35
|
|
|
25
36
|
export { intersectionBy };
|