@naturalcycles/js-lib 14.166.1 → 14.167.0
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.
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deepEquals, but after JSON stringify/parse
|
|
3
|
+
* E.g if object A has extra properties with value `undefined` -
|
|
4
|
+
* it won't be _deepEquals true, but will be _deepJsonEquals true.
|
|
5
|
+
* (because JSON.stringify removes undefined properties).
|
|
6
|
+
*/
|
|
7
|
+
export declare function _deepJsonEquals(a: any, b: any): boolean;
|
|
1
8
|
/**
|
|
2
9
|
* Based on: https://github.com/epoberezkin/fast-deep-equal/
|
|
3
10
|
*/
|
|
@@ -1,45 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._deepEquals = void 0;
|
|
3
|
+
exports._deepEquals = exports._deepJsonEquals = void 0;
|
|
4
4
|
const isArray = Array.isArray;
|
|
5
5
|
const keyList = Object.keys;
|
|
6
6
|
const hasProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* deepEquals, but after JSON stringify/parse
|
|
9
|
+
* E.g if object A has extra properties with value `undefined` -
|
|
10
|
+
* it won't be _deepEquals true, but will be _deepJsonEquals true.
|
|
11
|
+
* (because JSON.stringify removes undefined properties).
|
|
12
|
+
*/
|
|
13
|
+
function _deepJsonEquals(a, b) {
|
|
14
|
+
if (a === b)
|
|
15
|
+
return true;
|
|
16
|
+
const aj = JSON.stringify(a);
|
|
17
|
+
const bj = JSON.stringify(b);
|
|
18
|
+
if (aj === bj)
|
|
19
|
+
return true;
|
|
20
|
+
return _deepEquals(JSON.parse(aj), JSON.parse(bj));
|
|
21
|
+
}
|
|
22
|
+
exports._deepJsonEquals = _deepJsonEquals;
|
|
8
23
|
/**
|
|
9
24
|
* Based on: https://github.com/epoberezkin/fast-deep-equal/
|
|
10
25
|
*/
|
|
11
26
|
function _deepEquals(a, b) {
|
|
12
27
|
if (a === b)
|
|
13
28
|
return true;
|
|
14
|
-
if (a && b && typeof a
|
|
29
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
15
30
|
const arrA = isArray(a);
|
|
16
31
|
const arrB = isArray(b);
|
|
17
32
|
let i;
|
|
18
33
|
let length;
|
|
19
34
|
let key;
|
|
35
|
+
if (arrA !== arrB)
|
|
36
|
+
return false;
|
|
20
37
|
if (arrA && arrB) {
|
|
21
38
|
length = a.length;
|
|
22
|
-
if (length
|
|
39
|
+
if (length !== b.length)
|
|
23
40
|
return false;
|
|
24
41
|
for (i = length; i-- !== 0;)
|
|
25
42
|
if (!_deepEquals(a[i], b[i]))
|
|
26
43
|
return false;
|
|
27
44
|
return true;
|
|
28
45
|
}
|
|
29
|
-
if (arrA != arrB)
|
|
30
|
-
return false;
|
|
31
46
|
const dateA = a instanceof Date;
|
|
32
47
|
const dateB = b instanceof Date;
|
|
33
|
-
if (dateA
|
|
48
|
+
if (dateA !== dateB)
|
|
34
49
|
return false;
|
|
35
50
|
if (dateA && dateB)
|
|
36
|
-
return a.getTime()
|
|
51
|
+
return a.getTime() === b.getTime();
|
|
37
52
|
const regexpA = a instanceof RegExp;
|
|
38
53
|
const regexpB = b instanceof RegExp;
|
|
39
|
-
if (regexpA
|
|
54
|
+
if (regexpA !== regexpB)
|
|
40
55
|
return false;
|
|
41
56
|
if (regexpA && regexpB)
|
|
42
|
-
return a.toString()
|
|
57
|
+
return a.toString() === b.toString();
|
|
43
58
|
const keys = keyList(a);
|
|
44
59
|
length = keys.length;
|
|
45
60
|
if (length !== keyList(b).length)
|
|
@@ -1,42 +1,56 @@
|
|
|
1
1
|
const isArray = Array.isArray;
|
|
2
2
|
const keyList = Object.keys;
|
|
3
3
|
const hasProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* deepEquals, but after JSON stringify/parse
|
|
6
|
+
* E.g if object A has extra properties with value `undefined` -
|
|
7
|
+
* it won't be _deepEquals true, but will be _deepJsonEquals true.
|
|
8
|
+
* (because JSON.stringify removes undefined properties).
|
|
9
|
+
*/
|
|
10
|
+
export function _deepJsonEquals(a, b) {
|
|
11
|
+
if (a === b)
|
|
12
|
+
return true;
|
|
13
|
+
const aj = JSON.stringify(a);
|
|
14
|
+
const bj = JSON.stringify(b);
|
|
15
|
+
if (aj === bj)
|
|
16
|
+
return true;
|
|
17
|
+
return _deepEquals(JSON.parse(aj), JSON.parse(bj));
|
|
18
|
+
}
|
|
5
19
|
/**
|
|
6
20
|
* Based on: https://github.com/epoberezkin/fast-deep-equal/
|
|
7
21
|
*/
|
|
8
22
|
export function _deepEquals(a, b) {
|
|
9
23
|
if (a === b)
|
|
10
24
|
return true;
|
|
11
|
-
if (a && b && typeof a
|
|
25
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
12
26
|
const arrA = isArray(a);
|
|
13
27
|
const arrB = isArray(b);
|
|
14
28
|
let i;
|
|
15
29
|
let length;
|
|
16
30
|
let key;
|
|
31
|
+
if (arrA !== arrB)
|
|
32
|
+
return false;
|
|
17
33
|
if (arrA && arrB) {
|
|
18
34
|
length = a.length;
|
|
19
|
-
if (length
|
|
35
|
+
if (length !== b.length)
|
|
20
36
|
return false;
|
|
21
37
|
for (i = length; i-- !== 0;)
|
|
22
38
|
if (!_deepEquals(a[i], b[i]))
|
|
23
39
|
return false;
|
|
24
40
|
return true;
|
|
25
41
|
}
|
|
26
|
-
if (arrA != arrB)
|
|
27
|
-
return false;
|
|
28
42
|
const dateA = a instanceof Date;
|
|
29
43
|
const dateB = b instanceof Date;
|
|
30
|
-
if (dateA
|
|
44
|
+
if (dateA !== dateB)
|
|
31
45
|
return false;
|
|
32
46
|
if (dateA && dateB)
|
|
33
|
-
return a.getTime()
|
|
47
|
+
return a.getTime() === b.getTime();
|
|
34
48
|
const regexpA = a instanceof RegExp;
|
|
35
49
|
const regexpB = b instanceof RegExp;
|
|
36
|
-
if (regexpA
|
|
50
|
+
if (regexpA !== regexpB)
|
|
37
51
|
return false;
|
|
38
52
|
if (regexpA && regexpB)
|
|
39
|
-
return a.toString()
|
|
53
|
+
return a.toString() === b.toString();
|
|
40
54
|
const keys = keyList(a);
|
|
41
55
|
length = keys.length;
|
|
42
56
|
if (length !== keyList(b).length)
|
package/package.json
CHANGED
package/src/object/deepEquals.ts
CHANGED
|
@@ -2,7 +2,19 @@ const isArray = Array.isArray
|
|
|
2
2
|
const keyList = Object.keys
|
|
3
3
|
const hasProp = Object.prototype.hasOwnProperty
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* deepEquals, but after JSON stringify/parse
|
|
7
|
+
* E.g if object A has extra properties with value `undefined` -
|
|
8
|
+
* it won't be _deepEquals true, but will be _deepJsonEquals true.
|
|
9
|
+
* (because JSON.stringify removes undefined properties).
|
|
10
|
+
*/
|
|
11
|
+
export function _deepJsonEquals(a: any, b: any): boolean {
|
|
12
|
+
if (a === b) return true
|
|
13
|
+
const aj = JSON.stringify(a)
|
|
14
|
+
const bj = JSON.stringify(b)
|
|
15
|
+
if (aj === bj) return true
|
|
16
|
+
return _deepEquals(JSON.parse(aj), JSON.parse(bj))
|
|
17
|
+
}
|
|
6
18
|
|
|
7
19
|
/**
|
|
8
20
|
* Based on: https://github.com/epoberezkin/fast-deep-equal/
|
|
@@ -10,31 +22,31 @@ const hasProp = Object.prototype.hasOwnProperty
|
|
|
10
22
|
export function _deepEquals(a: any, b: any): boolean {
|
|
11
23
|
if (a === b) return true
|
|
12
24
|
|
|
13
|
-
if (a && b && typeof a
|
|
25
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
14
26
|
const arrA = isArray(a)
|
|
15
27
|
const arrB = isArray(b)
|
|
16
|
-
let i
|
|
17
|
-
let length
|
|
28
|
+
let i: number
|
|
29
|
+
let length: number
|
|
18
30
|
let key: string
|
|
19
31
|
|
|
32
|
+
if (arrA !== arrB) return false
|
|
33
|
+
|
|
20
34
|
if (arrA && arrB) {
|
|
21
35
|
length = a.length
|
|
22
|
-
if (length
|
|
36
|
+
if (length !== b.length) return false
|
|
23
37
|
for (i = length; i-- !== 0; ) if (!_deepEquals(a[i], b[i])) return false
|
|
24
38
|
return true
|
|
25
39
|
}
|
|
26
40
|
|
|
27
|
-
if (arrA != arrB) return false
|
|
28
|
-
|
|
29
41
|
const dateA = a instanceof Date
|
|
30
42
|
const dateB = b instanceof Date
|
|
31
|
-
if (dateA
|
|
32
|
-
if (dateA && dateB) return a.getTime()
|
|
43
|
+
if (dateA !== dateB) return false
|
|
44
|
+
if (dateA && dateB) return a.getTime() === b.getTime()
|
|
33
45
|
|
|
34
46
|
const regexpA = a instanceof RegExp
|
|
35
47
|
const regexpB = b instanceof RegExp
|
|
36
|
-
if (regexpA
|
|
37
|
-
if (regexpA && regexpB) return a.toString()
|
|
48
|
+
if (regexpA !== regexpB) return false
|
|
49
|
+
if (regexpA && regexpB) return a.toString() === b.toString()
|
|
38
50
|
|
|
39
51
|
const keys = keyList(a)
|
|
40
52
|
length = keys.length
|