es-toolkit 1.27.0 → 1.28.0-dev.910
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 +14 -0
- package/dist/_chunk/{isWeakSet-D8h8bS.js → isWeakSet-CvIdTA.js} +5 -0
- package/dist/_chunk/{toMerged-CPY8Ug.js → toMerged-AV73JV.js} +77 -65
- package/dist/_chunk/{upperFirst-DK_rTF.js → upperFirst-CorAVn.js} +1 -0
- 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/flatMap.d.mts +1 -1
- package/dist/array/flatMap.d.ts +1 -1
- package/dist/array/intersectionBy.d.mts +16 -5
- package/dist/array/intersectionBy.d.ts +16 -5
- package/dist/array/intersectionWith.d.mts +16 -4
- package/dist/array/intersectionWith.d.ts +16 -4
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/dropRightWhile.d.mts +2 -2
- package/dist/compat/array/dropRightWhile.d.ts +2 -2
- package/dist/compat/array/dropRightWhile.mjs +2 -0
- package/dist/compat/array/dropWhile.d.mts +2 -2
- package/dist/compat/array/dropWhile.d.ts +2 -2
- package/dist/compat/array/dropWhile.mjs +2 -0
- package/dist/compat/array/every.d.mts +6 -6
- package/dist/compat/array/every.d.ts +6 -6
- package/dist/compat/array/every.mjs +2 -0
- package/dist/compat/array/filter.d.mts +4 -4
- package/dist/compat/array/filter.d.ts +4 -4
- package/dist/compat/array/filter.mjs +2 -0
- package/dist/compat/array/find.d.mts +6 -6
- package/dist/compat/array/find.d.ts +6 -6
- package/dist/compat/array/find.mjs +2 -0
- package/dist/compat/array/findIndex.d.mts +3 -3
- package/dist/compat/array/findIndex.d.ts +3 -3
- package/dist/compat/array/findIndex.mjs +2 -0
- package/dist/compat/array/findLastIndex.d.mts +3 -3
- package/dist/compat/array/findLastIndex.d.ts +3 -3
- package/dist/compat/array/findLastIndex.mjs +2 -0
- package/dist/compat/array/some.d.mts +5 -5
- package/dist/compat/array/some.d.ts +5 -5
- package/dist/compat/array/some.mjs +2 -0
- package/dist/compat/array/uniqBy.d.mts +34 -13
- package/dist/compat/array/uniqBy.d.ts +34 -13
- package/dist/compat/array/uniqBy.mjs +3 -16
- package/dist/compat/function/debounce.d.mts +7 -5
- package/dist/compat/function/debounce.d.ts +7 -5
- package/dist/compat/function/throttle.d.mts +3 -4
- package/dist/compat/function/throttle.d.ts +3 -4
- package/dist/compat/function/throttle.mjs +6 -1
- package/dist/compat/index.d.mts +13 -2
- package/dist/compat/index.d.ts +13 -2
- package/dist/compat/index.js +211 -69
- package/dist/compat/index.mjs +11 -1
- package/dist/compat/math/add.d.mts +18 -0
- package/dist/compat/math/add.d.ts +18 -0
- package/dist/compat/math/add.mjs +5 -0
- package/dist/compat/object/assignIn.d.mts +103 -0
- package/dist/compat/object/assignIn.d.ts +103 -0
- package/dist/compat/object/assignIn.mjs +20 -0
- package/dist/compat/object/cloneDeep.mjs +2 -24
- package/dist/compat/object/cloneDeepWith.d.mts +38 -0
- package/dist/compat/object/cloneDeepWith.d.ts +38 -0
- package/dist/compat/object/cloneDeepWith.mjs +35 -0
- package/dist/compat/object/keysIn.d.mts +26 -0
- package/dist/compat/object/keysIn.d.ts +26 -0
- package/dist/compat/object/keysIn.mjs +53 -0
- package/dist/compat/predicate/isElement.d.mts +13 -0
- package/dist/compat/predicate/isElement.d.ts +13 -0
- package/dist/compat/predicate/isElement.mjs +8 -0
- package/dist/compat/string/toUpper.d.mts +20 -0
- package/dist/compat/string/toUpper.d.ts +20 -0
- package/dist/compat/string/toUpper.mjs +7 -0
- package/dist/compat/string/trim.mjs +1 -1
- package/dist/compat/string/trimEnd.mjs +1 -1
- package/dist/compat/string/trimStart.mjs +1 -1
- package/dist/compat/string/words.d.mts +15 -0
- package/dist/compat/string/words.d.ts +15 -0
- package/dist/compat/string/words.mjs +10 -0
- package/dist/compat/util/gt.d.mts +15 -0
- package/dist/compat/util/gt.d.ts +15 -0
- package/dist/compat/util/gt.mjs +10 -0
- package/dist/compat/util/gte.d.mts +15 -0
- package/dist/compat/util/gte.d.ts +15 -0
- package/dist/compat/util/gte.mjs +10 -0
- package/dist/compat/util/iteratee.d.mts +1 -1
- package/dist/compat/util/iteratee.d.ts +1 -1
- package/dist/compat/util/toArray.d.mts +15 -0
- package/dist/compat/util/toArray.d.ts +15 -0
- package/dist/compat/util/toArray.mjs +20 -0
- package/dist/function/debounce.d.mts +24 -22
- package/dist/function/debounce.d.ts +24 -22
- package/dist/function/index.d.mts +2 -2
- package/dist/function/index.d.ts +2 -2
- package/dist/function/partial.d.mts +533 -15
- package/dist/function/partial.d.ts +533 -15
- package/dist/function/partialRight.d.mts +610 -15
- package/dist/function/partialRight.d.ts +610 -15
- package/dist/function/throttle.d.mts +7 -5
- package/dist/function/throttle.d.ts +7 -5
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/dist/index.mjs +2 -0
- package/dist/object/cloneDeep.mjs +3 -110
- package/dist/object/cloneDeepWith.d.mts +38 -0
- package/dist/object/cloneDeepWith.d.ts +38 -0
- package/dist/object/cloneDeepWith.mjs +121 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +2 -1
- package/dist/object/index.mjs +1 -0
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +2 -1
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isBuffer.d.mts +21 -0
- package/dist/predicate/isBuffer.d.ts +21 -0
- package/dist/predicate/isBuffer.mjs +5 -0
- package/dist/string/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# es-toolkit Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.28.0
|
|
4
|
+
|
|
5
|
+
Released on November 30th, 2024.
|
|
6
|
+
|
|
7
|
+
- Added compatibility functions for [gt](https://es-toolkit.slash.page/reference/compat/util/gt.html), [gte](https://es-toolkit.slash.page/reference/compat/util/gte.html), [toArray](https://es-toolkit.slash.page/reference/compat/util/toArray.html), [toUpper](https://es-toolkit.slash.page/reference/compat/string/toUpper.html), [add](https://es-toolkit.slash.page/reference/compat/math/add.html), [assignIn](https://es-toolkit.slash.page/reference/compat/object/assignIn.html) ([extend](https://es-toolkit.slash.page/reference/compat/object/extend.html)), and [isElement](https://es-toolkit.slash.page/reference/compat/predicate/isElement.html).
|
|
8
|
+
- Introduced new compatibility types for `DebouncedFunc`.
|
|
9
|
+
- Enhanced our function types to accept `PropertyKey` instead of just `string` for property keys.
|
|
10
|
+
- Corrected [flatMap](https://es-toolkit.slash.page/reference/array/flatMap.html) to accurately infer return types when the `depth` parameter is omitted.
|
|
11
|
+
- Resolved issues with incorrect types for [partial](https://es-toolkit.slash.page/reference/function/partial.html) and [partialRight](https://es-toolkit.slash.page/reference/function/partialRight.html).
|
|
12
|
+
- Fixed [intersectionBy](https://es-toolkit.slash.page/reference/array/intersectionBy.html), [differenceBy](https://es-toolkit.slash.page/reference/array/differenceBy.html), and [differenceWith](https://es-toolkit.slash.page/reference/array/differenceWith.html) to properly calculate differences between various element types.
|
|
13
|
+
- Ensured that [words](https://es-toolkit.slash.page/reference/string/words.html) is now correctly exported in our compatibility library.
|
|
14
|
+
|
|
15
|
+
We sincerely thank @D-Sketon, @mass2527, @1eeminhyeong, @chhw130, @DONG-8, @filipsobol, @kim-dongho, @nnnnoel, @pbstar, and @jsparkdev for their contributions. We appreciate your great efforts!
|
|
16
|
+
|
|
3
17
|
## Version v1.27.0
|
|
4
18
|
|
|
5
19
|
Released on November 10th, 2024.
|
|
@@ -14,6 +14,10 @@ function isBlob(x) {
|
|
|
14
14
|
return x instanceof Blob;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function isBuffer(x) {
|
|
18
|
+
return typeof Buffer !== 'undefined' && Buffer.isBuffer(x);
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
function isDate(value) {
|
|
18
22
|
return value instanceof Date;
|
|
19
23
|
}
|
|
@@ -334,6 +338,7 @@ exports.eq = eq;
|
|
|
334
338
|
exports.getTag = getTag;
|
|
335
339
|
exports.isArrayBuffer = isArrayBuffer;
|
|
336
340
|
exports.isBlob = isBlob;
|
|
341
|
+
exports.isBuffer = isBuffer;
|
|
337
342
|
exports.isDate = isDate;
|
|
338
343
|
exports.isEqual = isEqual;
|
|
339
344
|
exports.isEqualWith = isEqualWith;
|
|
@@ -43,115 +43,126 @@ function clone(obj) {
|
|
|
43
43
|
return obj;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function
|
|
47
|
-
return
|
|
46
|
+
function cloneDeepWith(obj, cloneValue) {
|
|
47
|
+
return cloneDeepWithImpl(obj, undefined, obj, new Map(), cloneValue);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = new Map(), cloneValue = undefined) {
|
|
50
|
+
const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
|
|
51
|
+
if (cloned != null) {
|
|
52
|
+
return cloned;
|
|
53
|
+
}
|
|
54
|
+
if (isPlainObject.isPrimitive(valueToClone)) {
|
|
55
|
+
return valueToClone;
|
|
52
56
|
}
|
|
53
|
-
if (stack.has(
|
|
54
|
-
return stack.get(
|
|
57
|
+
if (stack.has(valueToClone)) {
|
|
58
|
+
return stack.get(valueToClone);
|
|
55
59
|
}
|
|
56
|
-
if (Array.isArray(
|
|
57
|
-
const result = new Array(
|
|
58
|
-
stack.set(
|
|
59
|
-
for (let i = 0; i <
|
|
60
|
-
result[i] =
|
|
60
|
+
if (Array.isArray(valueToClone)) {
|
|
61
|
+
const result = new Array(valueToClone.length);
|
|
62
|
+
stack.set(valueToClone, result);
|
|
63
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
64
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
61
65
|
}
|
|
62
|
-
if (Object.hasOwn(
|
|
63
|
-
result.index =
|
|
66
|
+
if (Object.hasOwn(valueToClone, 'index')) {
|
|
67
|
+
result.index = valueToClone.index;
|
|
64
68
|
}
|
|
65
|
-
if (Object.hasOwn(
|
|
66
|
-
result.input =
|
|
69
|
+
if (Object.hasOwn(valueToClone, 'input')) {
|
|
70
|
+
result.input = valueToClone.input;
|
|
67
71
|
}
|
|
68
72
|
return result;
|
|
69
73
|
}
|
|
70
|
-
if (
|
|
71
|
-
return new Date(
|
|
74
|
+
if (valueToClone instanceof Date) {
|
|
75
|
+
return new Date(valueToClone.getTime());
|
|
72
76
|
}
|
|
73
|
-
if (
|
|
74
|
-
const result = new RegExp(
|
|
75
|
-
result.lastIndex =
|
|
77
|
+
if (valueToClone instanceof RegExp) {
|
|
78
|
+
const result = new RegExp(valueToClone.source, valueToClone.flags);
|
|
79
|
+
result.lastIndex = valueToClone.lastIndex;
|
|
76
80
|
return result;
|
|
77
81
|
}
|
|
78
|
-
if (
|
|
82
|
+
if (valueToClone instanceof Map) {
|
|
79
83
|
const result = new Map();
|
|
80
|
-
stack.set(
|
|
81
|
-
for (const [key, value] of
|
|
82
|
-
result.set(key,
|
|
84
|
+
stack.set(valueToClone, result);
|
|
85
|
+
for (const [key, value] of valueToClone) {
|
|
86
|
+
result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
|
|
83
87
|
}
|
|
84
88
|
return result;
|
|
85
89
|
}
|
|
86
|
-
if (
|
|
90
|
+
if (valueToClone instanceof Set) {
|
|
87
91
|
const result = new Set();
|
|
88
|
-
stack.set(
|
|
89
|
-
for (const value of
|
|
90
|
-
result.add(
|
|
92
|
+
stack.set(valueToClone, result);
|
|
93
|
+
for (const value of valueToClone) {
|
|
94
|
+
result.add(cloneDeepWithImpl(value, undefined, objectToClone, stack, cloneValue));
|
|
91
95
|
}
|
|
92
96
|
return result;
|
|
93
97
|
}
|
|
94
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(
|
|
95
|
-
return
|
|
98
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(valueToClone)) {
|
|
99
|
+
return valueToClone.subarray();
|
|
96
100
|
}
|
|
97
|
-
if (isPlainObject.isTypedArray(
|
|
98
|
-
const result = new (Object.getPrototypeOf(
|
|
99
|
-
stack.set(
|
|
100
|
-
for (let i = 0; i <
|
|
101
|
-
result[i] =
|
|
101
|
+
if (isPlainObject.isTypedArray(valueToClone)) {
|
|
102
|
+
const result = new (Object.getPrototypeOf(valueToClone).constructor)(valueToClone.length);
|
|
103
|
+
stack.set(valueToClone, result);
|
|
104
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
105
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
102
106
|
}
|
|
103
107
|
return result;
|
|
104
108
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
109
|
+
if (valueToClone instanceof ArrayBuffer ||
|
|
110
|
+
(typeof SharedArrayBuffer !== 'undefined' && valueToClone instanceof SharedArrayBuffer)) {
|
|
111
|
+
return valueToClone.slice(0);
|
|
107
112
|
}
|
|
108
|
-
if (
|
|
109
|
-
const result = new DataView(
|
|
110
|
-
stack.set(
|
|
111
|
-
copyProperties(result,
|
|
113
|
+
if (valueToClone instanceof DataView) {
|
|
114
|
+
const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
|
|
115
|
+
stack.set(valueToClone, result);
|
|
116
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
112
117
|
return result;
|
|
113
118
|
}
|
|
114
|
-
if (typeof File !== 'undefined' &&
|
|
115
|
-
const result = new File([
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
if (typeof File !== 'undefined' && valueToClone instanceof File) {
|
|
120
|
+
const result = new File([valueToClone], valueToClone.name, {
|
|
121
|
+
type: valueToClone.type,
|
|
122
|
+
});
|
|
123
|
+
stack.set(valueToClone, result);
|
|
124
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
118
125
|
return result;
|
|
119
126
|
}
|
|
120
|
-
if (
|
|
121
|
-
const result = new Blob([
|
|
122
|
-
stack.set(
|
|
123
|
-
copyProperties(result,
|
|
127
|
+
if (valueToClone instanceof Blob) {
|
|
128
|
+
const result = new Blob([valueToClone], { type: valueToClone.type });
|
|
129
|
+
stack.set(valueToClone, result);
|
|
130
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
124
131
|
return result;
|
|
125
132
|
}
|
|
126
|
-
if (
|
|
127
|
-
const result = new
|
|
128
|
-
stack.set(
|
|
129
|
-
result.message =
|
|
130
|
-
result.name =
|
|
131
|
-
result.stack =
|
|
132
|
-
result.cause =
|
|
133
|
-
copyProperties(result,
|
|
133
|
+
if (valueToClone instanceof Error) {
|
|
134
|
+
const result = new valueToClone.constructor();
|
|
135
|
+
stack.set(valueToClone, result);
|
|
136
|
+
result.message = valueToClone.message;
|
|
137
|
+
result.name = valueToClone.name;
|
|
138
|
+
result.stack = valueToClone.stack;
|
|
139
|
+
result.cause = valueToClone.cause;
|
|
140
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
134
141
|
return result;
|
|
135
142
|
}
|
|
136
|
-
if (typeof
|
|
137
|
-
const result = Object.create(Object.getPrototypeOf(
|
|
138
|
-
stack.set(
|
|
139
|
-
copyProperties(result,
|
|
143
|
+
if (typeof valueToClone === 'object' && valueToClone !== null) {
|
|
144
|
+
const result = Object.create(Object.getPrototypeOf(valueToClone));
|
|
145
|
+
stack.set(valueToClone, result);
|
|
146
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
140
147
|
return result;
|
|
141
148
|
}
|
|
142
|
-
return
|
|
149
|
+
return valueToClone;
|
|
143
150
|
}
|
|
144
|
-
function copyProperties(target, source, stack) {
|
|
151
|
+
function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
|
|
145
152
|
const keys = [...Object.keys(source), ...isPlainObject.getSymbols(source)];
|
|
146
153
|
for (let i = 0; i < keys.length; i++) {
|
|
147
154
|
const key = keys[i];
|
|
148
155
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
149
156
|
if (descriptor == null || descriptor.writable) {
|
|
150
|
-
target[key] =
|
|
157
|
+
target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
|
|
151
158
|
}
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
|
|
162
|
+
function cloneDeep(obj) {
|
|
163
|
+
return cloneDeepWithImpl(obj, undefined, obj, new Map(), undefined);
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
function findKey(obj, predicate) {
|
|
156
167
|
const keys = Object.keys(obj);
|
|
157
168
|
return keys.find(key => predicate(obj[key], key, obj));
|
|
@@ -280,6 +291,7 @@ function toMerged(target, source) {
|
|
|
280
291
|
|
|
281
292
|
exports.clone = clone;
|
|
282
293
|
exports.cloneDeep = cloneDeep;
|
|
294
|
+
exports.cloneDeepWith = cloneDeepWith;
|
|
283
295
|
exports.copyProperties = copyProperties;
|
|
284
296
|
exports.findKey = findKey;
|
|
285
297
|
exports.flattenObject = flattenObject;
|
|
@@ -186,6 +186,7 @@ function upperFirst(str) {
|
|
|
186
186
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
exports.CASE_SPLIT_PATTERN = CASE_SPLIT_PATTERN;
|
|
189
190
|
exports.camelCase = camelCase;
|
|
190
191
|
exports.capitalize = capitalize;
|
|
191
192
|
exports.constantCase = constantCase;
|
|
@@ -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 };
|
package/dist/array/flatMap.d.mts
CHANGED
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
* flatMap(arr, (item: number) => [[item, item]], 2);
|
|
19
19
|
* // [1, 1, 2, 2, 3, 3]
|
|
20
20
|
*/
|
|
21
|
-
declare function flatMap<T, U, D extends number>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
21
|
+
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
22
22
|
|
|
23
23
|
export { flatMap };
|
package/dist/array/flatMap.d.ts
CHANGED
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
* flatMap(arr, (item: number) => [[item, item]], 2);
|
|
19
19
|
* // [1, 1, 2, 2, 3, 3]
|
|
20
20
|
*/
|
|
21
|
-
declare function flatMap<T, U, D extends number>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
21
|
+
declare function flatMap<T, U, D extends number = 1>(arr: readonly T[], iteratee: (item: T) => U, depth?: D): Array<FlatArray<U[], D>>;
|
|
22
22
|
|
|
23
23
|
export { flatMap };
|
|
@@ -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 };
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* by the custom equality function. It effectively filters out any elements from the first array that
|
|
7
7
|
* do not have corresponding matches in the second array according to the equality function.
|
|
8
8
|
*
|
|
9
|
-
* @template T - The type of elements in the array.
|
|
9
|
+
* @template T - The type of elements in the first array.
|
|
10
|
+
* @template U - The type of elements in the second array.
|
|
10
11
|
* @param {T[]} firstArr - The first array to compare.
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {(x: T, y:
|
|
12
|
+
* @param {U[]} secondArr - The second array to compare.
|
|
13
|
+
* @param {(x: T, y: U) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
13
14
|
* This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
14
15
|
* @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
|
|
15
16
|
*
|
|
@@ -19,7 +20,18 @@
|
|
|
19
20
|
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
20
21
|
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
21
22
|
* // result will be [{ id: 2 }] since this element has a matching id in both arrays.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const array1 = [
|
|
26
|
+
* { id: 1, name: 'jane' },
|
|
27
|
+
* { id: 2, name: 'amy' },
|
|
28
|
+
* { id: 3, name: 'michael' },
|
|
29
|
+
* ];
|
|
30
|
+
* const array2 = [2, 4];
|
|
31
|
+
* const areItemsEqual = (a, b) => a.id === b;
|
|
32
|
+
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
33
|
+
* // result will be [{ id: 2, name: 'amy' }] since this element has a matching id that is equal to seconds array's element.
|
|
22
34
|
*/
|
|
23
|
-
declare function intersectionWith<T>(firstArr: readonly T[], secondArr: readonly
|
|
35
|
+
declare function intersectionWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
|
|
24
36
|
|
|
25
37
|
export { intersectionWith };
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* by the custom equality function. It effectively filters out any elements from the first array that
|
|
7
7
|
* do not have corresponding matches in the second array according to the equality function.
|
|
8
8
|
*
|
|
9
|
-
* @template T - The type of elements in the array.
|
|
9
|
+
* @template T - The type of elements in the first array.
|
|
10
|
+
* @template U - The type of elements in the second array.
|
|
10
11
|
* @param {T[]} firstArr - The first array to compare.
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {(x: T, y:
|
|
12
|
+
* @param {U[]} secondArr - The second array to compare.
|
|
13
|
+
* @param {(x: T, y: U) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
13
14
|
* This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
14
15
|
* @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
|
|
15
16
|
*
|
|
@@ -19,7 +20,18 @@
|
|
|
19
20
|
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
20
21
|
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
21
22
|
* // result will be [{ id: 2 }] since this element has a matching id in both arrays.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const array1 = [
|
|
26
|
+
* { id: 1, name: 'jane' },
|
|
27
|
+
* { id: 2, name: 'amy' },
|
|
28
|
+
* { id: 3, name: 'michael' },
|
|
29
|
+
* ];
|
|
30
|
+
* const array2 = [2, 4];
|
|
31
|
+
* const areItemsEqual = (a, b) => a.id === b;
|
|
32
|
+
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
33
|
+
* // result will be [{ id: 2, name: 'amy' }] since this element has a matching id that is equal to seconds array's element.
|
|
22
34
|
*/
|
|
23
|
-
declare function intersectionWith<T>(firstArr: readonly T[], secondArr: readonly
|
|
35
|
+
declare function intersectionWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
|
|
24
36
|
|
|
25
37
|
export { intersectionWith };
|