@naturalcycles/js-lib 14.166.0 → 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.
- package/dist/http/fetcher.js +3 -1
- package/dist/object/deepEquals.d.ts +7 -0
- package/dist/object/deepEquals.js +25 -10
- package/dist-esm/http/fetcher.js +3 -2
- package/dist-esm/object/deepEquals.js +23 -9
- package/package.json +1 -1
- package/src/http/fetcher.ts +4 -3
- package/src/object/deepEquals.ts +23 -11
package/dist/http/fetcher.js
CHANGED
|
@@ -524,6 +524,7 @@ class Fetcher {
|
|
|
524
524
|
},
|
|
525
525
|
init: (0, object_util_1._merge)({
|
|
526
526
|
...this.cfg.init,
|
|
527
|
+
headers: { ...this.cfg.init.headers },
|
|
527
528
|
method: opt.method || this.cfg.init.method,
|
|
528
529
|
credentials: opt.credentials || this.cfg.init.credentials,
|
|
529
530
|
redirect: opt.redirect || this.cfg.init.redirect || 'follow',
|
|
@@ -549,6 +550,7 @@ class Fetcher {
|
|
|
549
550
|
req.fullUrl += (req.fullUrl.includes('?') ? '&' : '?') + qs;
|
|
550
551
|
}
|
|
551
552
|
// setup request body
|
|
553
|
+
// Unless it's a well-defined input type (json, text) - content-type is set automatically by the native fetch
|
|
552
554
|
if (opt.json !== undefined) {
|
|
553
555
|
req.init.body = JSON.stringify(opt.json);
|
|
554
556
|
req.init.headers['content-type'] = 'application/json';
|
|
@@ -563,8 +565,8 @@ class Fetcher {
|
|
|
563
565
|
}
|
|
564
566
|
else {
|
|
565
567
|
req.init.body = new URLSearchParams(opt.form);
|
|
568
|
+
req.init.headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
566
569
|
}
|
|
567
|
-
req.init.headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
568
570
|
}
|
|
569
571
|
else if (opt.body !== undefined) {
|
|
570
572
|
req.init.body = opt.body;
|
|
@@ -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)
|
package/dist-esm/http/fetcher.js
CHANGED
|
@@ -500,7 +500,7 @@ export class Fetcher {
|
|
|
500
500
|
'logResponse',
|
|
501
501
|
'logResponseBody',
|
|
502
502
|
'debug',
|
|
503
|
-
])), { started: Date.now() }), _omit(opt, ['method', 'headers', 'credentials'])), { inputUrl: opt.url || '', fullUrl: opt.url || '', retry: Object.assign(Object.assign({}, this.cfg.retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials, redirect: opt.redirect || this.cfg.init.redirect || 'follow' }), {
|
|
503
|
+
])), { started: Date.now() }), _omit(opt, ['method', 'headers', 'credentials'])), { inputUrl: opt.url || '', fullUrl: opt.url || '', retry: Object.assign(Object.assign({}, this.cfg.retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { headers: Object.assign({}, this.cfg.init.headers), method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials, redirect: opt.redirect || this.cfg.init.redirect || 'follow' }), {
|
|
504
504
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
|
505
505
|
}) });
|
|
506
506
|
// setup url
|
|
@@ -518,6 +518,7 @@ export class Fetcher {
|
|
|
518
518
|
req.fullUrl += (req.fullUrl.includes('?') ? '&' : '?') + qs;
|
|
519
519
|
}
|
|
520
520
|
// setup request body
|
|
521
|
+
// Unless it's a well-defined input type (json, text) - content-type is set automatically by the native fetch
|
|
521
522
|
if (opt.json !== undefined) {
|
|
522
523
|
req.init.body = JSON.stringify(opt.json);
|
|
523
524
|
req.init.headers['content-type'] = 'application/json';
|
|
@@ -532,8 +533,8 @@ export class Fetcher {
|
|
|
532
533
|
}
|
|
533
534
|
else {
|
|
534
535
|
req.init.body = new URLSearchParams(opt.form);
|
|
536
|
+
req.init.headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
535
537
|
}
|
|
536
|
-
req.init.headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
537
538
|
}
|
|
538
539
|
else if (opt.body !== undefined) {
|
|
539
540
|
req.init.body = opt.body;
|
|
@@ -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/http/fetcher.ts
CHANGED
|
@@ -637,13 +637,14 @@ export class Fetcher {
|
|
|
637
637
|
init: _merge(
|
|
638
638
|
{
|
|
639
639
|
...this.cfg.init,
|
|
640
|
+
headers: { ...this.cfg.init.headers }, // this avoids mutation
|
|
640
641
|
method: opt.method || this.cfg.init.method,
|
|
641
642
|
credentials: opt.credentials || this.cfg.init.credentials,
|
|
642
643
|
redirect: opt.redirect || this.cfg.init.redirect || 'follow',
|
|
643
644
|
},
|
|
644
645
|
{
|
|
645
646
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
|
646
|
-
}
|
|
647
|
+
} satisfies RequestInit,
|
|
647
648
|
),
|
|
648
649
|
}
|
|
649
650
|
// setup url
|
|
@@ -667,6 +668,7 @@ export class Fetcher {
|
|
|
667
668
|
}
|
|
668
669
|
|
|
669
670
|
// setup request body
|
|
671
|
+
// Unless it's a well-defined input type (json, text) - content-type is set automatically by the native fetch
|
|
670
672
|
if (opt.json !== undefined) {
|
|
671
673
|
req.init.body = JSON.stringify(opt.json)
|
|
672
674
|
req.init.headers['content-type'] = 'application/json'
|
|
@@ -678,9 +680,8 @@ export class Fetcher {
|
|
|
678
680
|
req.init.body = opt.form
|
|
679
681
|
} else {
|
|
680
682
|
req.init.body = new URLSearchParams(opt.form)
|
|
683
|
+
req.init.headers['content-type'] = 'application/x-www-form-urlencoded'
|
|
681
684
|
}
|
|
682
|
-
|
|
683
|
-
req.init.headers['content-type'] = 'application/x-www-form-urlencoded'
|
|
684
685
|
} else if (opt.body !== undefined) {
|
|
685
686
|
req.init.body = opt.body
|
|
686
687
|
}
|
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
|