@naturalcycles/js-lib 14.165.0 → 14.166.1

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.
@@ -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;
package/dist/semver.d.ts CHANGED
@@ -42,3 +42,13 @@ export declare class Semver {
42
42
  * Shortcut for Semver.of(input)
43
43
  */
44
44
  export declare function _semver(input: SemverInput): Semver;
45
+ /**
46
+ * Returns 1 if a > b
47
+ * returns 0 if they are equal
48
+ * returns -1 if a < b
49
+ *
50
+ * Quick&dirty implementation, which should suffice for 95% of the cases.
51
+ *
52
+ * Credit: https://stackoverflow.com/a/47159772/4919972
53
+ */
54
+ export declare function _semverCompare(a: string, b: string): -1 | 0 | 1;
package/dist/semver.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._semver = exports.Semver = void 0;
3
+ exports._semverCompare = exports._semver = exports.Semver = void 0;
4
4
  const range_1 = require("./array/range");
5
5
  const assert_1 = require("./error/assert");
6
6
  /**
@@ -81,3 +81,24 @@ function _semver(input) {
81
81
  return Semver.of(input);
82
82
  }
83
83
  exports._semver = _semver;
84
+ /**
85
+ * Returns 1 if a > b
86
+ * returns 0 if they are equal
87
+ * returns -1 if a < b
88
+ *
89
+ * Quick&dirty implementation, which should suffice for 95% of the cases.
90
+ *
91
+ * Credit: https://stackoverflow.com/a/47159772/4919972
92
+ */
93
+ function _semverCompare(a, b) {
94
+ const t1 = a.split('.');
95
+ const t2 = b.split('.');
96
+ const s1 = (0, range_1._range)(3)
97
+ .map(i => (t1[i] || '').padStart(5))
98
+ .join('');
99
+ const s2 = (0, range_1._range)(3)
100
+ .map(i => (t2[i] || '').padStart(5))
101
+ .join('');
102
+ return s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
103
+ }
104
+ exports._semverCompare = _semverCompare;
@@ -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;
@@ -76,3 +76,23 @@ export class Semver {
76
76
  export function _semver(input) {
77
77
  return Semver.of(input);
78
78
  }
79
+ /**
80
+ * Returns 1 if a > b
81
+ * returns 0 if they are equal
82
+ * returns -1 if a < b
83
+ *
84
+ * Quick&dirty implementation, which should suffice for 95% of the cases.
85
+ *
86
+ * Credit: https://stackoverflow.com/a/47159772/4919972
87
+ */
88
+ export function _semverCompare(a, b) {
89
+ const t1 = a.split('.');
90
+ const t2 = b.split('.');
91
+ const s1 = _range(3)
92
+ .map(i => (t1[i] || '').padStart(5))
93
+ .join('');
94
+ const s2 = _range(3)
95
+ .map(i => (t2[i] || '').padStart(5))
96
+ .join('');
97
+ return s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.165.0",
3
+ "version": "14.166.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -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
- } as RequestInit,
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/semver.ts CHANGED
@@ -85,3 +85,24 @@ export class Semver {
85
85
  export function _semver(input: SemverInput): Semver {
86
86
  return Semver.of(input)
87
87
  }
88
+
89
+ /**
90
+ * Returns 1 if a > b
91
+ * returns 0 if they are equal
92
+ * returns -1 if a < b
93
+ *
94
+ * Quick&dirty implementation, which should suffice for 95% of the cases.
95
+ *
96
+ * Credit: https://stackoverflow.com/a/47159772/4919972
97
+ */
98
+ export function _semverCompare(a: string, b: string): -1 | 0 | 1 {
99
+ const t1 = a.split('.')
100
+ const t2 = b.split('.')
101
+ const s1 = _range(3)
102
+ .map(i => (t1[i] || '').padStart(5))
103
+ .join('')
104
+ const s2 = _range(3)
105
+ .map(i => (t2[i] || '').padStart(5))
106
+ .join('')
107
+ return s1 < s2 ? -1 : s1 > s2 ? 1 : 0
108
+ }