@naturalcycles/js-lib 14.246.0 → 14.246.2

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.
@@ -196,19 +196,12 @@ declare class LocalDateFactory {
196
196
  * Performs STRICT parsing.
197
197
  * Only allows IsoDateString input, nothing else.
198
198
  */
199
- fromIsoDateString(s: IsoDateString): LocalDate;
199
+ fromString(s: IsoDateString): LocalDate;
200
200
  /**
201
201
  * Parses "compact iso8601 format", e.g `19840621` into LocalDate.
202
202
  * Throws if it fails to do so.
203
203
  */
204
204
  fromCompactString(s: string): LocalDate;
205
- /**
206
- * Performs LOOSE parsing.
207
- * Tries to coerce imprefect/incorrect string input into IsoDateString.
208
- * Use with caution.
209
- * Allows to input IsoDateTimeString, will drop the Time part of it.
210
- */
211
- parse(s: string): LocalDate;
212
205
  /**
213
206
  * Throws if it fails to parse the input string via Regex and YMD validation.
214
207
  */
@@ -9,11 +9,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
9
9
  /**
10
10
  * Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
11
11
  */
12
- const DATE_REGEX_LOOSE = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
13
- /**
14
- * Strict version.
15
- */
16
- const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
12
+ const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
17
13
  const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/;
18
14
  /**
19
15
  * LocalDate represents a date without time.
@@ -474,7 +470,7 @@ class LocalDateFactory {
474
470
  return this.fromDate(input);
475
471
  }
476
472
  // It means it's a string
477
- return this.fromIsoDateString(input);
473
+ return this.fromString(input);
478
474
  }
479
475
  /**
480
476
  * Returns true if input is valid to create LocalDate.
@@ -492,7 +488,7 @@ class LocalDateFactory {
492
488
  * Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
493
489
  */
494
490
  isValidString(isoString) {
495
- return !!this.parseToLocalDateOrUndefined(DATE_REGEX_STRICT, isoString);
491
+ return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString);
496
492
  }
497
493
  /**
498
494
  * Tries to convert/parse the input into LocalDate.
@@ -509,14 +505,14 @@ class LocalDateFactory {
509
505
  return;
510
506
  return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate());
511
507
  }
512
- return this.parseToLocalDateOrUndefined(DATE_REGEX_LOOSE, input);
508
+ return this.parseToLocalDateOrUndefined(DATE_REGEX, input);
513
509
  }
514
510
  /**
515
511
  * Performs STRICT parsing.
516
512
  * Only allows IsoDateString input, nothing else.
517
513
  */
518
- fromIsoDateString(s) {
519
- return this.parseToLocalDate(DATE_REGEX_STRICT, s);
514
+ fromString(s) {
515
+ return this.parseToLocalDate(DATE_REGEX, s);
520
516
  }
521
517
  /**
522
518
  * Parses "compact iso8601 format", e.g `19840621` into LocalDate.
@@ -525,15 +521,6 @@ class LocalDateFactory {
525
521
  fromCompactString(s) {
526
522
  return this.parseToLocalDate(COMPACT_DATE_REGEX, s);
527
523
  }
528
- /**
529
- * Performs LOOSE parsing.
530
- * Tries to coerce imprefect/incorrect string input into IsoDateString.
531
- * Use with caution.
532
- * Allows to input IsoDateTimeString, will drop the Time part of it.
533
- */
534
- parse(s) {
535
- return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s));
536
- }
537
524
  /**
538
525
  * Throws if it fails to parse the input string via Regex and YMD validation.
539
526
  */
@@ -88,7 +88,7 @@ async function pMap(iterable, mapper, opt = {}) {
88
88
  ret[i] = value;
89
89
  resolvingCount--;
90
90
  next();
91
- }, err => {
91
+ }, (err) => {
92
92
  if (errorMode === __1.ErrorMode.THROW_IMMEDIATELY) {
93
93
  isSettled = true;
94
94
  reject(err);
@@ -66,7 +66,7 @@ class PQueue {
66
66
  if (!resolveOnStart)
67
67
  fn.defer.resolve(result);
68
68
  })
69
- .catch(err => {
69
+ .catch((err) => {
70
70
  this.cfg.logger.error(err);
71
71
  if (resolveOnStart)
72
72
  return;
@@ -1,6 +1,6 @@
1
1
  import type { ErrorData } from '../error/error.model';
2
2
  import { TimeoutError } from '../error/error.util';
3
- import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
3
+ import { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
4
4
  export interface PTimeoutOptions {
5
5
  /**
6
6
  * Timeout in milliseconds.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pTimeoutFn = pTimeoutFn;
4
4
  exports.pTimeout = pTimeout;
5
5
  const error_util_1 = require("../error/error.util");
6
+ const types_1 = require("../types");
6
7
  /**
7
8
  * Decorates a Function with a timeout.
8
9
  * Returns a decorated Function.
@@ -44,6 +45,7 @@ async function pTimeout(fn, opt) {
44
45
  resolve(onTimeout(err));
45
46
  }
46
47
  catch (err) {
48
+ (0, types_1._typeCast)(err);
47
49
  // keep original stack
48
50
  err.stack = fakeError.stack.replace('Error: TimeoutError', err.name + ': ' + err.message);
49
51
  reject((0, error_util_1._errorDataAppend)(err, opt.errorData));
package/dist/semver.d.ts CHANGED
@@ -34,13 +34,13 @@ export declare class Semver {
34
34
  * returns 0 if they are equal
35
35
  * returns -1 if this < other
36
36
  */
37
- cmp(other: SemverInput): -1 | 0 | 1;
37
+ compare(other: SemverInput): -1 | 0 | 1;
38
38
  toJSON: () => string;
39
39
  toString(): string;
40
40
  }
41
41
  declare class SemverFactory {
42
- of(input: SemverInput): Semver;
43
- parseOrNull(input: SemverInputNullable): Semver | null;
42
+ fromInput(input: SemverInput): Semver;
43
+ fromInputOrUndefined(input: SemverInputNullable): Semver | undefined;
44
44
  /**
45
45
  * Returns the highest (max) Semver from the array, or undefined if the array is empty.
46
46
  */
package/dist/semver.js CHANGED
@@ -24,11 +24,11 @@ const is_util_1 = require("./is.util");
24
24
  class Semver {
25
25
  constructor(tokens) {
26
26
  this.tokens = tokens;
27
- this.isAfter = (other) => this.cmp(other) > 0;
28
- this.isSameOrAfter = (other) => this.cmp(other) >= 0;
29
- this.isBefore = (other) => this.cmp(other) < 0;
30
- this.isSameOrBefore = (other) => this.cmp(other) <= 0;
31
- this.isSame = (other) => this.cmp(other) === 0;
27
+ this.isAfter = (other) => this.compare(other) > 0;
28
+ this.isSameOrAfter = (other) => this.compare(other) >= 0;
29
+ this.isBefore = (other) => this.compare(other) < 0;
30
+ this.isSameOrBefore = (other) => this.compare(other) <= 0;
31
+ this.isSame = (other) => this.compare(other) === 0;
32
32
  this.toJSON = () => this.toString();
33
33
  }
34
34
  get major() {
@@ -45,8 +45,8 @@ class Semver {
45
45
  * returns 0 if they are equal
46
46
  * returns -1 if this < other
47
47
  */
48
- cmp(other) {
49
- const { tokens } = exports.semver2.of(other);
48
+ compare(other) {
49
+ const { tokens } = exports.semver2.fromInput(other);
50
50
  for (let i = 0; i < 3; i++) {
51
51
  if (this.tokens[i] < tokens[i])
52
52
  return -1;
@@ -61,16 +61,16 @@ class Semver {
61
61
  }
62
62
  exports.Semver = Semver;
63
63
  class SemverFactory {
64
- of(input) {
65
- const s = this.parseOrNull(input);
66
- (0, assert_1._assert)(s !== null, `Cannot parse "${input}" into Semver`, {
64
+ fromInput(input) {
65
+ const s = this.fromInputOrUndefined(input);
66
+ (0, assert_1._assert)(s, `Cannot parse "${input}" into Semver`, {
67
67
  input,
68
68
  });
69
69
  return s;
70
70
  }
71
- parseOrNull(input) {
71
+ fromInputOrUndefined(input) {
72
72
  if (!input)
73
- return null;
73
+ return;
74
74
  if (input instanceof Semver)
75
75
  return input;
76
76
  const t = input.split('.');
@@ -89,7 +89,9 @@ class SemverFactory {
89
89
  max(items) {
90
90
  const items2 = items.filter(is_util_1._isTruthy);
91
91
  (0, assert_1._assert)(items2.length, 'semver.max called on empty array');
92
- return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item));
92
+ return items2
93
+ .map(i => this.fromInput(i))
94
+ .reduce((max, item) => (max.isSameOrAfter(item) ? max : item));
93
95
  }
94
96
  /**
95
97
  * Returns the lowest (min) Semver from the array, or undefined if the array is empty.
@@ -105,7 +107,7 @@ class SemverFactory {
105
107
  const items2 = items.filter(is_util_1._isTruthy);
106
108
  (0, assert_1._assert)(items2.length, 'semver.min called on empty array');
107
109
  return items2
108
- .map(i => this.of(i))
110
+ .map(i => this.fromInput(i))
109
111
  .reduce((min, item) => (min.isSameOrBefore(item) ? min : item));
110
112
  }
111
113
  /**
@@ -113,11 +115,11 @@ class SemverFactory {
113
115
  */
114
116
  sort(items, dir = 'asc', mutate = false) {
115
117
  const mod = dir === 'desc' ? -1 : 1;
116
- return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod);
118
+ return (mutate ? items : [...items]).sort((a, b) => a.compare(b) * mod);
117
119
  }
118
120
  }
119
121
  const semverFactory = new SemverFactory();
120
- exports.semver2 = semverFactory.of.bind(semverFactory);
122
+ exports.semver2 = semverFactory.fromInput.bind(semverFactory);
121
123
  // The line below is the blackest of black magic I have ever written in 2024.
122
124
  // And probably 2023 as well.
123
125
  Object.setPrototypeOf(exports.semver2, semverFactory);
@@ -20,7 +20,6 @@ class MissingValueError extends Error {
20
20
  super(`Missing a value for ${key ? `the placeholder: ${key}` : 'a placeholder'}`);
21
21
  this.key = key;
22
22
  this.name = 'MissingValueError';
23
- this.key = key;
24
23
  }
25
24
  }
26
25
  exports.MissingValueError = MissingValueError;
@@ -6,11 +6,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
6
6
  /**
7
7
  * Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
8
8
  */
9
- const DATE_REGEX_LOOSE = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
10
- /**
11
- * Strict version.
12
- */
13
- const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
9
+ const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
14
10
  const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/;
15
11
  /**
16
12
  * LocalDate represents a date without time.
@@ -470,7 +466,7 @@ class LocalDateFactory {
470
466
  return this.fromDate(input);
471
467
  }
472
468
  // It means it's a string
473
- return this.fromIsoDateString(input);
469
+ return this.fromString(input);
474
470
  }
475
471
  /**
476
472
  * Returns true if input is valid to create LocalDate.
@@ -488,7 +484,7 @@ class LocalDateFactory {
488
484
  * Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
489
485
  */
490
486
  isValidString(isoString) {
491
- return !!this.parseToLocalDateOrUndefined(DATE_REGEX_STRICT, isoString);
487
+ return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString);
492
488
  }
493
489
  /**
494
490
  * Tries to convert/parse the input into LocalDate.
@@ -505,14 +501,14 @@ class LocalDateFactory {
505
501
  return;
506
502
  return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate());
507
503
  }
508
- return this.parseToLocalDateOrUndefined(DATE_REGEX_LOOSE, input);
504
+ return this.parseToLocalDateOrUndefined(DATE_REGEX, input);
509
505
  }
510
506
  /**
511
507
  * Performs STRICT parsing.
512
508
  * Only allows IsoDateString input, nothing else.
513
509
  */
514
- fromIsoDateString(s) {
515
- return this.parseToLocalDate(DATE_REGEX_STRICT, s);
510
+ fromString(s) {
511
+ return this.parseToLocalDate(DATE_REGEX, s);
516
512
  }
517
513
  /**
518
514
  * Parses "compact iso8601 format", e.g `19840621` into LocalDate.
@@ -521,15 +517,6 @@ class LocalDateFactory {
521
517
  fromCompactString(s) {
522
518
  return this.parseToLocalDate(COMPACT_DATE_REGEX, s);
523
519
  }
524
- /**
525
- * Performs LOOSE parsing.
526
- * Tries to coerce imprefect/incorrect string input into IsoDateString.
527
- * Use with caution.
528
- * Allows to input IsoDateTimeString, will drop the Time part of it.
529
- */
530
- parse(s) {
531
- return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s));
532
- }
533
520
  /**
534
521
  * Throws if it fails to parse the input string via Regex and YMD validation.
535
522
  */
@@ -85,7 +85,7 @@ export async function pMap(iterable, mapper, opt = {}) {
85
85
  ret[i] = value;
86
86
  resolvingCount--;
87
87
  next();
88
- }, err => {
88
+ }, (err) => {
89
89
  if (errorMode === ErrorMode.THROW_IMMEDIATELY) {
90
90
  isSettled = true;
91
91
  reject(err);
@@ -63,7 +63,7 @@ export class PQueue {
63
63
  if (!resolveOnStart)
64
64
  fn.defer.resolve(result);
65
65
  })
66
- .catch(err => {
66
+ .catch((err) => {
67
67
  this.cfg.logger.error(err);
68
68
  if (resolveOnStart)
69
69
  return;
@@ -1,4 +1,5 @@
1
1
  import { _errorDataAppend, TimeoutError } from '../error/error.util';
2
+ import { _typeCast } from '../types';
2
3
  /**
3
4
  * Decorates a Function with a timeout.
4
5
  * Returns a decorated Function.
@@ -40,6 +41,7 @@ export async function pTimeout(fn, opt) {
40
41
  resolve(onTimeout(err));
41
42
  }
42
43
  catch (err) {
44
+ _typeCast(err);
43
45
  // keep original stack
44
46
  err.stack = fakeError.stack.replace('Error: TimeoutError', err.name + ': ' + err.message);
45
47
  reject(_errorDataAppend(err, opt.errorData));
@@ -20,11 +20,11 @@ import { _isTruthy } from './is.util';
20
20
  export class Semver {
21
21
  constructor(tokens) {
22
22
  this.tokens = tokens;
23
- this.isAfter = (other) => this.cmp(other) > 0;
24
- this.isSameOrAfter = (other) => this.cmp(other) >= 0;
25
- this.isBefore = (other) => this.cmp(other) < 0;
26
- this.isSameOrBefore = (other) => this.cmp(other) <= 0;
27
- this.isSame = (other) => this.cmp(other) === 0;
23
+ this.isAfter = (other) => this.compare(other) > 0;
24
+ this.isSameOrAfter = (other) => this.compare(other) >= 0;
25
+ this.isBefore = (other) => this.compare(other) < 0;
26
+ this.isSameOrBefore = (other) => this.compare(other) <= 0;
27
+ this.isSame = (other) => this.compare(other) === 0;
28
28
  this.toJSON = () => this.toString();
29
29
  }
30
30
  get major() {
@@ -41,8 +41,8 @@ export class Semver {
41
41
  * returns 0 if they are equal
42
42
  * returns -1 if this < other
43
43
  */
44
- cmp(other) {
45
- const { tokens } = semver2.of(other);
44
+ compare(other) {
45
+ const { tokens } = semver2.fromInput(other);
46
46
  for (let i = 0; i < 3; i++) {
47
47
  if (this.tokens[i] < tokens[i])
48
48
  return -1;
@@ -56,16 +56,16 @@ export class Semver {
56
56
  }
57
57
  }
58
58
  class SemverFactory {
59
- of(input) {
60
- const s = this.parseOrNull(input);
61
- _assert(s !== null, `Cannot parse "${input}" into Semver`, {
59
+ fromInput(input) {
60
+ const s = this.fromInputOrUndefined(input);
61
+ _assert(s, `Cannot parse "${input}" into Semver`, {
62
62
  input,
63
63
  });
64
64
  return s;
65
65
  }
66
- parseOrNull(input) {
66
+ fromInputOrUndefined(input) {
67
67
  if (!input)
68
- return null;
68
+ return;
69
69
  if (input instanceof Semver)
70
70
  return input;
71
71
  const t = input.split('.');
@@ -84,7 +84,9 @@ class SemverFactory {
84
84
  max(items) {
85
85
  const items2 = items.filter(_isTruthy);
86
86
  _assert(items2.length, 'semver.max called on empty array');
87
- return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item));
87
+ return items2
88
+ .map(i => this.fromInput(i))
89
+ .reduce((max, item) => (max.isSameOrAfter(item) ? max : item));
88
90
  }
89
91
  /**
90
92
  * Returns the lowest (min) Semver from the array, or undefined if the array is empty.
@@ -100,7 +102,7 @@ class SemverFactory {
100
102
  const items2 = items.filter(_isTruthy);
101
103
  _assert(items2.length, 'semver.min called on empty array');
102
104
  return items2
103
- .map(i => this.of(i))
105
+ .map(i => this.fromInput(i))
104
106
  .reduce((min, item) => (min.isSameOrBefore(item) ? min : item));
105
107
  }
106
108
  /**
@@ -108,11 +110,11 @@ class SemverFactory {
108
110
  */
109
111
  sort(items, dir = 'asc', mutate = false) {
110
112
  const mod = dir === 'desc' ? -1 : 1;
111
- return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod);
113
+ return (mutate ? items : [...items]).sort((a, b) => a.compare(b) * mod);
112
114
  }
113
115
  }
114
116
  const semverFactory = new SemverFactory();
115
- export const semver2 = semverFactory.of.bind(semverFactory);
117
+ export const semver2 = semverFactory.fromInput.bind(semverFactory);
116
118
  // The line below is the blackest of black magic I have ever written in 2024.
117
119
  // And probably 2023 as well.
118
120
  Object.setPrototypeOf(semver2, semverFactory);
@@ -16,7 +16,6 @@ export class MissingValueError extends Error {
16
16
  super(`Missing a value for ${key ? `the placeholder: ${key}` : 'a placeholder'}`);
17
17
  this.key = key;
18
18
  this.name = 'MissingValueError';
19
- this.key = key;
20
19
  }
21
20
  }
22
21
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.246.0",
3
+ "version": "14.246.2",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@naturalcycles/bench-lib": "^3.0.0",
20
- "@naturalcycles/dev-lib": "^13.0.1",
20
+ "@naturalcycles/dev-lib": "^14.0.0",
21
21
  "@naturalcycles/nodejs-lib": "^13.0.1",
22
22
  "@naturalcycles/time-lib": "^3.5.1",
23
23
  "@types/crypto-js": "^4.1.1",
@@ -19,11 +19,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
19
19
  /**
20
20
  * Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
21
21
  */
22
- const DATE_REGEX_LOOSE = /^(\d\d\d\d)-(\d\d)-(\d\d)/
23
- /**
24
- * Strict version.
25
- */
26
- const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
22
+ const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/
27
23
  const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/
28
24
 
29
25
  export type LocalDateInput = LocalDate | Date | IsoDateString
@@ -540,7 +536,7 @@ class LocalDateFactory {
540
536
  return this.fromDate(input)
541
537
  }
542
538
  // It means it's a string
543
- return this.fromIsoDateString(input)
539
+ return this.fromString(input)
544
540
  }
545
541
 
546
542
  /**
@@ -557,7 +553,7 @@ class LocalDateFactory {
557
553
  * Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
558
554
  */
559
555
  isValidString(isoString: string | undefined | null): boolean {
560
- return !!this.parseToLocalDateOrUndefined(DATE_REGEX_STRICT, isoString)
556
+ return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString)
561
557
  }
562
558
 
563
559
  /**
@@ -572,15 +568,15 @@ class LocalDateFactory {
572
568
  if (isNaN(input.getDate())) return
573
569
  return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate())
574
570
  }
575
- return this.parseToLocalDateOrUndefined(DATE_REGEX_LOOSE, input)
571
+ return this.parseToLocalDateOrUndefined(DATE_REGEX, input)
576
572
  }
577
573
 
578
574
  /**
579
575
  * Performs STRICT parsing.
580
576
  * Only allows IsoDateString input, nothing else.
581
577
  */
582
- fromIsoDateString(s: IsoDateString): LocalDate {
583
- return this.parseToLocalDate(DATE_REGEX_STRICT, s)
578
+ fromString(s: IsoDateString): LocalDate {
579
+ return this.parseToLocalDate(DATE_REGEX, s)
584
580
  }
585
581
 
586
582
  /**
@@ -591,16 +587,6 @@ class LocalDateFactory {
591
587
  return this.parseToLocalDate(COMPACT_DATE_REGEX, s)
592
588
  }
593
589
 
594
- /**
595
- * Performs LOOSE parsing.
596
- * Tries to coerce imprefect/incorrect string input into IsoDateString.
597
- * Use with caution.
598
- * Allows to input IsoDateTimeString, will drop the Time part of it.
599
- */
600
- parse(s: string): LocalDate {
601
- return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s))
602
- }
603
-
604
590
  /**
605
591
  * Throws if it fails to parse the input string via Regex and YMD validation.
606
592
  */
@@ -127,7 +127,7 @@ export async function pMap<IN, OUT>(
127
127
  resolvingCount--
128
128
  next()
129
129
  },
130
- err => {
130
+ (err: Error) => {
131
131
  if (errorMode === ErrorMode.THROW_IMMEDIATELY) {
132
132
  isSettled = true
133
133
  reject(err)
@@ -124,7 +124,7 @@ export class PQueue {
124
124
  .then(result => {
125
125
  if (!resolveOnStart) fn.defer.resolve(result)
126
126
  })
127
- .catch(err => {
127
+ .catch((err: Error) => {
128
128
  this.cfg.logger.error(err)
129
129
  if (resolveOnStart) return
130
130
 
@@ -1,6 +1,6 @@
1
1
  import type { ErrorData } from '../error/error.model'
2
2
  import { _errorDataAppend, TimeoutError } from '../error/error.util'
3
- import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types'
3
+ import { _typeCast, AnyAsyncFunction, NumberOfMilliseconds } from '../types'
4
4
 
5
5
  export interface PTimeoutOptions {
6
6
  /**
@@ -84,6 +84,7 @@ export async function pTimeout<T>(fn: AnyAsyncFunction<T>, opt: PTimeoutOptions)
84
84
  try {
85
85
  resolve(onTimeout(err))
86
86
  } catch (err: any) {
87
+ _typeCast<Error>(err)
87
88
  // keep original stack
88
89
  err.stack = fakeError.stack!.replace('Error: TimeoutError', err.name + ': ' + err.message)
89
90
  reject(_errorDataAppend(err, opt.errorData))
@@ -98,7 +99,7 @@ export async function pTimeout<T>(fn: AnyAsyncFunction<T>, opt: PTimeoutOptions)
98
99
  try {
99
100
  resolve(await fn())
100
101
  } catch (err) {
101
- reject(err)
102
+ reject(err as Error)
102
103
  } finally {
103
104
  clearTimeout(timer)
104
105
  }
package/src/semver.ts CHANGED
@@ -36,19 +36,19 @@ export class Semver {
36
36
  return this.tokens[2]
37
37
  }
38
38
 
39
- isAfter = (other: SemverInput): boolean => this.cmp(other) > 0
40
- isSameOrAfter = (other: SemverInput): boolean => this.cmp(other) >= 0
41
- isBefore = (other: SemverInput): boolean => this.cmp(other) < 0
42
- isSameOrBefore = (other: SemverInput): boolean => this.cmp(other) <= 0
43
- isSame = (other: SemverInput): boolean => this.cmp(other) === 0
39
+ isAfter = (other: SemverInput): boolean => this.compare(other) > 0
40
+ isSameOrAfter = (other: SemverInput): boolean => this.compare(other) >= 0
41
+ isBefore = (other: SemverInput): boolean => this.compare(other) < 0
42
+ isSameOrBefore = (other: SemverInput): boolean => this.compare(other) <= 0
43
+ isSame = (other: SemverInput): boolean => this.compare(other) === 0
44
44
 
45
45
  /**
46
46
  * Returns 1 if this > other
47
47
  * returns 0 if they are equal
48
48
  * returns -1 if this < other
49
49
  */
50
- cmp(other: SemverInput): -1 | 0 | 1 {
51
- const { tokens } = semver2.of(other)
50
+ compare(other: SemverInput): -1 | 0 | 1 {
51
+ const { tokens } = semver2.fromInput(other)
52
52
  for (let i = 0; i < 3; i++) {
53
53
  if (this.tokens[i]! < tokens[i]!) return -1
54
54
  if (this.tokens[i]! > tokens[i]!) return 1
@@ -64,18 +64,18 @@ export class Semver {
64
64
  }
65
65
 
66
66
  class SemverFactory {
67
- of(input: SemverInput): Semver {
68
- const s = this.parseOrNull(input)
67
+ fromInput(input: SemverInput): Semver {
68
+ const s = this.fromInputOrUndefined(input)
69
69
 
70
- _assert(s !== null, `Cannot parse "${input}" into Semver`, {
70
+ _assert(s, `Cannot parse "${input}" into Semver`, {
71
71
  input,
72
72
  })
73
73
 
74
74
  return s
75
75
  }
76
76
 
77
- parseOrNull(input: SemverInputNullable): Semver | null {
78
- if (!input) return null
77
+ fromInputOrUndefined(input: SemverInputNullable): Semver | undefined {
78
+ if (!input) return
79
79
  if (input instanceof Semver) return input
80
80
 
81
81
  const t = input.split('.')
@@ -96,7 +96,9 @@ class SemverFactory {
96
96
  max(items: SemverInputNullable[]): Semver {
97
97
  const items2 = items.filter(_isTruthy)
98
98
  _assert(items2.length, 'semver.max called on empty array')
99
- return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item))
99
+ return items2
100
+ .map(i => this.fromInput(i))
101
+ .reduce((max, item) => (max.isSameOrAfter(item) ? max : item))
100
102
  }
101
103
 
102
104
  /**
@@ -114,7 +116,7 @@ class SemverFactory {
114
116
  const items2 = items.filter(_isTruthy)
115
117
  _assert(items2.length, 'semver.min called on empty array')
116
118
  return items2
117
- .map(i => this.of(i))
119
+ .map(i => this.fromInput(i))
118
120
  .reduce((min, item) => (min.isSameOrBefore(item) ? min : item))
119
121
  }
120
122
 
@@ -123,7 +125,7 @@ class SemverFactory {
123
125
  */
124
126
  sort(items: Semver[], dir: SortDirection = 'asc', mutate = false): Semver[] {
125
127
  const mod = dir === 'desc' ? -1 : 1
126
- return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod)
128
+ return (mutate ? items : [...items]).sort((a, b) => a.compare(b) * mod)
127
129
  }
128
130
  }
129
131
 
@@ -133,7 +135,7 @@ interface SemverFn extends SemverFactory {
133
135
 
134
136
  const semverFactory = new SemverFactory()
135
137
 
136
- export const semver2 = semverFactory.of.bind(semverFactory) as SemverFn
138
+ export const semver2 = semverFactory.fromInput.bind(semverFactory) as SemverFn
137
139
 
138
140
  // The line below is the blackest of black magic I have ever written in 2024.
139
141
  // And probably 2023 as well.
@@ -18,7 +18,6 @@ export class MissingValueError extends Error {
18
18
  constructor(public key: any) {
19
19
  super(`Missing a value for ${key ? `the placeholder: ${key}` : 'a placeholder'}`)
20
20
  this.name = 'MissingValueError'
21
- this.key = key
22
21
  }
23
22
  }
24
23