es-toolkit 1.32.0-dev.1005 → 1.32.0-dev.1007
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/find.mjs +12 -32
- package/dist/compat/array/findLast.d.mts +130 -0
- package/dist/compat/array/findLast.d.ts +130 -0
- package/dist/compat/array/findLast.mjs +32 -0
- package/dist/compat/array/intersectionWith.d.mts +96 -0
- package/dist/compat/array/intersectionWith.d.ts +96 -0
- package/dist/compat/array/intersectionWith.mjs +43 -0
- package/dist/compat/index.d.mts +2 -1
- package/dist/compat/index.d.ts +2 -1
- package/dist/compat/index.js +85 -37
- package/dist/compat/index.mjs +2 -1
- package/package.json +1 -1
package/dist/compat/index.js
CHANGED
|
@@ -728,45 +728,27 @@ function filter(source, predicate) {
|
|
|
728
728
|
}
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
-
function find(source,
|
|
731
|
+
function find(source, _doesMatch, fromIndex = 0) {
|
|
732
732
|
if (!source) {
|
|
733
733
|
return undefined;
|
|
734
734
|
}
|
|
735
735
|
if (fromIndex < 0) {
|
|
736
736
|
fromIndex = Math.max(source.length + fromIndex, 0);
|
|
737
737
|
}
|
|
738
|
+
const doesMatch = iteratee(_doesMatch);
|
|
738
739
|
const values = Array.isArray(source) ? source.slice(fromIndex) : Object.values(source).slice(fromIndex);
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (doesMatch(value, key, source)) {
|
|
747
|
-
return value;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return undefined;
|
|
740
|
+
if (typeof doesMatch === 'function' && !Array.isArray(source)) {
|
|
741
|
+
const keys = Object.keys(source).slice(fromIndex);
|
|
742
|
+
for (let i = 0; i < keys.length; i++) {
|
|
743
|
+
const key = keys[i];
|
|
744
|
+
const value = source[key];
|
|
745
|
+
if (doesMatch(value, key, source)) {
|
|
746
|
+
return value;
|
|
751
747
|
}
|
|
752
|
-
return values.find(doesMatch);
|
|
753
|
-
}
|
|
754
|
-
case 'object': {
|
|
755
|
-
if (Array.isArray(doesMatch) && doesMatch.length === 2) {
|
|
756
|
-
const key = doesMatch[0];
|
|
757
|
-
const value = doesMatch[1];
|
|
758
|
-
return values.find(matchesProperty(key, value));
|
|
759
|
-
}
|
|
760
|
-
else {
|
|
761
|
-
return values.find(matches(doesMatch));
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
case 'symbol':
|
|
765
|
-
case 'number':
|
|
766
|
-
case 'string': {
|
|
767
|
-
return values.find(property(doesMatch));
|
|
768
748
|
}
|
|
749
|
+
return undefined;
|
|
769
750
|
}
|
|
751
|
+
return values.find(doesMatch);
|
|
770
752
|
}
|
|
771
753
|
|
|
772
754
|
function findIndex(arr, doesMatch, fromIndex = 0) {
|
|
@@ -803,6 +785,34 @@ function findIndex(arr, doesMatch, fromIndex = 0) {
|
|
|
803
785
|
return index === -1 ? -1 : index + fromIndex;
|
|
804
786
|
}
|
|
805
787
|
|
|
788
|
+
function findLast(source, _doesMatch, fromIndex) {
|
|
789
|
+
if (!source) {
|
|
790
|
+
return undefined;
|
|
791
|
+
}
|
|
792
|
+
const length = Array.isArray(source) ? source.length : Object.keys(source).length;
|
|
793
|
+
fromIndex = toInteger(fromIndex ?? length - 1);
|
|
794
|
+
if (fromIndex < 0) {
|
|
795
|
+
fromIndex = Math.max(length + fromIndex, 0);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
fromIndex = Math.min(fromIndex, length - 1);
|
|
799
|
+
}
|
|
800
|
+
const doesMatch = iteratee(_doesMatch);
|
|
801
|
+
const values = Array.isArray(source) ? source.slice(0, fromIndex + 1) : Object.values(source).slice(0, fromIndex + 1);
|
|
802
|
+
if (typeof doesMatch === 'function' && !Array.isArray(source)) {
|
|
803
|
+
const keys = Object.keys(source).slice(0, fromIndex + 1);
|
|
804
|
+
for (let i = fromIndex; i >= 0; i--) {
|
|
805
|
+
const key = keys[i];
|
|
806
|
+
const value = source[key];
|
|
807
|
+
if (doesMatch(value, key, source)) {
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return undefined;
|
|
812
|
+
}
|
|
813
|
+
return values.findLast(doesMatch);
|
|
814
|
+
}
|
|
815
|
+
|
|
806
816
|
function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
807
817
|
if (!arr) {
|
|
808
818
|
return -1;
|
|
@@ -996,6 +1006,50 @@ function intersectionBy(array, ...values) {
|
|
|
996
1006
|
return result;
|
|
997
1007
|
}
|
|
998
1008
|
|
|
1009
|
+
function uniq(arr) {
|
|
1010
|
+
if (!isArrayLike(arr)) {
|
|
1011
|
+
return [];
|
|
1012
|
+
}
|
|
1013
|
+
return zipWith.uniq(Array.from(arr));
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function intersectionWith(firstArr, ...otherArrs) {
|
|
1017
|
+
console.log(firstArr);
|
|
1018
|
+
if (firstArr == null) {
|
|
1019
|
+
return [];
|
|
1020
|
+
}
|
|
1021
|
+
const _comparator = last(otherArrs);
|
|
1022
|
+
let comparator = isWeakSet$1.eq;
|
|
1023
|
+
let uniq$1 = uniq;
|
|
1024
|
+
if (typeof _comparator === 'function') {
|
|
1025
|
+
comparator = _comparator;
|
|
1026
|
+
uniq$1 = uniqPreserve0;
|
|
1027
|
+
otherArrs.pop();
|
|
1028
|
+
}
|
|
1029
|
+
let result = uniq$1(Array.from(firstArr));
|
|
1030
|
+
for (let i = 0; i < otherArrs.length; ++i) {
|
|
1031
|
+
const otherArr = otherArrs[i];
|
|
1032
|
+
if (otherArr == null) {
|
|
1033
|
+
return [];
|
|
1034
|
+
}
|
|
1035
|
+
result = zipWith.intersectionWith(result, Array.from(otherArr), comparator);
|
|
1036
|
+
}
|
|
1037
|
+
return result;
|
|
1038
|
+
}
|
|
1039
|
+
function uniqPreserve0(arr) {
|
|
1040
|
+
const result = [];
|
|
1041
|
+
const added = new Set();
|
|
1042
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1043
|
+
const item = arr[i];
|
|
1044
|
+
if (added.has(item)) {
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
result.push(item);
|
|
1048
|
+
added.add(item);
|
|
1049
|
+
}
|
|
1050
|
+
return result;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
999
1053
|
function join(array, separator = ',') {
|
|
1000
1054
|
if (!isArrayLike(array)) {
|
|
1001
1055
|
return '';
|
|
@@ -1438,13 +1492,6 @@ function union(...arrays) {
|
|
|
1438
1492
|
return zipWith.uniq(flattened);
|
|
1439
1493
|
}
|
|
1440
1494
|
|
|
1441
|
-
function uniq(arr) {
|
|
1442
|
-
if (!isArrayLike(arr)) {
|
|
1443
|
-
return [];
|
|
1444
|
-
}
|
|
1445
|
-
return zipWith.uniq(Array.from(arr));
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
1495
|
function uniqBy(array, iteratee$1) {
|
|
1449
1496
|
if (!isArrayLikeObject(array)) {
|
|
1450
1497
|
return [];
|
|
@@ -3173,7 +3220,6 @@ exports.flatMapDeep = zipWith.flatMapDeep;
|
|
|
3173
3220
|
exports.forEachRight = zipWith.forEachRight;
|
|
3174
3221
|
exports.groupBy = zipWith.groupBy;
|
|
3175
3222
|
exports.initial = zipWith.initial;
|
|
3176
|
-
exports.intersectionWith = zipWith.intersectionWith;
|
|
3177
3223
|
exports.isSubset = zipWith.isSubset;
|
|
3178
3224
|
exports.isSubsetWith = zipWith.isSubsetWith;
|
|
3179
3225
|
exports.keyBy = zipWith.keyBy;
|
|
@@ -3286,6 +3332,7 @@ exports.filter = filter;
|
|
|
3286
3332
|
exports.find = find;
|
|
3287
3333
|
exports.findIndex = findIndex;
|
|
3288
3334
|
exports.findKey = findKey;
|
|
3335
|
+
exports.findLast = findLast;
|
|
3289
3336
|
exports.findLastIndex = findLastIndex;
|
|
3290
3337
|
exports.first = head;
|
|
3291
3338
|
exports.flatten = flatten;
|
|
@@ -3307,6 +3354,7 @@ exports.includes = includes;
|
|
|
3307
3354
|
exports.indexOf = indexOf;
|
|
3308
3355
|
exports.intersection = intersection;
|
|
3309
3356
|
exports.intersectionBy = intersectionBy;
|
|
3357
|
+
exports.intersectionWith = intersectionWith;
|
|
3310
3358
|
exports.invertBy = invertBy;
|
|
3311
3359
|
exports.invoke = invoke;
|
|
3312
3360
|
exports.isArguments = isArguments;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
|
5
5
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
6
6
|
export { groupBy } from '../array/groupBy.mjs';
|
|
7
7
|
export { initial } from '../array/initial.mjs';
|
|
8
|
-
export { intersectionWith } from '../array/intersectionWith.mjs';
|
|
9
8
|
export { isSubset } from '../array/isSubset.mjs';
|
|
10
9
|
export { isSubsetWith } from '../array/isSubsetWith.mjs';
|
|
11
10
|
export { keyBy } from '../array/keyBy.mjs';
|
|
@@ -87,6 +86,7 @@ export { fill } from './array/fill.mjs';
|
|
|
87
86
|
export { filter } from './array/filter.mjs';
|
|
88
87
|
export { find } from './array/find.mjs';
|
|
89
88
|
export { findIndex } from './array/findIndex.mjs';
|
|
89
|
+
export { findLast } from './array/findLast.mjs';
|
|
90
90
|
export { findLastIndex } from './array/findLastIndex.mjs';
|
|
91
91
|
export { flatten } from './array/flatten.mjs';
|
|
92
92
|
export { flattenDeep } from './array/flattenDeep.mjs';
|
|
@@ -97,6 +97,7 @@ export { includes } from './array/includes.mjs';
|
|
|
97
97
|
export { indexOf } from './array/indexOf.mjs';
|
|
98
98
|
export { intersection } from './array/intersection.mjs';
|
|
99
99
|
export { intersectionBy } from './array/intersectionBy.mjs';
|
|
100
|
+
export { intersectionWith } from './array/intersectionWith.mjs';
|
|
100
101
|
export { join } from './array/join.mjs';
|
|
101
102
|
export { last } from './array/last.mjs';
|
|
102
103
|
export { lastIndexOf } from './array/lastIndexOf.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.32.0-dev.
|
|
4
|
+
"version": "1.32.0-dev.1007+9bc5fa98",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|