es-toolkit 1.13.1-dev.373 → 1.13.1-dev.375
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/isNil-CYi_Vh.js +7 -0
- package/dist/_chunk/{size-DmGMC-.js → size-BlsJKU.js} +12 -2
- package/dist/array/index.js +3 -4
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/getSymbols.mjs +6 -0
- package/dist/compat/_internal/tags.mjs +28 -0
- package/dist/compat/index.js +5 -5
- package/dist/compat/object/mapKeys.d.mts +2 -2
- package/dist/compat/object/mapKeys.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/object/mapKeys.d.mts +1 -1
- package/dist/object/mapKeys.d.ts +1 -1
- package/dist/predicate/index.js +202 -27
- package/dist/predicate/isEqual.d.mts +1 -1
- package/dist/predicate/isEqual.d.ts +1 -1
- package/dist/predicate/isEqual.mjs +165 -19
- package/package.json +1 -1
- package/dist/_chunk/isNil-IuJ4cv.js +0 -17
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const regexpTag = '[object RegExp]';
|
|
2
|
+
const stringTag = '[object String]';
|
|
3
|
+
const numberTag = '[object Number]';
|
|
4
|
+
const booleanTag = '[object Boolean]';
|
|
5
|
+
const argumentsTag = '[object Arguments]';
|
|
6
|
+
const symbolTag = '[object Symbol]';
|
|
7
|
+
const dateTag = '[object Date]';
|
|
8
|
+
const mapTag = '[object Map]';
|
|
9
|
+
const setTag = '[object Set]';
|
|
10
|
+
const arrayTag = '[object Array]';
|
|
11
|
+
const functionTag = '[object Function]';
|
|
12
|
+
const arrayBufferTag = '[object ArrayBuffer]';
|
|
13
|
+
const objectTag = '[object Object]';
|
|
14
|
+
const errorTag = '[object Error]';
|
|
15
|
+
const dataViewTag = '[object DataView]';
|
|
16
|
+
const uint8ArrayTag = '[object Uint8Array]';
|
|
17
|
+
const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
|
|
18
|
+
const uint16ArrayTag = '[object Uint16Array]';
|
|
19
|
+
const uint32ArrayTag = '[object Uint32Array]';
|
|
20
|
+
const bigUint64ArrayTag = '[object BigUint64Array]';
|
|
21
|
+
const int8ArrayTag = '[object Int8Array]';
|
|
22
|
+
const int16ArrayTag = '[object Int16Array]';
|
|
23
|
+
const int32ArrayTag = '[object Int32Array]';
|
|
24
|
+
const bigInt64ArrayTag = '[object BigInt64Array]';
|
|
25
|
+
const float32ArrayTag = '[object Float32Array]';
|
|
26
|
+
const float64ArrayTag = '[object Float64Array]';
|
|
27
|
+
|
|
28
|
+
export { argumentsTag, arrayBufferTag, arrayTag, bigInt64ArrayTag, bigUint64ArrayTag, booleanTag, dataViewTag, dateTag, errorTag, float32ArrayTag, float64ArrayTag, functionTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag };
|
package/dist/compat/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const size = require('../_chunk/size-
|
|
6
|
-
const isNil = require('../_chunk/isNil-IuJ4cv.js');
|
|
5
|
+
const size = require('../_chunk/size-BlsJKU.js');
|
|
7
6
|
const promise_index = require('../_chunk/index-CwRt_M.js');
|
|
8
7
|
const function_index = require('../function/index.js');
|
|
9
8
|
const math_index = require('../math/index.js');
|
|
10
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
11
10
|
const object_index = require('../object/index.js');
|
|
12
11
|
const predicate_index = require('../predicate/index.js');
|
|
12
|
+
const isNil = require('../_chunk/isNil-CYi_Vh.js');
|
|
13
13
|
const isTypedArray$1 = require('../_chunk/isTypedArray-BBEkFl.js');
|
|
14
14
|
const string_index = require('../string/index.js');
|
|
15
15
|
|
|
@@ -440,8 +440,10 @@ exports.takeRight = size.takeRight;
|
|
|
440
440
|
exports.takeRightWhile = size.takeRightWhile;
|
|
441
441
|
exports.takeWhile = size.takeWhile;
|
|
442
442
|
exports.toFilled = size.toFilled;
|
|
443
|
+
exports.union = size.union;
|
|
443
444
|
exports.unionBy = size.unionBy;
|
|
444
445
|
exports.unionWith = size.unionWith;
|
|
446
|
+
exports.uniq = size.uniq;
|
|
445
447
|
exports.uniqBy = size.uniqBy;
|
|
446
448
|
exports.uniqWith = size.uniqWith;
|
|
447
449
|
exports.unzip = size.unzip;
|
|
@@ -453,9 +455,6 @@ exports.xorWith = size.xorWith;
|
|
|
453
455
|
exports.zip = size.zip;
|
|
454
456
|
exports.zipObject = size.zipObject;
|
|
455
457
|
exports.zipWith = size.zipWith;
|
|
456
|
-
exports.isNil = isNil.isNil;
|
|
457
|
-
exports.union = isNil.union;
|
|
458
|
-
exports.uniq = isNil.uniq;
|
|
459
458
|
exports.AbortError = promise_index.AbortError;
|
|
460
459
|
exports.TimeoutError = promise_index.TimeoutError;
|
|
461
460
|
exports.delay = promise_index.delay;
|
|
@@ -498,6 +497,7 @@ exports.isNotNil = predicate_index.isNotNil;
|
|
|
498
497
|
exports.isNull = predicate_index.isNull;
|
|
499
498
|
exports.isObjectLike = predicate_index.isObjectLike;
|
|
500
499
|
exports.isUndefined = predicate_index.isUndefined;
|
|
500
|
+
exports.isNil = isNil.isNil;
|
|
501
501
|
exports.isPrimitive = isTypedArray$1.isPrimitive;
|
|
502
502
|
exports.camelCase = string_index.camelCase;
|
|
503
503
|
exports.capitalize = string_index.capitalize;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
16
16
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
17
17
|
*/
|
|
18
|
-
declare function mapKeys<T extends
|
|
18
|
+
declare function mapKeys<T extends object>(object: T, getNewKey?: PropertyKey | readonly PropertyKey[]): Record<PropertyKey, T[keyof T]>;
|
|
19
19
|
/**
|
|
20
20
|
* Creates a new object with the same values as the given object, but with keys generated
|
|
21
21
|
* by running each own enumerable property of the object through the iteratee function.
|
|
@@ -34,6 +34,6 @@ declare function mapKeys<T extends {}>(object: T, getNewKey?: PropertyKey | read
|
|
|
34
34
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
35
35
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
36
36
|
*/
|
|
37
|
-
declare function mapKeys<T extends
|
|
37
|
+
declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey?: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
|
|
38
38
|
|
|
39
39
|
export { mapKeys };
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
16
16
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
17
17
|
*/
|
|
18
|
-
declare function mapKeys<T extends
|
|
18
|
+
declare function mapKeys<T extends object>(object: T, getNewKey?: PropertyKey | readonly PropertyKey[]): Record<PropertyKey, T[keyof T]>;
|
|
19
19
|
/**
|
|
20
20
|
* Creates a new object with the same values as the given object, but with keys generated
|
|
21
21
|
* by running each own enumerable property of the object through the iteratee function.
|
|
@@ -34,6 +34,6 @@ declare function mapKeys<T extends {}>(object: T, getNewKey?: PropertyKey | read
|
|
|
34
34
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
35
35
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
36
36
|
*/
|
|
37
|
-
declare function mapKeys<T extends
|
|
37
|
+
declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey?: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
|
|
38
38
|
|
|
39
39
|
export { mapKeys };
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const size = require('./_chunk/size-
|
|
5
|
+
const size = require('./_chunk/size-BlsJKU.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
|
-
const isNil = require('./_chunk/isNil-IuJ4cv.js');
|
|
8
7
|
const promise_index = require('./_chunk/index-CwRt_M.js');
|
|
9
8
|
const function_index = require('./function/index.js');
|
|
10
9
|
const math_index = require('./math/index.js');
|
|
11
10
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
12
11
|
const object_index = require('./object/index.js');
|
|
13
12
|
const predicate_index = require('./predicate/index.js');
|
|
13
|
+
const isNil = require('./_chunk/isNil-CYi_Vh.js');
|
|
14
14
|
const isTypedArray = require('./_chunk/isTypedArray-BBEkFl.js');
|
|
15
15
|
const string_index = require('./string/index.js');
|
|
16
16
|
|
|
@@ -53,8 +53,10 @@ exports.takeRight = size.takeRight;
|
|
|
53
53
|
exports.takeRightWhile = size.takeRightWhile;
|
|
54
54
|
exports.takeWhile = size.takeWhile;
|
|
55
55
|
exports.toFilled = size.toFilled;
|
|
56
|
+
exports.union = size.union;
|
|
56
57
|
exports.unionBy = size.unionBy;
|
|
57
58
|
exports.unionWith = size.unionWith;
|
|
59
|
+
exports.uniq = size.uniq;
|
|
58
60
|
exports.uniqBy = size.uniqBy;
|
|
59
61
|
exports.uniqWith = size.uniqWith;
|
|
60
62
|
exports.unzip = size.unzip;
|
|
@@ -67,9 +69,6 @@ exports.zip = size.zip;
|
|
|
67
69
|
exports.zipObject = size.zipObject;
|
|
68
70
|
exports.zipWith = size.zipWith;
|
|
69
71
|
exports.flattenDeep = array_index.flattenDeep;
|
|
70
|
-
exports.isNil = isNil.isNil;
|
|
71
|
-
exports.union = isNil.union;
|
|
72
|
-
exports.uniq = isNil.uniq;
|
|
73
72
|
exports.AbortError = promise_index.AbortError;
|
|
74
73
|
exports.TimeoutError = promise_index.TimeoutError;
|
|
75
74
|
exports.delay = promise_index.delay;
|
|
@@ -113,6 +112,7 @@ exports.isNotNil = predicate_index.isNotNil;
|
|
|
113
112
|
exports.isNull = predicate_index.isNull;
|
|
114
113
|
exports.isObjectLike = predicate_index.isObjectLike;
|
|
115
114
|
exports.isUndefined = predicate_index.isUndefined;
|
|
115
|
+
exports.isNil = isNil.isNil;
|
|
116
116
|
exports.isPlainObject = isTypedArray.isPlainObject;
|
|
117
117
|
exports.isPrimitive = isTypedArray.isPrimitive;
|
|
118
118
|
exports.isTypedArray = isTypedArray.isTypedArray;
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
17
17
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
18
18
|
*/
|
|
19
|
-
declare function mapKeys<T extends
|
|
19
|
+
declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
|
|
20
20
|
|
|
21
21
|
export { mapKeys };
|
package/dist/object/mapKeys.d.ts
CHANGED
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
* const result = mapKeys(obj, (value, key) => key + value);
|
|
17
17
|
* console.log(result); // { a1: 1, b2: 2 }
|
|
18
18
|
*/
|
|
19
|
-
declare function mapKeys<T extends
|
|
19
|
+
declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
|
|
20
20
|
|
|
21
21
|
export { mapKeys };
|
package/dist/predicate/index.js
CHANGED
|
@@ -2,39 +2,221 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const isNil = require('../_chunk/isNil-IuJ4cv.js');
|
|
6
5
|
const isTypedArray = require('../_chunk/isTypedArray-BBEkFl.js');
|
|
6
|
+
const isNil = require('../_chunk/isNil-CYi_Vh.js');
|
|
7
|
+
|
|
8
|
+
const regexpTag = '[object RegExp]';
|
|
9
|
+
const stringTag = '[object String]';
|
|
10
|
+
const numberTag = '[object Number]';
|
|
11
|
+
const booleanTag = '[object Boolean]';
|
|
12
|
+
const argumentsTag = '[object Arguments]';
|
|
13
|
+
const symbolTag = '[object Symbol]';
|
|
14
|
+
const dateTag = '[object Date]';
|
|
15
|
+
const mapTag = '[object Map]';
|
|
16
|
+
const setTag = '[object Set]';
|
|
17
|
+
const arrayTag = '[object Array]';
|
|
18
|
+
const functionTag = '[object Function]';
|
|
19
|
+
const arrayBufferTag = '[object ArrayBuffer]';
|
|
20
|
+
const objectTag = '[object Object]';
|
|
21
|
+
const errorTag = '[object Error]';
|
|
22
|
+
const dataViewTag = '[object DataView]';
|
|
23
|
+
const uint8ArrayTag = '[object Uint8Array]';
|
|
24
|
+
const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
|
|
25
|
+
const uint16ArrayTag = '[object Uint16Array]';
|
|
26
|
+
const uint32ArrayTag = '[object Uint32Array]';
|
|
27
|
+
const bigUint64ArrayTag = '[object BigUint64Array]';
|
|
28
|
+
const int8ArrayTag = '[object Int8Array]';
|
|
29
|
+
const int16ArrayTag = '[object Int16Array]';
|
|
30
|
+
const int32ArrayTag = '[object Int32Array]';
|
|
31
|
+
const bigInt64ArrayTag = '[object BigInt64Array]';
|
|
32
|
+
const float32ArrayTag = '[object Float32Array]';
|
|
33
|
+
const float64ArrayTag = '[object Float64Array]';
|
|
34
|
+
|
|
35
|
+
function getSymbols(object) {
|
|
36
|
+
return Object.getOwnPropertySymbols(object)
|
|
37
|
+
.filter(symbol => object.propertyIsEnumerable(symbol));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getTag(value) {
|
|
41
|
+
if (value == null) {
|
|
42
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
43
|
+
}
|
|
44
|
+
return Object.prototype.toString.call(value);
|
|
45
|
+
}
|
|
7
46
|
|
|
8
47
|
function isEqual(a, b) {
|
|
48
|
+
if (typeof a === typeof b) {
|
|
49
|
+
switch (typeof a) {
|
|
50
|
+
case 'bigint':
|
|
51
|
+
case 'string':
|
|
52
|
+
case 'boolean':
|
|
53
|
+
case 'symbol':
|
|
54
|
+
case 'undefined': {
|
|
55
|
+
return a === b;
|
|
56
|
+
}
|
|
57
|
+
case 'number': {
|
|
58
|
+
return a === b || Object.is(a, b);
|
|
59
|
+
}
|
|
60
|
+
case 'function': {
|
|
61
|
+
return a === b;
|
|
62
|
+
}
|
|
63
|
+
case 'object': {
|
|
64
|
+
return areObjectsEqual(a, b);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return areObjectsEqual(a, b);
|
|
69
|
+
}
|
|
70
|
+
function areObjectsEqual(a, b, stack) {
|
|
9
71
|
if (Object.is(a, b)) {
|
|
10
72
|
return true;
|
|
11
73
|
}
|
|
12
|
-
|
|
13
|
-
|
|
74
|
+
let aTag = getTag(a);
|
|
75
|
+
let bTag = getTag(b);
|
|
76
|
+
if (aTag === argumentsTag) {
|
|
77
|
+
aTag = objectTag;
|
|
14
78
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
79
|
+
if (bTag === argumentsTag) {
|
|
80
|
+
bTag = objectTag;
|
|
17
81
|
}
|
|
18
|
-
if (
|
|
82
|
+
if (aTag !== bTag) {
|
|
19
83
|
return false;
|
|
20
84
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
85
|
+
switch (aTag) {
|
|
86
|
+
case regexpTag:
|
|
87
|
+
case stringTag:
|
|
88
|
+
return a.toString() === b.toString();
|
|
89
|
+
case numberTag: {
|
|
90
|
+
const x = a.valueOf();
|
|
91
|
+
const y = b.valueOf();
|
|
92
|
+
return x === y || Number.isNaN(x) && Number.isNaN(y);
|
|
93
|
+
}
|
|
94
|
+
case booleanTag:
|
|
95
|
+
case dateTag:
|
|
96
|
+
case symbolTag:
|
|
97
|
+
return Object.is(a.valueOf(), b.valueOf());
|
|
98
|
+
case regexpTag: {
|
|
99
|
+
return a.source === b.source && a.flags === b.flags;
|
|
100
|
+
}
|
|
101
|
+
case functionTag: {
|
|
102
|
+
return a == b;
|
|
103
|
+
}
|
|
25
104
|
}
|
|
26
|
-
|
|
27
|
-
|
|
105
|
+
stack = stack ?? new Map();
|
|
106
|
+
const aStack = stack.get(a);
|
|
107
|
+
const bStack = stack.get(b);
|
|
108
|
+
if (aStack != null && bStack != null) {
|
|
109
|
+
return aStack === b;
|
|
28
110
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
111
|
+
stack.set(a, b);
|
|
112
|
+
stack.set(b, a);
|
|
113
|
+
try {
|
|
114
|
+
switch (aTag) {
|
|
115
|
+
case mapTag: {
|
|
116
|
+
if (a.size !== b.size) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
for (const [key, value] of a.entries()) {
|
|
120
|
+
if (!b.has(key) || !areObjectsEqual(value, b.get(key), stack)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
case setTag: {
|
|
127
|
+
if (a.size !== b.size) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const aValues = Array.from(a.values());
|
|
131
|
+
const bValues = Array.from(b.values());
|
|
132
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
133
|
+
const aValue = aValues[i];
|
|
134
|
+
const index = bValues.findIndex(bValue => {
|
|
135
|
+
return areObjectsEqual(aValue, bValue, stack);
|
|
136
|
+
});
|
|
137
|
+
if (index === -1) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
bValues.splice(index, 1);
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
case arrayTag:
|
|
145
|
+
case uint8ArrayTag:
|
|
146
|
+
case uint8ClampedArrayTag:
|
|
147
|
+
case uint16ArrayTag:
|
|
148
|
+
case uint32ArrayTag:
|
|
149
|
+
case bigUint64ArrayTag:
|
|
150
|
+
case int8ArrayTag:
|
|
151
|
+
case int16ArrayTag:
|
|
152
|
+
case int32ArrayTag:
|
|
153
|
+
case bigInt64ArrayTag:
|
|
154
|
+
case float32ArrayTag:
|
|
155
|
+
case float64ArrayTag: {
|
|
156
|
+
if (Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (a.length !== b.length) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
for (let i = 0; i < a.length; i++) {
|
|
163
|
+
if (!areObjectsEqual(a[i], b[i], stack)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
case arrayBufferTag: {
|
|
170
|
+
if (a.byteLength !== b.byteLength) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack);
|
|
174
|
+
}
|
|
175
|
+
case dataViewTag: {
|
|
176
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return areObjectsEqual(a.buffer, b.buffer, stack);
|
|
180
|
+
}
|
|
181
|
+
case errorTag: {
|
|
182
|
+
return a.name === b.name && a.message === b.message;
|
|
183
|
+
}
|
|
184
|
+
case objectTag: {
|
|
185
|
+
if (a == null || b == null) {
|
|
186
|
+
return a === b;
|
|
187
|
+
}
|
|
188
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack) ||
|
|
189
|
+
(isTypedArray.isPlainObject(a) && isTypedArray.isPlainObject(b));
|
|
190
|
+
if (!areEqualInstances) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
194
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
195
|
+
if (aKeys.length !== bKeys.length) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
199
|
+
const propKey = aKeys[i];
|
|
200
|
+
const aProp = a[propKey];
|
|
201
|
+
if (!b.hasOwnProperty(propKey)) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const bProp = b[propKey];
|
|
205
|
+
if (!areObjectsEqual(aProp, bProp, stack)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
default: {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
35
214
|
}
|
|
36
215
|
}
|
|
37
|
-
|
|
216
|
+
finally {
|
|
217
|
+
stack.delete(a);
|
|
218
|
+
stack.delete(b);
|
|
219
|
+
}
|
|
38
220
|
}
|
|
39
221
|
|
|
40
222
|
function isNotNil(x) {
|
|
@@ -66,21 +248,14 @@ function isObjectLike(value) {
|
|
|
66
248
|
return typeof value === 'object' && value !== null;
|
|
67
249
|
}
|
|
68
250
|
|
|
69
|
-
function getTag(value) {
|
|
70
|
-
if (value == null) {
|
|
71
|
-
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
72
|
-
}
|
|
73
|
-
return Object.prototype.toString.call(value);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
251
|
function isArguments(value) {
|
|
77
252
|
return value !== null && typeof value === 'object' && getTag(value) === '[object Arguments]';
|
|
78
253
|
}
|
|
79
254
|
|
|
80
|
-
exports.isNil = isNil.isNil;
|
|
81
255
|
exports.isPlainObject = isTypedArray.isPlainObject;
|
|
82
256
|
exports.isPrimitive = isTypedArray.isPrimitive;
|
|
83
257
|
exports.isTypedArray = isTypedArray.isTypedArray;
|
|
258
|
+
exports.isNil = isNil.isNil;
|
|
84
259
|
exports.isArguments = isArguments;
|
|
85
260
|
exports.isArrayLike = isArrayLike;
|
|
86
261
|
exports.isEqual = isEqual;
|
|
@@ -1,35 +1,181 @@
|
|
|
1
|
-
import {
|
|
1
|
+
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';
|
|
2
|
+
import { getSymbols } from '../compat/_internal/getSymbols.mjs';
|
|
3
|
+
import { getTag } from '../compat/_internal/getTag.mjs';
|
|
4
|
+
import { isPlainObject } from './isPlainObject.mjs';
|
|
2
5
|
|
|
3
6
|
function isEqual(a, b) {
|
|
7
|
+
if (typeof a === typeof b) {
|
|
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) {
|
|
4
30
|
if (Object.is(a, b)) {
|
|
5
31
|
return true;
|
|
6
32
|
}
|
|
7
|
-
|
|
8
|
-
|
|
33
|
+
let aTag = getTag(a);
|
|
34
|
+
let bTag = getTag(b);
|
|
35
|
+
if (aTag === argumentsTag) {
|
|
36
|
+
aTag = objectTag;
|
|
9
37
|
}
|
|
10
|
-
if (
|
|
11
|
-
|
|
38
|
+
if (bTag === argumentsTag) {
|
|
39
|
+
bTag = objectTag;
|
|
12
40
|
}
|
|
13
|
-
if (
|
|
41
|
+
if (aTag !== bTag) {
|
|
14
42
|
return false;
|
|
15
43
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
44
|
+
switch (aTag) {
|
|
45
|
+
case regexpTag:
|
|
46
|
+
case stringTag:
|
|
47
|
+
return a.toString() === b.toString();
|
|
48
|
+
case numberTag: {
|
|
49
|
+
const x = a.valueOf();
|
|
50
|
+
const y = b.valueOf();
|
|
51
|
+
return x === y || Number.isNaN(x) && Number.isNaN(y);
|
|
52
|
+
}
|
|
53
|
+
case booleanTag:
|
|
54
|
+
case dateTag:
|
|
55
|
+
case symbolTag:
|
|
56
|
+
return Object.is(a.valueOf(), b.valueOf());
|
|
57
|
+
case regexpTag: {
|
|
58
|
+
return a.source === b.source && a.flags === b.flags;
|
|
59
|
+
}
|
|
60
|
+
case functionTag: {
|
|
61
|
+
return a == b;
|
|
62
|
+
}
|
|
20
63
|
}
|
|
21
|
-
|
|
22
|
-
|
|
64
|
+
stack = stack ?? new Map();
|
|
65
|
+
const aStack = stack.get(a);
|
|
66
|
+
const bStack = stack.get(b);
|
|
67
|
+
if (aStack != null && bStack != null) {
|
|
68
|
+
return aStack === b;
|
|
23
69
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
70
|
+
stack.set(a, b);
|
|
71
|
+
stack.set(b, a);
|
|
72
|
+
try {
|
|
73
|
+
switch (aTag) {
|
|
74
|
+
case mapTag: {
|
|
75
|
+
if (a.size !== b.size) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
for (const [key, value] of a.entries()) {
|
|
79
|
+
if (!b.has(key) || !areObjectsEqual(value, b.get(key), stack)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
case setTag: {
|
|
86
|
+
if (a.size !== b.size) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const aValues = Array.from(a.values());
|
|
90
|
+
const bValues = Array.from(b.values());
|
|
91
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
92
|
+
const aValue = aValues[i];
|
|
93
|
+
const index = bValues.findIndex(bValue => {
|
|
94
|
+
return areObjectsEqual(aValue, bValue, stack);
|
|
95
|
+
});
|
|
96
|
+
if (index === -1) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
bValues.splice(index, 1);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
case arrayTag:
|
|
104
|
+
case uint8ArrayTag:
|
|
105
|
+
case uint8ClampedArrayTag:
|
|
106
|
+
case uint16ArrayTag:
|
|
107
|
+
case uint32ArrayTag:
|
|
108
|
+
case bigUint64ArrayTag:
|
|
109
|
+
case int8ArrayTag:
|
|
110
|
+
case int16ArrayTag:
|
|
111
|
+
case int32ArrayTag:
|
|
112
|
+
case bigInt64ArrayTag:
|
|
113
|
+
case float32ArrayTag:
|
|
114
|
+
case float64ArrayTag: {
|
|
115
|
+
if (Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (a.length !== b.length) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
for (let i = 0; i < a.length; i++) {
|
|
122
|
+
if (!areObjectsEqual(a[i], b[i], stack)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
case arrayBufferTag: {
|
|
129
|
+
if (a.byteLength !== b.byteLength) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack);
|
|
133
|
+
}
|
|
134
|
+
case dataViewTag: {
|
|
135
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return areObjectsEqual(a.buffer, b.buffer, stack);
|
|
139
|
+
}
|
|
140
|
+
case errorTag: {
|
|
141
|
+
return a.name === b.name && a.message === b.message;
|
|
142
|
+
}
|
|
143
|
+
case objectTag: {
|
|
144
|
+
if (a == null || b == null) {
|
|
145
|
+
return a === b;
|
|
146
|
+
}
|
|
147
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack) ||
|
|
148
|
+
(isPlainObject(a) && isPlainObject(b));
|
|
149
|
+
if (!areEqualInstances) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
153
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
154
|
+
if (aKeys.length !== bKeys.length) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
158
|
+
const propKey = aKeys[i];
|
|
159
|
+
const aProp = a[propKey];
|
|
160
|
+
if (!b.hasOwnProperty(propKey)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const bProp = b[propKey];
|
|
164
|
+
if (!areObjectsEqual(aProp, bProp, stack)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
default: {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
30
173
|
}
|
|
31
174
|
}
|
|
32
|
-
|
|
175
|
+
finally {
|
|
176
|
+
stack.delete(a);
|
|
177
|
+
stack.delete(b);
|
|
178
|
+
}
|
|
33
179
|
}
|
|
34
180
|
|
|
35
181
|
export { isEqual };
|
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.13.1-dev.
|
|
4
|
+
"version": "1.13.1-dev.375+86001298",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|