es-toolkit 1.25.2-dev.810 → 1.25.2-dev.813

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.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
3
+ *
4
+ * This function takes multiple arrays and an iteratee function (or property key) to
5
+ * compare the elements after transforming them. It returns a new array containing the elements from
6
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
7
+ *
8
+ * @template T1, T2
9
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
10
+ * @param {ArrayLike<T2>} values - The second array to compare.
11
+ * @param {(value: T1 | T2) => unknown | string} iteratee - The iteratee invoked on each element
12
+ * for comparison. It can also be a property key to compare based on that property.
13
+ * @returns {T1[]} A new array containing the elements from the first array that are present
14
+ * in all subsequent arrays after applying the iteratee.
15
+ *
16
+ * @example
17
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
18
+ * const array2 = [{ x: 2 }, { x: 3 }, { x: 4 }];
19
+ * const result = intersectionBy(array1, array2, 'x');
20
+ * // result will be [{ x: 2 }, { x: 3 }] since these elements have the same `x` property.
21
+ *
22
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
23
+ * const array2 = [{ x: 2 }, { x: 3 }, { x: 4 }];
24
+ * const result = intersectionBy(array1, array2, value => value.x);
25
+ * // result will be [{ x: 2 }, { x: 3 }] since these elements have the same `x` property.
26
+ */
27
+ declare function intersectionBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: ((value: T1 | T2) => unknown) | string): T1[];
28
+ /**
29
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
30
+ *
31
+ * This function takes multiple arrays and an iteratee function (or property key) to
32
+ * compare the elements after transforming them. It returns a new array containing the elements from
33
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
34
+ *
35
+ * @template T1, T2, T3
36
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
37
+ * @param {ArrayLike<T2>} values1 - The second array to compare.
38
+ * @param {ArrayLike<T3>} values2 - The third array to compare.
39
+ * @param {(value: T1 | T2 | T3) => unknown | string} iteratee - The iteratee invoked on each element
40
+ * for comparison. It can also be a property key to compare based on that property.
41
+ * @returns {T1[]} A new array containing the elements from the first array that are present
42
+ * in all subsequent arrays after applying the iteratee.
43
+ *
44
+ * @example
45
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
46
+ * const array2 = [{ x: 2 }, { x: 3 }];
47
+ * const array3 = [{ x: 3 }];
48
+ * const result = intersectionBy(array1, array2, array3, 'x');
49
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
50
+ *
51
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
52
+ * const array2 = [{ x: 2 }, { x: 3 }];
53
+ * const array3 = [{ x: 3 }];
54
+ * const result = intersectionBy(array1, array2, array3, value => value.x);
55
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
56
+ */
57
+ declare function intersectionBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: ((value: T1 | T2 | T3) => unknown) | string): T1[];
58
+ /**
59
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
60
+ *
61
+ * This function takes multiple arrays and an iteratee function (or property key) to
62
+ * compare the elements after transforming them. It returns a new array containing the elements from
63
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
64
+ *
65
+ * @template T1, T2, T3, T4
66
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
67
+ * @param {ArrayLike<T2>} values1 - The second array to compare.
68
+ * @param {ArrayLike<T3>} values2 - The third array to compare.
69
+ * @param {...(ArrayLike<T4> | ((value: T1 | T2 | T3 | T4) => unknown) | string)} values - Additional arrays to compare, or the iteratee function.
70
+ * @returns {T1[]} A new array containing the elements from the first array that are present
71
+ * in all subsequent arrays after applying the iteratee.
72
+ *
73
+ * @example
74
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
75
+ * const array2 = [{ x: 2 }, { x: 3 }];
76
+ * const array3 = [{ x: 3 }];
77
+ * const array4 = [{ x: 3 }, { x: 4 }];
78
+ * const result = intersectionBy(array1, array2, array3, array4, 'x');
79
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
80
+ *
81
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
82
+ * const array2 = [{ x: 2 }, { x: 3 }];
83
+ * const array3 = [{ x: 3 }];
84
+ * const array4 = [{ x: 3 }, { x: 4 }];
85
+ * const result = intersectionBy(array1, array2, array3, array4, value => value.x);
86
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
87
+ */
88
+ declare function intersectionBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((value: T1 | T2 | T3 | T4) => unknown) | string>): T1[];
89
+ /**
90
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
91
+ *
92
+ * This function takes multiple arrays and an iteratee function (or property key) to
93
+ * compare the elements after transforming them. It returns a new array containing the elements from
94
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
95
+ *
96
+ * @template T
97
+ * @param {ArrayLike<T> | null | undefined} [array] - The first array to compare.
98
+ * @param {...ArrayLike<T>} values - Additional arrays to compare.
99
+ * @returns {T[]} A new array containing the elements from the first array that are present
100
+ * in all subsequent arrays after applying the iteratee.
101
+ *
102
+ * @example
103
+ * const array1 = [1, 2, 3];
104
+ * const array2 = [2, 3];
105
+ * const array3 = [3];
106
+ * const result = intersectionBy(array1, array2, array3);
107
+ * // result will be [3] since these all elements have the same value 3.
108
+ */
109
+ declare function intersectionBy<T>(array?: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
110
+
111
+ export { intersectionBy };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
3
+ *
4
+ * This function takes multiple arrays and an iteratee function (or property key) to
5
+ * compare the elements after transforming them. It returns a new array containing the elements from
6
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
7
+ *
8
+ * @template T1, T2
9
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
10
+ * @param {ArrayLike<T2>} values - The second array to compare.
11
+ * @param {(value: T1 | T2) => unknown | string} iteratee - The iteratee invoked on each element
12
+ * for comparison. It can also be a property key to compare based on that property.
13
+ * @returns {T1[]} A new array containing the elements from the first array that are present
14
+ * in all subsequent arrays after applying the iteratee.
15
+ *
16
+ * @example
17
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
18
+ * const array2 = [{ x: 2 }, { x: 3 }, { x: 4 }];
19
+ * const result = intersectionBy(array1, array2, 'x');
20
+ * // result will be [{ x: 2 }, { x: 3 }] since these elements have the same `x` property.
21
+ *
22
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
23
+ * const array2 = [{ x: 2 }, { x: 3 }, { x: 4 }];
24
+ * const result = intersectionBy(array1, array2, value => value.x);
25
+ * // result will be [{ x: 2 }, { x: 3 }] since these elements have the same `x` property.
26
+ */
27
+ declare function intersectionBy<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, iteratee: ((value: T1 | T2) => unknown) | string): T1[];
28
+ /**
29
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
30
+ *
31
+ * This function takes multiple arrays and an iteratee function (or property key) to
32
+ * compare the elements after transforming them. It returns a new array containing the elements from
33
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
34
+ *
35
+ * @template T1, T2, T3
36
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
37
+ * @param {ArrayLike<T2>} values1 - The second array to compare.
38
+ * @param {ArrayLike<T3>} values2 - The third array to compare.
39
+ * @param {(value: T1 | T2 | T3) => unknown | string} iteratee - The iteratee invoked on each element
40
+ * for comparison. It can also be a property key to compare based on that property.
41
+ * @returns {T1[]} A new array containing the elements from the first array that are present
42
+ * in all subsequent arrays after applying the iteratee.
43
+ *
44
+ * @example
45
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
46
+ * const array2 = [{ x: 2 }, { x: 3 }];
47
+ * const array3 = [{ x: 3 }];
48
+ * const result = intersectionBy(array1, array2, array3, 'x');
49
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
50
+ *
51
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
52
+ * const array2 = [{ x: 2 }, { x: 3 }];
53
+ * const array3 = [{ x: 3 }];
54
+ * const result = intersectionBy(array1, array2, array3, value => value.x);
55
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
56
+ */
57
+ declare function intersectionBy<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, iteratee: ((value: T1 | T2 | T3) => unknown) | string): T1[];
58
+ /**
59
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
60
+ *
61
+ * This function takes multiple arrays and an iteratee function (or property key) to
62
+ * compare the elements after transforming them. It returns a new array containing the elements from
63
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
64
+ *
65
+ * @template T1, T2, T3, T4
66
+ * @param {ArrayLike<T1> | null | undefined} array - The first array to compare.
67
+ * @param {ArrayLike<T2>} values1 - The second array to compare.
68
+ * @param {ArrayLike<T3>} values2 - The third array to compare.
69
+ * @param {...(ArrayLike<T4> | ((value: T1 | T2 | T3 | T4) => unknown) | string)} values - Additional arrays to compare, or the iteratee function.
70
+ * @returns {T1[]} A new array containing the elements from the first array that are present
71
+ * in all subsequent arrays after applying the iteratee.
72
+ *
73
+ * @example
74
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
75
+ * const array2 = [{ x: 2 }, { x: 3 }];
76
+ * const array3 = [{ x: 3 }];
77
+ * const array4 = [{ x: 3 }, { x: 4 }];
78
+ * const result = intersectionBy(array1, array2, array3, array4, 'x');
79
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
80
+ *
81
+ * const array1 = [{ x: 1 }, { x: 2 }, { x: 3 }];
82
+ * const array2 = [{ x: 2 }, { x: 3 }];
83
+ * const array3 = [{ x: 3 }];
84
+ * const array4 = [{ x: 3 }, { x: 4 }];
85
+ * const result = intersectionBy(array1, array2, array3, array4, value => value.x);
86
+ * // result will be [{ x: 3 }] since this element has the same `x` property in all arrays.
87
+ */
88
+ declare function intersectionBy<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((value: T1 | T2 | T3 | T4) => unknown) | string>): T1[];
89
+ /**
90
+ * Returns the intersection of multiple arrays after applying the iteratee function to their elements.
91
+ *
92
+ * This function takes multiple arrays and an iteratee function (or property key) to
93
+ * compare the elements after transforming them. It returns a new array containing the elements from
94
+ * the first array that are present in all subsequent arrays after applying the iteratee to each element.
95
+ *
96
+ * @template T
97
+ * @param {ArrayLike<T> | null | undefined} [array] - The first array to compare.
98
+ * @param {...ArrayLike<T>} values - Additional arrays to compare.
99
+ * @returns {T[]} A new array containing the elements from the first array that are present
100
+ * in all subsequent arrays after applying the iteratee.
101
+ *
102
+ * @example
103
+ * const array1 = [1, 2, 3];
104
+ * const array2 = [2, 3];
105
+ * const array3 = [3];
106
+ * const result = intersectionBy(array1, array2, array3);
107
+ * // result will be [3] since these all elements have the same value 3.
108
+ */
109
+ declare function intersectionBy<T>(array?: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
110
+
111
+ export { intersectionBy };
@@ -0,0 +1,36 @@
1
+ import { intersectionBy as intersectionBy$1 } from '../../array/intersectionBy.mjs';
2
+ import { last } from '../../array/last.mjs';
3
+ import { uniq } from '../../array/uniq.mjs';
4
+ import { identity } from '../_internal/identity.mjs';
5
+ import { property } from '../object/property.mjs';
6
+ import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
7
+
8
+ function intersectionBy(array, ...values) {
9
+ if (!isArrayLikeObject(array)) {
10
+ return [];
11
+ }
12
+ const lastValue = last(values);
13
+ if (lastValue === undefined) {
14
+ return Array.from(array);
15
+ }
16
+ let result = uniq(Array.from(array));
17
+ const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
18
+ for (let i = 0; i < count; ++i) {
19
+ const value = values[i];
20
+ if (!isArrayLikeObject(value)) {
21
+ return [];
22
+ }
23
+ if (isArrayLikeObject(lastValue)) {
24
+ result = intersectionBy$1(result, Array.from(value), identity);
25
+ }
26
+ else if (typeof lastValue === 'function') {
27
+ result = intersectionBy$1(result, Array.from(value), value => lastValue(value));
28
+ }
29
+ else if (typeof lastValue === 'string') {
30
+ result = intersectionBy$1(result, Array.from(value), property(lastValue));
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+
36
+ export { intersectionBy };
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
7
7
  export { forEachRight } from '../array/forEachRight.mjs';
8
8
  export { groupBy } from '../array/groupBy.mjs';
9
9
  export { initial } from '../array/initial.mjs';
10
- export { intersectionBy } from '../array/intersectionBy.mjs';
11
10
  export { intersectionWith } from '../array/intersectionWith.mjs';
12
11
  export { isSubset } from '../array/isSubset.mjs';
13
12
  export { keyBy } from '../array/keyBy.mjs';
@@ -101,6 +100,7 @@ export { head as first, head } from './array/head.mjs';
101
100
  export { includes } from './array/includes.mjs';
102
101
  export { indexOf } from './array/indexOf.mjs';
103
102
  export { intersection } from './array/intersection.mjs';
103
+ export { intersectionBy } from './array/intersectionBy.mjs';
104
104
  export { join } from './array/join.mjs';
105
105
  export { last } from './array/last.mjs';
106
106
  export { orderBy } from './array/orderBy.mjs';
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.js';
7
7
  export { forEachRight } from '../array/forEachRight.js';
8
8
  export { groupBy } from '../array/groupBy.js';
9
9
  export { initial } from '../array/initial.js';
10
- export { intersectionBy } from '../array/intersectionBy.js';
11
10
  export { intersectionWith } from '../array/intersectionWith.js';
12
11
  export { isSubset } from '../array/isSubset.js';
13
12
  export { keyBy } from '../array/keyBy.js';
@@ -101,6 +100,7 @@ export { head as first, head } from './array/head.js';
101
100
  export { includes } from './array/includes.js';
102
101
  export { indexOf } from './array/indexOf.js';
103
102
  export { intersection } from './array/intersection.js';
103
+ export { intersectionBy } from './array/intersectionBy.js';
104
104
  export { join } from './array/join.js';
105
105
  export { last } from './array/last.js';
106
106
  export { orderBy } from './array/orderBy.js';
@@ -824,6 +824,34 @@ function intersection(...arrays) {
824
824
  return result;
825
825
  }
826
826
 
827
+ function intersectionBy(array, ...values) {
828
+ if (!isArrayLikeObject(array)) {
829
+ return [];
830
+ }
831
+ const lastValue = zipWith.last(values);
832
+ if (lastValue === undefined) {
833
+ return Array.from(array);
834
+ }
835
+ let result = zipWith.uniq(Array.from(array));
836
+ const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
837
+ for (let i = 0; i < count; ++i) {
838
+ const value = values[i];
839
+ if (!isArrayLikeObject(value)) {
840
+ return [];
841
+ }
842
+ if (isArrayLikeObject(lastValue)) {
843
+ result = zipWith.intersectionBy(result, Array.from(value), identity);
844
+ }
845
+ else if (typeof lastValue === 'function') {
846
+ result = zipWith.intersectionBy(result, Array.from(value), value => lastValue(value));
847
+ }
848
+ else if (typeof lastValue === 'string') {
849
+ result = zipWith.intersectionBy(result, Array.from(value), property(lastValue));
850
+ }
851
+ }
852
+ return result;
853
+ }
854
+
827
855
  function join(array, separator = ',') {
828
856
  if (!isArrayLike(array)) {
829
857
  return '';
@@ -2257,7 +2285,6 @@ exports.flatMapDeep = zipWith.flatMapDeep;
2257
2285
  exports.forEachRight = zipWith.forEachRight;
2258
2286
  exports.groupBy = zipWith.groupBy;
2259
2287
  exports.initial = zipWith.initial;
2260
- exports.intersectionBy = zipWith.intersectionBy;
2261
2288
  exports.intersectionWith = zipWith.intersectionWith;
2262
2289
  exports.isSubset = zipWith.isSubset;
2263
2290
  exports.keyBy = zipWith.keyBy;
@@ -2384,6 +2411,7 @@ exports.inRange = inRange;
2384
2411
  exports.includes = includes;
2385
2412
  exports.indexOf = indexOf;
2386
2413
  exports.intersection = intersection;
2414
+ exports.intersectionBy = intersectionBy;
2387
2415
  exports.invertBy = invertBy;
2388
2416
  exports.isArguments = isArguments;
2389
2417
  exports.isArray = isArray;
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
7
7
  export { forEachRight } from '../array/forEachRight.mjs';
8
8
  export { groupBy } from '../array/groupBy.mjs';
9
9
  export { initial } from '../array/initial.mjs';
10
- export { intersectionBy } from '../array/intersectionBy.mjs';
11
10
  export { intersectionWith } from '../array/intersectionWith.mjs';
12
11
  export { isSubset } from '../array/isSubset.mjs';
13
12
  export { keyBy } from '../array/keyBy.mjs';
@@ -103,6 +102,7 @@ export { head as first, head } from './array/head.mjs';
103
102
  export { includes } from './array/includes.mjs';
104
103
  export { indexOf } from './array/indexOf.mjs';
105
104
  export { intersection } from './array/intersection.mjs';
105
+ export { intersectionBy } from './array/intersectionBy.mjs';
106
106
  export { join } from './array/join.mjs';
107
107
  export { last } from './array/last.mjs';
108
108
  export { orderBy } from './array/orderBy.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.25.2-dev.810+4a8ea44e",
4
+ "version": "1.25.2-dev.813+d22c156d",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {