es-toolkit 1.22.0-dev.712 → 1.22.0-dev.714
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/_chunk/{flowRight-DD5Qyk.js → flowRight-Dv8J0U.js} +0 -3
- package/dist/_chunk/{isWeakSet-CsTXLi.js → isWeakSet-BAMm2l.js} +25 -11
- package/dist/_chunk/noop-2IwLUk.js +5 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +6 -4
- package/dist/compat/index.mjs +1 -0
- package/dist/function/index.js +3 -2
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -3
- package/dist/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/isEqual.mjs +3 -171
- package/dist/predicate/isEqualWith.d.mts +38 -0
- package/dist/predicate/isEqualWith.d.ts +38 -0
- package/dist/predicate/isEqualWith.mjs +184 -0
- package/package.json +3 -3
package/dist/compat/index.d.mts
CHANGED
|
@@ -72,6 +72,7 @@ export { toMerged } from '../object/toMerged.mjs';
|
|
|
72
72
|
export { isArrayBuffer } from '../predicate/isArrayBuffer.mjs';
|
|
73
73
|
export { isDate } from '../predicate/isDate.mjs';
|
|
74
74
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
75
|
+
export { isEqualWith } from '../predicate/isEqualWith.mjs';
|
|
75
76
|
export { isMap } from '../predicate/isMap.mjs';
|
|
76
77
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
77
78
|
export { isNull } from '../predicate/isNull.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export { toMerged } from '../object/toMerged.js';
|
|
|
72
72
|
export { isArrayBuffer } from '../predicate/isArrayBuffer.js';
|
|
73
73
|
export { isDate } from '../predicate/isDate.js';
|
|
74
74
|
export { isEqual } from '../predicate/isEqual.js';
|
|
75
|
+
export { isEqualWith } from '../predicate/isEqualWith.js';
|
|
75
76
|
export { isMap } from '../predicate/isMap.js';
|
|
76
77
|
export { isNotNil } from '../predicate/isNotNil.js';
|
|
77
78
|
export { isNull } from '../predicate/isNull.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -4,12 +4,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const zipWith = require('../_chunk/zipWith-EOU_KZ.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
|
-
const flowRight$1 = require('../_chunk/flowRight-
|
|
7
|
+
const flowRight$1 = require('../_chunk/flowRight-Dv8J0U.js');
|
|
8
|
+
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
8
9
|
const range = require('../_chunk/range-BXlMmn.js');
|
|
9
10
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
11
|
const isObjectLike = require('../_chunk/isObjectLike-aywuSF.js');
|
|
11
12
|
const isPlainObject$1 = require('../_chunk/isPlainObject-DgrsU7.js');
|
|
12
|
-
const isWeakSet$1 = require('../_chunk/isWeakSet-
|
|
13
|
+
const isWeakSet$1 = require('../_chunk/isWeakSet-BAMm2l.js');
|
|
13
14
|
const pad$1 = require('../_chunk/pad-BWiShN.js');
|
|
14
15
|
|
|
15
16
|
function castArray(value) {
|
|
@@ -1405,7 +1406,7 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
1405
1406
|
}
|
|
1406
1407
|
|
|
1407
1408
|
function merge(object, ...sources) {
|
|
1408
|
-
return mergeWith(object, ...sources,
|
|
1409
|
+
return mergeWith(object, ...sources, noop.noop);
|
|
1409
1410
|
}
|
|
1410
1411
|
|
|
1411
1412
|
function isArrayLike(value) {
|
|
@@ -1863,11 +1864,11 @@ exports.before = flowRight$1.before;
|
|
|
1863
1864
|
exports.curryRight = flowRight$1.curryRight;
|
|
1864
1865
|
exports.memoize = flowRight$1.memoize;
|
|
1865
1866
|
exports.negate = flowRight$1.negate;
|
|
1866
|
-
exports.noop = flowRight$1.noop;
|
|
1867
1867
|
exports.once = flowRight$1.once;
|
|
1868
1868
|
exports.partial = flowRight$1.partial;
|
|
1869
1869
|
exports.partialRight = flowRight$1.partialRight;
|
|
1870
1870
|
exports.unary = flowRight$1.unary;
|
|
1871
|
+
exports.noop = noop.noop;
|
|
1871
1872
|
exports.mean = range.mean;
|
|
1872
1873
|
exports.meanBy = range.meanBy;
|
|
1873
1874
|
exports.range = range.range;
|
|
@@ -1885,6 +1886,7 @@ exports.isPrimitive = isPlainObject$1.isPrimitive;
|
|
|
1885
1886
|
exports.isArrayBuffer = isWeakSet$1.isArrayBuffer;
|
|
1886
1887
|
exports.isDate = isWeakSet$1.isDate;
|
|
1887
1888
|
exports.isEqual = isWeakSet$1.isEqual;
|
|
1889
|
+
exports.isEqualWith = isWeakSet$1.isEqualWith;
|
|
1888
1890
|
exports.isFunction = isWeakSet$1.isFunction;
|
|
1889
1891
|
exports.isJSONArray = isWeakSet$1.isJSONArray;
|
|
1890
1892
|
exports.isJSONObject = isWeakSet$1.isJSONObject;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -74,6 +74,7 @@ export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
|
74
74
|
export { isArrayBuffer } from '../predicate/isArrayBuffer.mjs';
|
|
75
75
|
export { isDate } from '../predicate/isDate.mjs';
|
|
76
76
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
77
|
+
export { isEqualWith } from '../predicate/isEqualWith.mjs';
|
|
77
78
|
export { isMap } from '../predicate/isMap.mjs';
|
|
78
79
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
79
80
|
export { isNull } from '../predicate/isNull.mjs';
|
package/dist/function/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const flowRight = require('../_chunk/flowRight-
|
|
5
|
+
const flowRight = require('../_chunk/flowRight-Dv8J0U.js');
|
|
6
|
+
const noop = require('../_chunk/noop-2IwLUk.js');
|
|
6
7
|
|
|
7
8
|
function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
|
|
8
9
|
let pendingAt = null;
|
|
@@ -60,12 +61,12 @@ exports.flow = flowRight.flow;
|
|
|
60
61
|
exports.flowRight = flowRight.flowRight;
|
|
61
62
|
exports.memoize = flowRight.memoize;
|
|
62
63
|
exports.negate = flowRight.negate;
|
|
63
|
-
exports.noop = flowRight.noop;
|
|
64
64
|
exports.once = flowRight.once;
|
|
65
65
|
exports.partial = flowRight.partial;
|
|
66
66
|
exports.partialRight = flowRight.partialRight;
|
|
67
67
|
exports.rest = flowRight.rest;
|
|
68
68
|
exports.unary = flowRight.unary;
|
|
69
|
+
exports.noop = noop.noop;
|
|
69
70
|
exports.curry = curry;
|
|
70
71
|
exports.spread = spread;
|
|
71
72
|
exports.throttle = throttle;
|
package/dist/index.d.mts
CHANGED
|
@@ -100,6 +100,7 @@ export { mergeWith } from './object/mergeWith.mjs';
|
|
|
100
100
|
export { isArrayBuffer } from './predicate/isArrayBuffer.mjs';
|
|
101
101
|
export { isDate } from './predicate/isDate.mjs';
|
|
102
102
|
export { isEqual } from './predicate/isEqual.mjs';
|
|
103
|
+
export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
103
104
|
export { isError } from './predicate/isError.mjs';
|
|
104
105
|
export { isMap } from './predicate/isMap.mjs';
|
|
105
106
|
export { isNil } from './predicate/isNil.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ export { mergeWith } from './object/mergeWith.js';
|
|
|
100
100
|
export { isArrayBuffer } from './predicate/isArrayBuffer.js';
|
|
101
101
|
export { isDate } from './predicate/isDate.js';
|
|
102
102
|
export { isEqual } from './predicate/isEqual.js';
|
|
103
|
+
export { isEqualWith } from './predicate/isEqualWith.js';
|
|
103
104
|
export { isError } from './predicate/isError.js';
|
|
104
105
|
export { isMap } from './predicate/isMap.js';
|
|
105
106
|
export { isNil } from './predicate/isNil.js';
|
package/dist/index.js
CHANGED
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
|
-
const flowRight = require('./_chunk/flowRight-
|
|
8
|
+
const flowRight = require('./_chunk/flowRight-Dv8J0U.js');
|
|
9
|
+
const noop = require('./_chunk/noop-2IwLUk.js');
|
|
9
10
|
const function_index = require('./function/index.js');
|
|
10
11
|
const range = require('./_chunk/range-BXlMmn.js');
|
|
11
12
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
12
13
|
const math_index = require('./math/index.js');
|
|
13
14
|
const object_index = require('./object/index.js');
|
|
14
15
|
const isObjectLike = require('./_chunk/isObjectLike-aywuSF.js');
|
|
15
|
-
const isWeakSet = require('./_chunk/isWeakSet-
|
|
16
|
+
const isWeakSet = require('./_chunk/isWeakSet-BAMm2l.js');
|
|
16
17
|
const predicate_index = require('./predicate/index.js');
|
|
17
18
|
const isPlainObject = require('./_chunk/isPlainObject-DgrsU7.js');
|
|
18
19
|
const pad = require('./_chunk/pad-BWiShN.js');
|
|
@@ -90,12 +91,12 @@ exports.flow = flowRight.flow;
|
|
|
90
91
|
exports.flowRight = flowRight.flowRight;
|
|
91
92
|
exports.memoize = flowRight.memoize;
|
|
92
93
|
exports.negate = flowRight.negate;
|
|
93
|
-
exports.noop = flowRight.noop;
|
|
94
94
|
exports.once = flowRight.once;
|
|
95
95
|
exports.partial = flowRight.partial;
|
|
96
96
|
exports.partialRight = flowRight.partialRight;
|
|
97
97
|
exports.rest = flowRight.rest;
|
|
98
98
|
exports.unary = flowRight.unary;
|
|
99
|
+
exports.noop = noop.noop;
|
|
99
100
|
exports.curry = function_index.curry;
|
|
100
101
|
exports.spread = function_index.spread;
|
|
101
102
|
exports.throttle = function_index.throttle;
|
|
@@ -125,6 +126,7 @@ exports.toMerged = isObjectLike.toMerged;
|
|
|
125
126
|
exports.isArrayBuffer = isWeakSet.isArrayBuffer;
|
|
126
127
|
exports.isDate = isWeakSet.isDate;
|
|
127
128
|
exports.isEqual = isWeakSet.isEqual;
|
|
129
|
+
exports.isEqualWith = isWeakSet.isEqualWith;
|
|
128
130
|
exports.isFunction = isWeakSet.isFunction;
|
|
129
131
|
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
130
132
|
exports.isJSONObject = isWeakSet.isJSONObject;
|
package/dist/index.mjs
CHANGED
|
@@ -100,6 +100,7 @@ export { mergeWith } from './object/mergeWith.mjs';
|
|
|
100
100
|
export { isArrayBuffer } from './predicate/isArrayBuffer.mjs';
|
|
101
101
|
export { isDate } from './predicate/isDate.mjs';
|
|
102
102
|
export { isEqual } from './predicate/isEqual.mjs';
|
|
103
|
+
export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
103
104
|
export { isError } from './predicate/isError.mjs';
|
|
104
105
|
export { isMap } from './predicate/isMap.mjs';
|
|
105
106
|
export { isNil } from './predicate/isNil.mjs';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { isArrayBuffer } from './isArrayBuffer.mjs';
|
|
2
2
|
export { isDate } from './isDate.mjs';
|
|
3
3
|
export { isEqual } from './isEqual.mjs';
|
|
4
|
+
export { isEqualWith } from './isEqualWith.mjs';
|
|
4
5
|
export { isError } from './isError.mjs';
|
|
5
6
|
export { isMap } from './isMap.mjs';
|
|
6
7
|
export { isNil } from './isNil.mjs';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { isArrayBuffer } from './isArrayBuffer.js';
|
|
2
2
|
export { isDate } from './isDate.js';
|
|
3
3
|
export { isEqual } from './isEqual.js';
|
|
4
|
+
export { isEqualWith } from './isEqualWith.js';
|
|
4
5
|
export { isError } from './isError.js';
|
|
5
6
|
export { isMap } from './isMap.js';
|
|
6
7
|
export { isNil } from './isNil.js';
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isWeakSet = require('../_chunk/isWeakSet-
|
|
5
|
+
const isWeakSet = require('../_chunk/isWeakSet-BAMm2l.js');
|
|
6
6
|
const isPlainObject = require('../_chunk/isPlainObject-DgrsU7.js');
|
|
7
7
|
|
|
8
8
|
function isError(value) {
|
|
@@ -24,6 +24,7 @@ function isString(value) {
|
|
|
24
24
|
exports.isArrayBuffer = isWeakSet.isArrayBuffer;
|
|
25
25
|
exports.isDate = isWeakSet.isDate;
|
|
26
26
|
exports.isEqual = isWeakSet.isEqual;
|
|
27
|
+
exports.isEqualWith = isWeakSet.isEqualWith;
|
|
27
28
|
exports.isFunction = isWeakSet.isFunction;
|
|
28
29
|
exports.isJSONArray = isWeakSet.isJSONArray;
|
|
29
30
|
exports.isJSONObject = isWeakSet.isJSONObject;
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { isArrayBuffer } from './isArrayBuffer.mjs';
|
|
2
2
|
export { isDate } from './isDate.mjs';
|
|
3
3
|
export { isEqual } from './isEqual.mjs';
|
|
4
|
+
export { isEqualWith } from './isEqualWith.mjs';
|
|
4
5
|
export { isError } from './isError.mjs';
|
|
5
6
|
export { isMap } from './isMap.mjs';
|
|
6
7
|
export { isNil } from './isNil.mjs';
|
|
@@ -1,176 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getTag } from '../compat/_internal/getTag.mjs';
|
|
4
|
-
import { functionTag, regexpTag, symbolTag, dateTag, booleanTag, numberTag, stringTag, objectTag, errorTag, dataViewTag, arrayBufferTag, float64ArrayTag, float32ArrayTag, bigInt64ArrayTag, int32ArrayTag, int16ArrayTag, int8ArrayTag, bigUint64ArrayTag, uint32ArrayTag, uint16ArrayTag, uint8ClampedArrayTag, uint8ArrayTag, arrayTag, setTag, mapTag, argumentsTag } from '../compat/_internal/tags.mjs';
|
|
1
|
+
import { isEqualWith } from './isEqualWith.mjs';
|
|
2
|
+
import { noop } from '../function/noop.mjs';
|
|
5
3
|
|
|
6
4
|
function isEqual(a, b) {
|
|
7
|
-
|
|
8
|
-
switch (typeof a) {
|
|
9
|
-
case 'bigint':
|
|
10
|
-
case 'string':
|
|
11
|
-
case 'boolean':
|
|
12
|
-
case 'symbol':
|
|
13
|
-
case 'undefined': {
|
|
14
|
-
return a === b;
|
|
15
|
-
}
|
|
16
|
-
case 'number': {
|
|
17
|
-
return a === b || Object.is(a, b);
|
|
18
|
-
}
|
|
19
|
-
case 'function': {
|
|
20
|
-
return a === b;
|
|
21
|
-
}
|
|
22
|
-
case 'object': {
|
|
23
|
-
return areObjectsEqual(a, b);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return areObjectsEqual(a, b);
|
|
28
|
-
}
|
|
29
|
-
function areObjectsEqual(a, b, stack) {
|
|
30
|
-
if (Object.is(a, b)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
let aTag = getTag(a);
|
|
34
|
-
let bTag = getTag(b);
|
|
35
|
-
if (aTag === argumentsTag) {
|
|
36
|
-
aTag = objectTag;
|
|
37
|
-
}
|
|
38
|
-
if (bTag === argumentsTag) {
|
|
39
|
-
bTag = objectTag;
|
|
40
|
-
}
|
|
41
|
-
if (aTag !== bTag) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
switch (aTag) {
|
|
45
|
-
case stringTag:
|
|
46
|
-
return a.toString() === b.toString();
|
|
47
|
-
case numberTag: {
|
|
48
|
-
const x = a.valueOf();
|
|
49
|
-
const y = b.valueOf();
|
|
50
|
-
return x === y || (Number.isNaN(x) && Number.isNaN(y));
|
|
51
|
-
}
|
|
52
|
-
case booleanTag:
|
|
53
|
-
case dateTag:
|
|
54
|
-
case symbolTag:
|
|
55
|
-
return Object.is(a.valueOf(), b.valueOf());
|
|
56
|
-
case regexpTag: {
|
|
57
|
-
return a.source === b.source && a.flags === b.flags;
|
|
58
|
-
}
|
|
59
|
-
case functionTag: {
|
|
60
|
-
return a === b;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
stack = stack ?? new Map();
|
|
64
|
-
const aStack = stack.get(a);
|
|
65
|
-
const bStack = stack.get(b);
|
|
66
|
-
if (aStack != null && bStack != null) {
|
|
67
|
-
return aStack === b;
|
|
68
|
-
}
|
|
69
|
-
stack.set(a, b);
|
|
70
|
-
stack.set(b, a);
|
|
71
|
-
try {
|
|
72
|
-
switch (aTag) {
|
|
73
|
-
case mapTag: {
|
|
74
|
-
if (a.size !== b.size) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
for (const [key, value] of a.entries()) {
|
|
78
|
-
if (!b.has(key) || !areObjectsEqual(value, b.get(key), stack)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
case setTag: {
|
|
85
|
-
if (a.size !== b.size) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
const aValues = Array.from(a.values());
|
|
89
|
-
const bValues = Array.from(b.values());
|
|
90
|
-
for (let i = 0; i < aValues.length; i++) {
|
|
91
|
-
const aValue = aValues[i];
|
|
92
|
-
const index = bValues.findIndex(bValue => {
|
|
93
|
-
return areObjectsEqual(aValue, bValue, stack);
|
|
94
|
-
});
|
|
95
|
-
if (index === -1) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
bValues.splice(index, 1);
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
case arrayTag:
|
|
103
|
-
case uint8ArrayTag:
|
|
104
|
-
case uint8ClampedArrayTag:
|
|
105
|
-
case uint16ArrayTag:
|
|
106
|
-
case uint32ArrayTag:
|
|
107
|
-
case bigUint64ArrayTag:
|
|
108
|
-
case int8ArrayTag:
|
|
109
|
-
case int16ArrayTag:
|
|
110
|
-
case int32ArrayTag:
|
|
111
|
-
case bigInt64ArrayTag:
|
|
112
|
-
case float32ArrayTag:
|
|
113
|
-
case float64ArrayTag: {
|
|
114
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
if (a.length !== b.length) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
for (let i = 0; i < a.length; i++) {
|
|
121
|
-
if (!areObjectsEqual(a[i], b[i], stack)) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
case arrayBufferTag: {
|
|
128
|
-
if (a.byteLength !== b.byteLength) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack);
|
|
132
|
-
}
|
|
133
|
-
case dataViewTag: {
|
|
134
|
-
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
return areObjectsEqual(a.buffer, b.buffer, stack);
|
|
138
|
-
}
|
|
139
|
-
case errorTag: {
|
|
140
|
-
return a.name === b.name && a.message === b.message;
|
|
141
|
-
}
|
|
142
|
-
case objectTag: {
|
|
143
|
-
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack) || (isPlainObject(a) && isPlainObject(b));
|
|
144
|
-
if (!areEqualInstances) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
148
|
-
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
149
|
-
if (aKeys.length !== bKeys.length) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
for (let i = 0; i < aKeys.length; i++) {
|
|
153
|
-
const propKey = aKeys[i];
|
|
154
|
-
const aProp = a[propKey];
|
|
155
|
-
if (!Object.hasOwn(b, propKey)) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
const bProp = b[propKey];
|
|
159
|
-
if (!areObjectsEqual(aProp, bProp, stack)) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
default: {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
stack.delete(a);
|
|
172
|
-
stack.delete(b);
|
|
173
|
-
}
|
|
5
|
+
return isEqualWith(a, b, noop);
|
|
174
6
|
}
|
|
175
7
|
|
|
176
8
|
export { isEqual };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values for equality using a custom comparison function.
|
|
3
|
+
*
|
|
4
|
+
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|
5
|
+
*
|
|
6
|
+
* This function also uses the custom equality function to compare values inside objects,
|
|
7
|
+
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|
8
|
+
*
|
|
9
|
+
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|
10
|
+
*
|
|
11
|
+
* The custom comparison function can take up to six parameters:
|
|
12
|
+
* - `x`: The value from the first object `a`.
|
|
13
|
+
* - `y`: The value from the second object `b`.
|
|
14
|
+
* - `property`: The property key used to get `x` and `y`.
|
|
15
|
+
* - `xParent`: The parent of the first value `x`.
|
|
16
|
+
* - `yParent`: The parent of the second value `y`.
|
|
17
|
+
* - `stack`: An internal stack (Map) to handle circular references.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} a - The first value to compare.
|
|
20
|
+
* @param {unknown} b - The second value to compare.
|
|
21
|
+
* @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} areValuesEqual - A function to customize the comparison.
|
|
22
|
+
* If it returns a boolean, that result will be used. If it returns undefined,
|
|
23
|
+
* the default equality comparison will be used.
|
|
24
|
+
* @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const customizer = (a, b) => {
|
|
28
|
+
* if (typeof a === 'string' && typeof b === 'string') {
|
|
29
|
+
* return a.toLowerCase() === b.toLowerCase();
|
|
30
|
+
* }
|
|
31
|
+
* };
|
|
32
|
+
* isEqualWith('Hello', 'hello', customizer); // true
|
|
33
|
+
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|
34
|
+
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|
35
|
+
*/
|
|
36
|
+
declare function isEqualWith(a: any, b: any, areValuesEqual: (x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
|
|
37
|
+
|
|
38
|
+
export { isEqualWith };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values for equality using a custom comparison function.
|
|
3
|
+
*
|
|
4
|
+
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|
5
|
+
*
|
|
6
|
+
* This function also uses the custom equality function to compare values inside objects,
|
|
7
|
+
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|
8
|
+
*
|
|
9
|
+
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|
10
|
+
*
|
|
11
|
+
* The custom comparison function can take up to six parameters:
|
|
12
|
+
* - `x`: The value from the first object `a`.
|
|
13
|
+
* - `y`: The value from the second object `b`.
|
|
14
|
+
* - `property`: The property key used to get `x` and `y`.
|
|
15
|
+
* - `xParent`: The parent of the first value `x`.
|
|
16
|
+
* - `yParent`: The parent of the second value `y`.
|
|
17
|
+
* - `stack`: An internal stack (Map) to handle circular references.
|
|
18
|
+
*
|
|
19
|
+
* @param {unknown} a - The first value to compare.
|
|
20
|
+
* @param {unknown} b - The second value to compare.
|
|
21
|
+
* @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} areValuesEqual - A function to customize the comparison.
|
|
22
|
+
* If it returns a boolean, that result will be used. If it returns undefined,
|
|
23
|
+
* the default equality comparison will be used.
|
|
24
|
+
* @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const customizer = (a, b) => {
|
|
28
|
+
* if (typeof a === 'string' && typeof b === 'string') {
|
|
29
|
+
* return a.toLowerCase() === b.toLowerCase();
|
|
30
|
+
* }
|
|
31
|
+
* };
|
|
32
|
+
* isEqualWith('Hello', 'hello', customizer); // true
|
|
33
|
+
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|
34
|
+
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|
35
|
+
*/
|
|
36
|
+
declare function isEqualWith(a: any, b: any, areValuesEqual: (x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void): boolean;
|
|
37
|
+
|
|
38
|
+
export { isEqualWith };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { isPlainObject } from './isPlainObject.mjs';
|
|
2
|
+
import { getSymbols } from '../compat/_internal/getSymbols.mjs';
|
|
3
|
+
import { getTag } from '../compat/_internal/getTag.mjs';
|
|
4
|
+
import { functionTag, regexpTag, symbolTag, dateTag, booleanTag, numberTag, stringTag, objectTag, errorTag, dataViewTag, arrayBufferTag, float64ArrayTag, float32ArrayTag, bigInt64ArrayTag, int32ArrayTag, int16ArrayTag, int8ArrayTag, bigUint64ArrayTag, uint32ArrayTag, uint16ArrayTag, uint8ClampedArrayTag, uint8ArrayTag, arrayTag, setTag, mapTag, argumentsTag } from '../compat/_internal/tags.mjs';
|
|
5
|
+
|
|
6
|
+
function isEqualWith(a, b, areValuesEqual) {
|
|
7
|
+
return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
|
|
8
|
+
}
|
|
9
|
+
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
|
|
10
|
+
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
|
|
11
|
+
if (result !== undefined) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
if (typeof a === typeof b) {
|
|
15
|
+
switch (typeof a) {
|
|
16
|
+
case 'bigint':
|
|
17
|
+
case 'string':
|
|
18
|
+
case 'boolean':
|
|
19
|
+
case 'symbol':
|
|
20
|
+
case 'undefined': {
|
|
21
|
+
return a === b;
|
|
22
|
+
}
|
|
23
|
+
case 'number': {
|
|
24
|
+
return a === b || Object.is(a, b);
|
|
25
|
+
}
|
|
26
|
+
case 'function': {
|
|
27
|
+
return a === b;
|
|
28
|
+
}
|
|
29
|
+
case 'object': {
|
|
30
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
35
|
+
}
|
|
36
|
+
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
|
37
|
+
if (Object.is(a, b)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
let aTag = getTag(a);
|
|
41
|
+
let bTag = getTag(b);
|
|
42
|
+
if (aTag === argumentsTag) {
|
|
43
|
+
aTag = objectTag;
|
|
44
|
+
}
|
|
45
|
+
if (bTag === argumentsTag) {
|
|
46
|
+
bTag = objectTag;
|
|
47
|
+
}
|
|
48
|
+
if (aTag !== bTag) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
switch (aTag) {
|
|
52
|
+
case stringTag:
|
|
53
|
+
return a.toString() === b.toString();
|
|
54
|
+
case numberTag: {
|
|
55
|
+
const x = a.valueOf();
|
|
56
|
+
const y = b.valueOf();
|
|
57
|
+
return x === y || (Number.isNaN(x) && Number.isNaN(y));
|
|
58
|
+
}
|
|
59
|
+
case booleanTag:
|
|
60
|
+
case dateTag:
|
|
61
|
+
case symbolTag:
|
|
62
|
+
return Object.is(a.valueOf(), b.valueOf());
|
|
63
|
+
case regexpTag: {
|
|
64
|
+
return a.source === b.source && a.flags === b.flags;
|
|
65
|
+
}
|
|
66
|
+
case functionTag: {
|
|
67
|
+
return a === b;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
stack = stack ?? new Map();
|
|
71
|
+
const aStack = stack.get(a);
|
|
72
|
+
const bStack = stack.get(b);
|
|
73
|
+
if (aStack != null && bStack != null) {
|
|
74
|
+
return aStack === b;
|
|
75
|
+
}
|
|
76
|
+
stack.set(a, b);
|
|
77
|
+
stack.set(b, a);
|
|
78
|
+
try {
|
|
79
|
+
switch (aTag) {
|
|
80
|
+
case mapTag: {
|
|
81
|
+
if (a.size !== b.size) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
for (const [key, value] of a.entries()) {
|
|
85
|
+
if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
case setTag: {
|
|
92
|
+
if (a.size !== b.size) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const aValues = Array.from(a.values());
|
|
96
|
+
const bValues = Array.from(b.values());
|
|
97
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
98
|
+
const aValue = aValues[i];
|
|
99
|
+
const index = bValues.findIndex(bValue => {
|
|
100
|
+
return isEqualWithImpl(aValue, bValue, undefined, a, b, stack, areValuesEqual);
|
|
101
|
+
});
|
|
102
|
+
if (index === -1) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
bValues.splice(index, 1);
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
case arrayTag:
|
|
110
|
+
case uint8ArrayTag:
|
|
111
|
+
case uint8ClampedArrayTag:
|
|
112
|
+
case uint16ArrayTag:
|
|
113
|
+
case uint32ArrayTag:
|
|
114
|
+
case bigUint64ArrayTag:
|
|
115
|
+
case int8ArrayTag:
|
|
116
|
+
case int16ArrayTag:
|
|
117
|
+
case int32ArrayTag:
|
|
118
|
+
case bigInt64ArrayTag:
|
|
119
|
+
case float32ArrayTag:
|
|
120
|
+
case float64ArrayTag: {
|
|
121
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (a.length !== b.length) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
for (let i = 0; i < a.length; i++) {
|
|
128
|
+
if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
case arrayBufferTag: {
|
|
135
|
+
if (a.byteLength !== b.byteLength) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
139
|
+
}
|
|
140
|
+
case dataViewTag: {
|
|
141
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
145
|
+
}
|
|
146
|
+
case errorTag: {
|
|
147
|
+
return a.name === b.name && a.message === b.message;
|
|
148
|
+
}
|
|
149
|
+
case objectTag: {
|
|
150
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) ||
|
|
151
|
+
(isPlainObject(a) && isPlainObject(b));
|
|
152
|
+
if (!areEqualInstances) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
156
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
157
|
+
if (aKeys.length !== bKeys.length) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
161
|
+
const propKey = aKeys[i];
|
|
162
|
+
const aProp = a[propKey];
|
|
163
|
+
if (!Object.hasOwn(b, propKey)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const bProp = b[propKey];
|
|
167
|
+
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
default: {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
stack.delete(a);
|
|
180
|
+
stack.delete(b);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { isEqualWith };
|