es-toolkit 1.29.0-dev.932 → 1.29.0-dev.933
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/differenceWith.d.mts +91 -0
- package/dist/compat/array/differenceWith.d.ts +91 -0
- package/dist/compat/array/differenceWith.mjs +19 -0
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +13 -1
- package/dist/compat/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between the primary array and another array using a comparator function.
|
|
3
|
+
*
|
|
4
|
+
* @template T1, T2
|
|
5
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
6
|
+
* @param {ArrayLike<T2>} values - The array containing elements to compare with the primary array.
|
|
7
|
+
* @param {(a: T1, b: T2) => boolean} comparator - A function to determine if two elements are considered equal.
|
|
8
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values` based on the comparator.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
12
|
+
* const values = [{ id: 2 }];
|
|
13
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
14
|
+
*
|
|
15
|
+
* const result = differenceWith(array, values, comparator);
|
|
16
|
+
* // result will be [{ id: 1 }, { id: 3 }]
|
|
17
|
+
*/
|
|
18
|
+
declare function differenceWith<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, comparator: (a: T1, b: T2) => boolean): T1[];
|
|
19
|
+
/**
|
|
20
|
+
* Computes the difference between the primary array and two arrays using a comparator function.
|
|
21
|
+
*
|
|
22
|
+
* @template T1, T2, T3
|
|
23
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
24
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
|
|
25
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
|
|
26
|
+
* @param {(a: T1, b: T2 | T3) => boolean} comparator - A function to determine if two elements are considered equal.
|
|
27
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values1` or `values2` based on the comparator.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
31
|
+
* const values1 = [{ id: 2 }];
|
|
32
|
+
* const values2 = [{ id: 3 }];
|
|
33
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
34
|
+
*
|
|
35
|
+
* const result = differenceWith(array, values1, values2, comparator);
|
|
36
|
+
* // result will be [{ id: 1 }]
|
|
37
|
+
*/
|
|
38
|
+
declare function differenceWith<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, comparator: (a: T1, b: T2 | T3) => boolean): T1[];
|
|
39
|
+
/**
|
|
40
|
+
* Computes the difference between the primary array and multiple arrays using a comparator function.
|
|
41
|
+
*
|
|
42
|
+
* @template T1, T2, T3, T4
|
|
43
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
44
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
|
|
45
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
|
|
46
|
+
* @param {...Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>} values - Additional arrays and an optional comparator function to determine if two elements are considered equal.
|
|
47
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements
|
|
48
|
+
* in `values1`, `values2`, or subsequent arrays. If a comparator function is provided, it will be used to compare elements;
|
|
49
|
+
* otherwise, [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) algorithm will be used.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Example with comparator function
|
|
53
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
|
|
54
|
+
* const values1 = [{ id: 2 }];
|
|
55
|
+
* const values2 = [{ id: 3 }];
|
|
56
|
+
* const values3 = [{ id: 4 }];
|
|
57
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
58
|
+
*
|
|
59
|
+
* const result = differenceWith(array, values1, values2, values3, comparator);
|
|
60
|
+
* // result will be [{ id: 1 }]
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Example without comparator function (behaves like `difference`)
|
|
64
|
+
* const array = [1, 2, 3, 4];
|
|
65
|
+
* const values1 = [2];
|
|
66
|
+
* const values2 = [3];
|
|
67
|
+
* const values3 = [4];
|
|
68
|
+
*
|
|
69
|
+
* const result = differenceWith(array, values1, values2, values3);
|
|
70
|
+
* // result will be [1]
|
|
71
|
+
*/
|
|
72
|
+
declare function differenceWith<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>): T1[];
|
|
73
|
+
/**
|
|
74
|
+
* Computes the difference between the primary array and one or more arrays without using a comparator function.
|
|
75
|
+
*
|
|
76
|
+
* @template T
|
|
77
|
+
* @param {ArrayLike<T> | null | undefined} array - The primary array to compare elements against.
|
|
78
|
+
* @param {...Array<ArrayLike<T>>} values - One or more arrays containing elements to compare with the primary array.
|
|
79
|
+
* @returns {T[]} A new array containing the elements from the primary array that do not match any elements in the provided arrays.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const array = [1, 2, 3];
|
|
83
|
+
* const values1 = [2];
|
|
84
|
+
* const values2 = [3];
|
|
85
|
+
*
|
|
86
|
+
* const result = differenceWith(array, values1, values2);
|
|
87
|
+
* // result will be [1]
|
|
88
|
+
*/
|
|
89
|
+
declare function differenceWith<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
|
|
90
|
+
|
|
91
|
+
export { differenceWith };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between the primary array and another array using a comparator function.
|
|
3
|
+
*
|
|
4
|
+
* @template T1, T2
|
|
5
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
6
|
+
* @param {ArrayLike<T2>} values - The array containing elements to compare with the primary array.
|
|
7
|
+
* @param {(a: T1, b: T2) => boolean} comparator - A function to determine if two elements are considered equal.
|
|
8
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values` based on the comparator.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
12
|
+
* const values = [{ id: 2 }];
|
|
13
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
14
|
+
*
|
|
15
|
+
* const result = differenceWith(array, values, comparator);
|
|
16
|
+
* // result will be [{ id: 1 }, { id: 3 }]
|
|
17
|
+
*/
|
|
18
|
+
declare function differenceWith<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, comparator: (a: T1, b: T2) => boolean): T1[];
|
|
19
|
+
/**
|
|
20
|
+
* Computes the difference between the primary array and two arrays using a comparator function.
|
|
21
|
+
*
|
|
22
|
+
* @template T1, T2, T3
|
|
23
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
24
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
|
|
25
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
|
|
26
|
+
* @param {(a: T1, b: T2 | T3) => boolean} comparator - A function to determine if two elements are considered equal.
|
|
27
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values1` or `values2` based on the comparator.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
31
|
+
* const values1 = [{ id: 2 }];
|
|
32
|
+
* const values2 = [{ id: 3 }];
|
|
33
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
34
|
+
*
|
|
35
|
+
* const result = differenceWith(array, values1, values2, comparator);
|
|
36
|
+
* // result will be [{ id: 1 }]
|
|
37
|
+
*/
|
|
38
|
+
declare function differenceWith<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, comparator: (a: T1, b: T2 | T3) => boolean): T1[];
|
|
39
|
+
/**
|
|
40
|
+
* Computes the difference between the primary array and multiple arrays using a comparator function.
|
|
41
|
+
*
|
|
42
|
+
* @template T1, T2, T3, T4
|
|
43
|
+
* @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
|
|
44
|
+
* @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
|
|
45
|
+
* @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
|
|
46
|
+
* @param {...Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>} values - Additional arrays and an optional comparator function to determine if two elements are considered equal.
|
|
47
|
+
* @returns {T1[]} A new array containing the elements from the primary array that do not match any elements
|
|
48
|
+
* in `values1`, `values2`, or subsequent arrays. If a comparator function is provided, it will be used to compare elements;
|
|
49
|
+
* otherwise, [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) algorithm will be used.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Example with comparator function
|
|
53
|
+
* const array = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
|
|
54
|
+
* const values1 = [{ id: 2 }];
|
|
55
|
+
* const values2 = [{ id: 3 }];
|
|
56
|
+
* const values3 = [{ id: 4 }];
|
|
57
|
+
* const comparator = (a, b) => a.id === b.id;
|
|
58
|
+
*
|
|
59
|
+
* const result = differenceWith(array, values1, values2, values3, comparator);
|
|
60
|
+
* // result will be [{ id: 1 }]
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Example without comparator function (behaves like `difference`)
|
|
64
|
+
* const array = [1, 2, 3, 4];
|
|
65
|
+
* const values1 = [2];
|
|
66
|
+
* const values2 = [3];
|
|
67
|
+
* const values3 = [4];
|
|
68
|
+
*
|
|
69
|
+
* const result = differenceWith(array, values1, values2, values3);
|
|
70
|
+
* // result will be [1]
|
|
71
|
+
*/
|
|
72
|
+
declare function differenceWith<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>): T1[];
|
|
73
|
+
/**
|
|
74
|
+
* Computes the difference between the primary array and one or more arrays without using a comparator function.
|
|
75
|
+
*
|
|
76
|
+
* @template T
|
|
77
|
+
* @param {ArrayLike<T> | null | undefined} array - The primary array to compare elements against.
|
|
78
|
+
* @param {...Array<ArrayLike<T>>} values - One or more arrays containing elements to compare with the primary array.
|
|
79
|
+
* @returns {T[]} A new array containing the elements from the primary array that do not match any elements in the provided arrays.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const array = [1, 2, 3];
|
|
83
|
+
* const values1 = [2];
|
|
84
|
+
* const values2 = [3];
|
|
85
|
+
*
|
|
86
|
+
* const result = differenceWith(array, values1, values2);
|
|
87
|
+
* // result will be [1]
|
|
88
|
+
*/
|
|
89
|
+
declare function differenceWith<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
|
|
90
|
+
|
|
91
|
+
export { differenceWith };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { last } from './last.mjs';
|
|
2
|
+
import { difference } from '../../array/difference.mjs';
|
|
3
|
+
import { differenceWith as differenceWith$1 } from '../../array/differenceWith.mjs';
|
|
4
|
+
import { flattenArrayLike } from '../_internal/flattenArrayLike.mjs';
|
|
5
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
6
|
+
|
|
7
|
+
function differenceWith(array, ...values) {
|
|
8
|
+
if (!isArrayLikeObject(array)) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const comparator = last(values);
|
|
12
|
+
const flattenedValues = flattenArrayLike(values);
|
|
13
|
+
if (typeof comparator === 'function') {
|
|
14
|
+
return differenceWith$1(Array.from(array), flattenedValues, comparator);
|
|
15
|
+
}
|
|
16
|
+
return difference(Array.from(array), flattenedValues);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { differenceWith };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { at } from '../array/at.mjs';
|
|
2
2
|
export { countBy } from '../array/countBy.mjs';
|
|
3
|
-
export { differenceWith } from '../array/differenceWith.mjs';
|
|
4
3
|
export { flatMap } from '../array/flatMap.mjs';
|
|
5
4
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
6
5
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -82,6 +81,7 @@ export { compact } from './array/compact.mjs';
|
|
|
82
81
|
export { concat } from './array/concat.mjs';
|
|
83
82
|
export { difference } from './array/difference.mjs';
|
|
84
83
|
export { differenceBy } from './array/differenceBy.mjs';
|
|
84
|
+
export { differenceWith } from './array/differenceWith.mjs';
|
|
85
85
|
export { drop } from './array/drop.mjs';
|
|
86
86
|
export { dropRight } from './array/dropRight.mjs';
|
|
87
87
|
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { at } from '../array/at.js';
|
|
2
2
|
export { countBy } from '../array/countBy.js';
|
|
3
|
-
export { differenceWith } from '../array/differenceWith.js';
|
|
4
3
|
export { flatMap } from '../array/flatMap.js';
|
|
5
4
|
export { flatMapDeep } from '../array/flatMapDeep.js';
|
|
6
5
|
export { forEachRight } from '../array/forEachRight.js';
|
|
@@ -82,6 +81,7 @@ export { compact } from './array/compact.js';
|
|
|
82
81
|
export { concat } from './array/concat.js';
|
|
83
82
|
export { difference } from './array/difference.js';
|
|
84
83
|
export { differenceBy } from './array/differenceBy.js';
|
|
84
|
+
export { differenceWith } from './array/differenceWith.js';
|
|
85
85
|
export { drop } from './array/drop.js';
|
|
86
86
|
export { dropRight } from './array/dropRight.js';
|
|
87
87
|
export { dropRightWhile } from './array/dropRightWhile.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -496,6 +496,18 @@ function differenceBy(arr, ..._values) {
|
|
|
496
496
|
return zipWith.differenceBy(Array.from(arr), values, iteratee(iteratee$1));
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
function differenceWith(array, ...values) {
|
|
500
|
+
if (!isArrayLikeObject(array)) {
|
|
501
|
+
return [];
|
|
502
|
+
}
|
|
503
|
+
const comparator = last(values);
|
|
504
|
+
const flattenedValues = flattenArrayLike(values);
|
|
505
|
+
if (typeof comparator === 'function') {
|
|
506
|
+
return zipWith.differenceWith(Array.from(array), flattenedValues, comparator);
|
|
507
|
+
}
|
|
508
|
+
return zipWith.difference(Array.from(array), flattenedValues);
|
|
509
|
+
}
|
|
510
|
+
|
|
499
511
|
function isSymbol(value) {
|
|
500
512
|
return typeof value === 'symbol' || value instanceof Symbol;
|
|
501
513
|
}
|
|
@@ -2807,7 +2819,6 @@ function toSafeInteger(value) {
|
|
|
2807
2819
|
|
|
2808
2820
|
exports.at = zipWith.at;
|
|
2809
2821
|
exports.countBy = zipWith.countBy;
|
|
2810
|
-
exports.differenceWith = zipWith.differenceWith;
|
|
2811
2822
|
exports.flatMap = zipWith.flatMap;
|
|
2812
2823
|
exports.flatMapDeep = zipWith.flatMapDeep;
|
|
2813
2824
|
exports.forEachRight = zipWith.forEachRight;
|
|
@@ -2913,6 +2924,7 @@ exports.defaults = defaults;
|
|
|
2913
2924
|
exports.defer = defer;
|
|
2914
2925
|
exports.difference = difference;
|
|
2915
2926
|
exports.differenceBy = differenceBy;
|
|
2927
|
+
exports.differenceWith = differenceWith;
|
|
2916
2928
|
exports.drop = drop;
|
|
2917
2929
|
exports.dropRight = dropRight;
|
|
2918
2930
|
exports.dropRightWhile = dropRightWhile;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { at } from '../array/at.mjs';
|
|
2
2
|
export { countBy } from '../array/countBy.mjs';
|
|
3
|
-
export { differenceWith } from '../array/differenceWith.mjs';
|
|
4
3
|
export { flatMap } from '../array/flatMap.mjs';
|
|
5
4
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
6
5
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -83,6 +82,7 @@ export { compact } from './array/compact.mjs';
|
|
|
83
82
|
export { concat } from './array/concat.mjs';
|
|
84
83
|
export { difference } from './array/difference.mjs';
|
|
85
84
|
export { differenceBy } from './array/differenceBy.mjs';
|
|
85
|
+
export { differenceWith } from './array/differenceWith.mjs';
|
|
86
86
|
export { drop } from './array/drop.mjs';
|
|
87
87
|
export { dropRight } from './array/dropRight.mjs';
|
|
88
88
|
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
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.29.0-dev.
|
|
4
|
+
"version": "1.29.0-dev.933+5b5194d3",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|