@augment-vir/assert 31.0.0 → 31.0.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.
Files changed (63) hide show
  1. package/dist/assertions/boolean.d.ts +20 -26
  2. package/dist/assertions/boolean.js +185 -41
  3. package/dist/assertions/boundary.d.ts +40 -256
  4. package/dist/assertions/boundary.js +265 -229
  5. package/dist/assertions/enum.d.ts +12 -13
  6. package/dist/assertions/enum.js +98 -20
  7. package/dist/assertions/equality/entry-equality.d.ts +11 -15
  8. package/dist/assertions/equality/entry-equality.js +210 -43
  9. package/dist/assertions/equality/json-equality.d.ts +11 -15
  10. package/dist/assertions/equality/json-equality.js +144 -43
  11. package/dist/assertions/equality/simple-equality.d.ts +39 -46
  12. package/dist/assertions/equality/simple-equality.js +316 -61
  13. package/dist/assertions/extendable-assertions.d.ts +0 -12
  14. package/dist/assertions/extendable-assertions.js +0 -12
  15. package/dist/assertions/http.d.ts +10 -14
  16. package/dist/assertions/http.js +96 -28
  17. package/dist/assertions/instance.d.ts +10 -18
  18. package/dist/assertions/instance.js +92 -26
  19. package/dist/assertions/keys.d.ts +59 -138
  20. package/dist/assertions/keys.js +279 -162
  21. package/dist/assertions/length.d.ts +30 -212
  22. package/dist/assertions/length.js +117 -175
  23. package/dist/assertions/nullish.d.ts +8 -20
  24. package/dist/assertions/nullish.js +85 -27
  25. package/dist/assertions/numeric.d.ts +67 -81
  26. package/dist/assertions/numeric.js +564 -133
  27. package/dist/assertions/output.d.ts +2 -3
  28. package/dist/assertions/output.js +1 -7
  29. package/dist/assertions/primitive.d.ts +33 -40
  30. package/dist/assertions/primitive.js +232 -66
  31. package/dist/assertions/promise.d.ts +20 -30
  32. package/dist/assertions/promise.js +244 -53
  33. package/dist/assertions/regexp.d.ts +12 -14
  34. package/dist/assertions/regexp.js +84 -21
  35. package/dist/assertions/runtime-type.d.ts +99 -150
  36. package/dist/assertions/runtime-type.js +805 -229
  37. package/dist/assertions/throws.d.ts +24 -25
  38. package/dist/assertions/throws.js +43 -5
  39. package/dist/assertions/uuid.d.ts +11 -16
  40. package/dist/assertions/uuid.js +91 -22
  41. package/dist/assertions/values.d.ts +81 -210
  42. package/dist/assertions/values.js +627 -234
  43. package/dist/augments/guards/assert-wrap.d.ts +7 -4
  44. package/dist/augments/guards/assert-wrap.js +5 -4
  45. package/dist/augments/guards/check-wrap.d.ts +7 -5
  46. package/dist/augments/guards/check-wrap.js +5 -4
  47. package/dist/augments/guards/check.d.ts +5 -5
  48. package/dist/augments/guards/check.js +5 -4
  49. package/dist/augments/guards/wait-until.d.ts +8 -4
  50. package/dist/augments/guards/wait-until.js +7 -8
  51. package/dist/guard-types/guard-group.d.ts +5 -2
  52. package/dist/guard-types/wait-until-function.d.ts +2 -10
  53. package/dist/guard-types/wait-until-function.js +1 -9
  54. package/dist/index.d.ts +1 -0
  55. package/package.json +2 -2
  56. package/dist/guard-types/assert-wrap-function.d.ts +0 -12
  57. package/dist/guard-types/assert-wrap-function.js +0 -14
  58. package/dist/guard-types/check-function.d.ts +0 -14
  59. package/dist/guard-types/check-function.js +0 -22
  60. package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
  61. package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
  62. package/dist/guard-types/guard-override.d.ts +0 -4
  63. package/dist/guard-types/guard-override.js +0 -10
@@ -1,44 +1,155 @@
1
1
  import { stringify } from '@augment-vir/core';
2
2
  import { AssertionError } from '../augments/assertion.error.js';
3
- import { autoGuard, autoGuardSymbol } from '../guard-types/guard-override.js';
4
3
  import { createWaitUntil } from '../guard-types/wait-until-function.js';
5
- function isPromiseLike(actual, failureMessage) {
6
- if (!(actual instanceof Promise) &&
7
- !(actual &&
8
- typeof actual === 'object' &&
9
- 'then' in actual &&
10
- typeof actual.then === 'function')) {
11
- throw new AssertionError(`'${stringify(actual)}' is not a PromiseLike.`, failureMessage);
12
- }
13
- }
14
- function isNotPromiseLike(actual, failureMessage) {
15
- try {
16
- isPromiseLike(actual);
17
- }
18
- catch {
19
- return;
20
- }
21
- throw new AssertionError(`'${stringify(actual)}' is a PromiseLike.`, failureMessage);
22
- }
23
- /**
24
- * Checks if a value is an actual `Promise` object. In reality this is just a simple wrapper for
25
- * `instanceof Promise`, but it makes checking a bit more ergonomic.
26
- */
27
- function isPromise(actual, failureMessage) {
28
- if (!(actual instanceof Promise)) {
29
- throw new AssertionError(`'${stringify(actual)}' is not a Promise.`, failureMessage);
30
- }
31
- }
32
- function isNotPromise(actual, failureMessage) {
33
- if (actual instanceof Promise) {
34
- throw new AssertionError(`'${stringify(actual)}' is a Promise.`, failureMessage);
35
- }
36
- }
37
4
  const assertions = {
38
- isPromiseLike,
39
- isNotPromiseLike,
40
- isPromise,
41
- isNotPromise,
5
+ /**
6
+ * Asserts that a value is a `PromiseLike`.
7
+ *
8
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like a
9
+ * promise. This is also referred to as a "thenable". This enables the use of third-party
10
+ * promise implementations that aren't instances of the built-in `Promise` class.
11
+ *
12
+ * Type guards the value.
13
+ *
14
+ * @example
15
+ *
16
+ * ```ts
17
+ * import {assert} from '@augment-vir/assert';
18
+ *
19
+ * class CustomThenable {
20
+ * constructor(public value: any) {}
21
+ *
22
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
23
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
24
+ * }
25
+ * }
26
+ *
27
+ * assert.isPromiseLike(Promise.resolve(5)); // passes
28
+ * assert.isPromiseLike(new CustomThenable(5)); // passes
29
+ * assert.isPromiseLike(5); // fails
30
+ * ```
31
+ *
32
+ * @throws {@link AssertionError} If the assertion fails.
33
+ * @see
34
+ * - {@link assert.isNotPromiseLike} : the opposite assertion.
35
+ * - {@link assert.isPromise} : the more precise assertion.
36
+ */
37
+ isPromiseLike(actual, failureMessage) {
38
+ if (!(actual instanceof Promise) &&
39
+ !(actual &&
40
+ typeof actual === 'object' &&
41
+ 'then' in actual &&
42
+ typeof actual.then === 'function')) {
43
+ throw new AssertionError(`'${stringify(actual)}' is not a PromiseLike.`, failureMessage);
44
+ }
45
+ },
46
+ /**
47
+ * Asserts that a value is _not_ a `PromiseLike`.
48
+ *
49
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like a
50
+ * promise. This is also referred to as a "thenable". This enables the use of third-party
51
+ * promise implementations that aren't instances of the built-in `Promise` class.
52
+ *
53
+ * Type guards the value.
54
+ *
55
+ * @example
56
+ *
57
+ * ```ts
58
+ * import {assert} from '@augment-vir/assert';
59
+ *
60
+ * class CustomThenable {
61
+ * constructor(public value: any) {}
62
+ *
63
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
64
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
65
+ * }
66
+ * }
67
+ *
68
+ * assert.isNotPromiseLike(Promise.resolve(5)); // fails
69
+ * assert.isNotPromiseLike(new CustomThenable(5)); // fails
70
+ * assert.isNotPromiseLike(5); // passes
71
+ * ```
72
+ *
73
+ * @throws {@link AssertionError} If the assertion fails.
74
+ * @see
75
+ * - {@link assert.isPromiseLike} : the opposite assertion.
76
+ * - {@link assert.isNotPromise} : the more precise assertion.
77
+ */
78
+ isNotPromiseLike(actual, failureMessage) {
79
+ if (actual instanceof Promise ||
80
+ (actual &&
81
+ typeof actual === 'object' &&
82
+ 'then' in actual &&
83
+ typeof actual.then === 'function')) {
84
+ throw new AssertionError(`'${stringify(actual)}' is a PromiseLike.`, failureMessage);
85
+ }
86
+ },
87
+ /**
88
+ * Asserts that a value is a `Promise` instance.
89
+ *
90
+ * Type guards the value.
91
+ *
92
+ * @example
93
+ *
94
+ * ```ts
95
+ * import {assert} from '@augment-vir/assert';
96
+ *
97
+ * class CustomThenable {
98
+ * constructor(public value: any) {}
99
+ *
100
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
101
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
102
+ * }
103
+ * }
104
+ *
105
+ * assert.isPromise(Promise.resolve(5)); // passes
106
+ * assert.isPromise(new CustomThenable(5)); // fails
107
+ * assert.isPromise(5); // fails
108
+ * ```
109
+ *
110
+ * @throws {@link AssertionError} If the assertion fails.
111
+ * @see
112
+ * - {@link assert.isNotPromise} : the opposite assertion.
113
+ * - {@link assert.isPromiseLike} : the more lenient assertion.
114
+ */
115
+ isPromise(actual, failureMessage) {
116
+ if (!(actual instanceof Promise)) {
117
+ throw new AssertionError(`'${stringify(actual)}' is not a Promise.`, failureMessage);
118
+ }
119
+ },
120
+ /**
121
+ * Asserts that a value is a _not_ `Promise` instance.
122
+ *
123
+ * Type guards the value.
124
+ *
125
+ * @example
126
+ *
127
+ * ```ts
128
+ * import {assert} from '@augment-vir/assert';
129
+ *
130
+ * class CustomThenable {
131
+ * constructor(public value: any) {}
132
+ *
133
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
134
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
135
+ * }
136
+ * }
137
+ *
138
+ * assert.isNotPromise(Promise.resolve(5)); // fails
139
+ * assert.isNotPromise(new CustomThenable(5)); // passes
140
+ * assert.isNotPromise(5); // passes
141
+ * ```
142
+ *
143
+ * @throws {@link AssertionError} If the assertion fails.
144
+ * @see
145
+ * - {@link assert.isPromise} : the opposite assertion.
146
+ * - {@link assert.isNotPromiseLike} : the more lenient assertion.
147
+ */
148
+ isNotPromise(actual, failureMessage) {
149
+ if (actual instanceof Promise) {
150
+ throw new AssertionError(`'${stringify(actual)}' is a Promise.`, failureMessage);
151
+ }
152
+ },
42
153
  };
43
154
  export const promiseGuards = {
44
155
  assert: assertions,
@@ -76,7 +187,13 @@ export const promiseGuards = {
76
187
  * - {@link check.isNotPromiseLike} : the opposite check.
77
188
  * - {@link check.isPromise} : the more precise check.
78
189
  */
79
- isPromiseLike: autoGuardSymbol,
190
+ isPromiseLike(actual) {
191
+ return !!(actual instanceof Promise ||
192
+ (actual &&
193
+ typeof actual === 'object' &&
194
+ 'then' in actual &&
195
+ typeof actual.then === 'function'));
196
+ },
80
197
  /**
81
198
  * Checks that a value is _not_ a `PromiseLike`.
82
199
  *
@@ -110,7 +227,13 @@ export const promiseGuards = {
110
227
  * - {@link check.isPromiseLike} : the opposite check.
111
228
  * - {@link check.isNotPromise} : the more precise check.
112
229
  */
113
- isNotPromiseLike: autoGuard(),
230
+ isNotPromiseLike(actual) {
231
+ return !(actual instanceof Promise ||
232
+ (actual &&
233
+ typeof actual === 'object' &&
234
+ 'then' in actual &&
235
+ typeof actual.then === 'function'));
236
+ },
114
237
  /**
115
238
  * Checks that a value is a `Promise` instance.
116
239
  *
@@ -140,7 +263,9 @@ export const promiseGuards = {
140
263
  * - {@link check.isNotPromise} : the opposite check.
141
264
  * - {@link check.isPromiseLike} : the more lenient check.
142
265
  */
143
- isPromise: autoGuardSymbol,
266
+ isPromise(actual) {
267
+ return actual instanceof Promise;
268
+ },
144
269
  /**
145
270
  * Checks that a value is a _not_ `Promise` instance.
146
271
  *
@@ -170,7 +295,9 @@ export const promiseGuards = {
170
295
  * - {@link check.isPromise} : the opposite check.
171
296
  * - {@link check.isNotPromiseLike} : the more lenient check.
172
297
  */
173
- isNotPromise: autoGuard(),
298
+ isNotPromise(actual) {
299
+ return !(actual instanceof Promise);
300
+ },
174
301
  },
175
302
  assertWrap: {
176
303
  /**
@@ -208,7 +335,16 @@ export const promiseGuards = {
208
335
  * - {@link assertWrap.isNotPromiseLike} : the opposite assertion.
209
336
  * - {@link assertWrap.isPromise} : the more precise assertion.
210
337
  */
211
- isPromiseLike: autoGuard(),
338
+ isPromiseLike(actual, failureMessage) {
339
+ if (!(actual instanceof Promise) &&
340
+ !(actual &&
341
+ typeof actual === 'object' &&
342
+ 'then' in actual &&
343
+ typeof actual.then === 'function')) {
344
+ throw new AssertionError(`'${stringify(actual)}' is not a PromiseLike.`, failureMessage);
345
+ }
346
+ return actual;
347
+ },
212
348
  /**
213
349
  * Asserts that a value is _not_ a `PromiseLike`. Returns the value if the assertion passes.
214
350
  *
@@ -244,7 +380,16 @@ export const promiseGuards = {
244
380
  * - {@link assertWrap.isPromiseLike} : the opposite assertion.
245
381
  * - {@link assertWrap.isNotPromise} : the more precise assertion.
246
382
  */
247
- isNotPromiseLike: autoGuard(),
383
+ isNotPromiseLike(actual, failureMessage) {
384
+ if (actual instanceof Promise ||
385
+ (actual &&
386
+ typeof actual === 'object' &&
387
+ 'then' in actual &&
388
+ typeof actual.then === 'function')) {
389
+ throw new AssertionError(`'${stringify(actual)}' is a PromiseLike.`, failureMessage);
390
+ }
391
+ return actual;
392
+ },
248
393
  /**
249
394
  * Asserts that a value is a `Promise` instance. Returns the value if the assertion passes.
250
395
  *
@@ -276,7 +421,12 @@ export const promiseGuards = {
276
421
  * - {@link assertWrap.isNotPromise} : the opposite assertion.
277
422
  * - {@link assertWrap.isPromiseLike} : the more lenient assertion.
278
423
  */
279
- isPromise: autoGuard(),
424
+ isPromise(actual, failureMessage) {
425
+ if (!(actual instanceof Promise)) {
426
+ throw new AssertionError(`'${stringify(actual)}' is not a Promise.`, failureMessage);
427
+ }
428
+ return actual;
429
+ },
280
430
  /**
281
431
  * Asserts that a value is a _not_ `Promise` instance. Returns the value if the assertion
282
432
  * passes.
@@ -309,7 +459,12 @@ export const promiseGuards = {
309
459
  * - {@link assertWrap.isPromise} : the opposite assertion.
310
460
  * - {@link assertWrap.isNotPromiseLike} : the more lenient assertion.
311
461
  */
312
- isNotPromise: autoGuard(),
462
+ isNotPromise(actual, failureMessage) {
463
+ if (actual instanceof Promise) {
464
+ throw new AssertionError(`'${stringify(actual)}' is a Promise.`, failureMessage);
465
+ }
466
+ return actual;
467
+ },
313
468
  },
314
469
  checkWrap: {
315
470
  /**
@@ -346,7 +501,18 @@ export const promiseGuards = {
346
501
  * - {@link checkWrap.isNotPromiseLike} : the opposite check.
347
502
  * - {@link checkWrap.isPromise} : the more precise check.
348
503
  */
349
- isNotPromise: autoGuard(),
504
+ isPromiseLike(actual) {
505
+ if (actual instanceof Promise ||
506
+ (actual &&
507
+ typeof actual === 'object' &&
508
+ 'then' in actual &&
509
+ typeof actual.then === 'function')) {
510
+ return actual;
511
+ }
512
+ else {
513
+ return undefined;
514
+ }
515
+ },
350
516
  /**
351
517
  * Checks that a value is _not_ a `PromiseLike`. Returns the value if the check passes,
352
518
  * otherwise `undefined`.
@@ -381,7 +547,18 @@ export const promiseGuards = {
381
547
  * - {@link checkWrap.isPromiseLike} : the opposite check.
382
548
  * - {@link checkWrap.isNotPromise} : the more precise check.
383
549
  */
384
- isNotPromiseLike: autoGuard(),
550
+ isNotPromiseLike(actual) {
551
+ if (actual instanceof Promise ||
552
+ (actual &&
553
+ typeof actual === 'object' &&
554
+ 'then' in actual &&
555
+ typeof actual.then === 'function')) {
556
+ return undefined;
557
+ }
558
+ else {
559
+ return actual;
560
+ }
561
+ },
385
562
  /**
386
563
  * Checks that a value is a `Promise` instance. Returns the value if the check passes,
387
564
  * otherwise `undefined`.
@@ -412,7 +589,14 @@ export const promiseGuards = {
412
589
  * - {@link checkWrap.isNotPromise} : the opposite check.
413
590
  * - {@link checkWrap.isPromiseLike} : the more lenient check.
414
591
  */
415
- isPromise: autoGuardSymbol,
592
+ isPromise(actual) {
593
+ if (actual instanceof Promise) {
594
+ return actual;
595
+ }
596
+ else {
597
+ return undefined;
598
+ }
599
+ },
416
600
  /**
417
601
  * Checks that a value is a _not_ `Promise` instance. Returns the value if the check passes,
418
602
  * otherwise `undefined`.
@@ -443,7 +627,14 @@ export const promiseGuards = {
443
627
  * - {@link checkWrap.isPromise} : the opposite check.
444
628
  * - {@link checkWrap.isNotPromiseLike} : the more lenient check.
445
629
  */
446
- isPromiseLike: autoGuardSymbol,
630
+ isNotPromise(actual) {
631
+ if (actual instanceof Promise) {
632
+ return undefined;
633
+ }
634
+ else {
635
+ return actual;
636
+ }
637
+ },
447
638
  },
448
639
  waitUntil: {
449
640
  /**
@@ -482,7 +673,7 @@ export const promiseGuards = {
482
673
  * - {@link waitUntil.isNotPromiseLike} : the opposite assertion.
483
674
  * - {@link waitUntil.isPromise} : the more precise assertion.
484
675
  */
485
- isPromiseLike: createWaitUntil(isPromiseLike, true),
676
+ isPromiseLike: createWaitUntil(assertions.isPromiseLike, true),
486
677
  /**
487
678
  * Repeatedly calls a callback until its output is _not_ a `PromiseLike`. Once the callback
488
679
  * output passes, it is returned. If the attempts time out, an error is thrown.
@@ -519,7 +710,7 @@ export const promiseGuards = {
519
710
  * - {@link waitUntil.isPromiseLike} : the opposite assertion.
520
711
  * - {@link waitUntil.isNotPromise} : the more precise assertion.
521
712
  */
522
- isNotPromiseLike: createWaitUntil(isNotPromiseLike, true),
713
+ isNotPromiseLike: createWaitUntil(assertions.isNotPromiseLike, true),
523
714
  /**
524
715
  * Repeatedly calls a callback until its output is a `Promise` instance. Once the callback
525
716
  * output passes, it is returned. If the attempts time out, an error is thrown.
@@ -552,7 +743,7 @@ export const promiseGuards = {
552
743
  * - {@link waitUntil.isNotPromise} : the opposite assertion.
553
744
  * - {@link waitUntil.isPromiseLike} : the more lenient assertion.
554
745
  */
555
- isPromise: createWaitUntil(isPromise, true),
746
+ isPromise: createWaitUntil(assertions.isPromise, true),
556
747
  /**
557
748
  * Repeatedly calls a callback until its output is a _not_ `Promise` instance. Once the
558
749
  * callback output passes, it is returned. If the attempts time out, an error is thrown.
@@ -585,6 +776,6 @@ export const promiseGuards = {
585
776
  * - {@link waitUntil.isPromise} : the opposite assertion.
586
777
  * - {@link waitUntil.isNotPromiseLike} : the more lenient assertion.
587
778
  */
588
- isNotPromise: createWaitUntil(isNotPromise, true),
779
+ isNotPromise: createWaitUntil(assertions.isNotPromise, true),
589
780
  },
590
781
  };
@@ -1,6 +1,5 @@
1
- import { autoGuardSymbol } from '../guard-types/guard-override.js';
2
- declare function matches(actual: string, expected: RegExp, failureMessage?: string | undefined): void;
3
- declare function mismatches(actual: string, expected: RegExp, failureMessage?: string | undefined): void;
1
+ import type { MaybePromise } from '@augment-vir/core';
2
+ import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
4
3
  export declare const regexpGuards: {
5
4
  assert: {
6
5
  /**
@@ -21,7 +20,7 @@ export declare const regexpGuards: {
21
20
  * @see
22
21
  * - {@link assert.mismatches} : the opposite assertion.
23
22
  */
24
- matches: typeof matches;
23
+ matches(this: void, actual: string, expected: RegExp, failureMessage?: string | undefined): void;
25
24
  /**
26
25
  * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
27
26
  * `expected`).
@@ -41,7 +40,7 @@ export declare const regexpGuards: {
41
40
  * @see
42
41
  * - {@link assert.matches} : the opposite assertion.
43
42
  */
44
- mismatches: typeof mismatches;
43
+ mismatches(this: void, actual: string, expected: RegExp, failureMessage?: string | undefined): void;
45
44
  };
46
45
  check: {
47
46
  /**
@@ -61,7 +60,7 @@ export declare const regexpGuards: {
61
60
  * @see
62
61
  * - {@link check.mismatches} : the opposite check.
63
62
  */
64
- matches: typeof autoGuardSymbol;
63
+ matches(this: void, actual: string, expected: RegExp): boolean;
65
64
  /**
66
65
  * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
67
66
  * `expected`).
@@ -80,7 +79,7 @@ export declare const regexpGuards: {
80
79
  * @see
81
80
  * - {@link check.matches} : the opposite check.
82
81
  */
83
- mismatches: typeof autoGuardSymbol;
82
+ mismatches(this: void, actual: string, expected: RegExp): boolean;
84
83
  };
85
84
  assertWrap: {
86
85
  /**
@@ -103,7 +102,7 @@ export declare const regexpGuards: {
103
102
  * @see
104
103
  * - {@link assertWrap.mismatches} : the opposite assertion.
105
104
  */
106
- matches: typeof autoGuardSymbol;
105
+ matches(this: void, actual: string, expected: RegExp, failureMessage?: string | undefined): string;
107
106
  /**
108
107
  * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
109
108
  * `expected`). Returns the string if the assertion passes.
@@ -124,7 +123,7 @@ export declare const regexpGuards: {
124
123
  * @see
125
124
  * - {@link assertWrap.matches} : the opposite assertion.
126
125
  */
127
- mismatches: typeof autoGuardSymbol;
126
+ mismatches(this: void, actual: string, expected: RegExp, failureMessage?: string | undefined): string;
128
127
  };
129
128
  checkWrap: {
130
129
  /**
@@ -146,7 +145,7 @@ export declare const regexpGuards: {
146
145
  * @see
147
146
  * - {@link checkWrap.mismatches} : the opposite check.
148
147
  */
149
- matches: typeof autoGuardSymbol;
148
+ matches(this: void, actual: string, expected: RegExp): string | undefined;
150
149
  /**
151
150
  * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
152
151
  * `expected`). Returns the string if the check passes, otherwise `undefined`.
@@ -166,7 +165,7 @@ export declare const regexpGuards: {
166
165
  * @see
167
166
  * - {@link checkWrap.matches} : the opposite check.
168
167
  */
169
- mismatches: typeof autoGuardSymbol;
168
+ mismatches(this: void, actual: string, expected: RegExp): string | undefined;
170
169
  };
171
170
  waitUntil: {
172
171
  /**
@@ -190,7 +189,7 @@ export declare const regexpGuards: {
190
189
  * @see
191
190
  * - {@link waitUntil.mismatches} : the opposite assertion.
192
191
  */
193
- matches: typeof autoGuardSymbol;
192
+ matches: (this: void, expected: RegExp, callback: () => MaybePromise<string>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<string>;
194
193
  /**
195
194
  * Repeatedly calls a callback until its output is a string that does _not_ match a RegExp
196
195
  * (first input, `expected`). Once the callback output passes, it is returned. If the
@@ -212,7 +211,6 @@ export declare const regexpGuards: {
212
211
  * @see
213
212
  * - {@link waitUntil.matches} : the opposite assertion.
214
213
  */
215
- mismatches: typeof autoGuardSymbol;
214
+ mismatches: (this: void, expected: RegExp, callback: () => MaybePromise<string>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<string>;
216
215
  };
217
216
  };
218
- export {};
@@ -1,18 +1,53 @@
1
1
  import { AssertionError } from '../augments/assertion.error.js';
2
- import { autoGuardSymbol } from '../guard-types/guard-override.js';
3
- function matches(actual, expected, failureMessage) {
4
- if (!expected.test(actual)) {
5
- throw new AssertionError(`'${actual}' does not match ${expected}`, failureMessage);
6
- }
7
- }
8
- function mismatches(actual, expected, failureMessage) {
9
- if (expected.test(actual)) {
10
- throw new AssertionError(`'${actual}' matches ${expected}`, failureMessage);
11
- }
12
- }
2
+ import { createWaitUntil } from '../guard-types/wait-until-function.js';
13
3
  const assertions = {
14
- matches,
15
- mismatches,
4
+ /**
5
+ * Asserts that a string (first input, `actual`) matches a RegExp (second input, `expected`).
6
+ *
7
+ * Performs no type guarding.
8
+ *
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {assert} from '@augment-vir/assert';
13
+ *
14
+ * assert.matches('hi', /^h/); // passes
15
+ * assert.matches('hi', /^g/); // fails
16
+ * ```
17
+ *
18
+ * @throws {@link AssertionError} If the assertion fails.
19
+ * @see
20
+ * - {@link assert.mismatches} : the opposite assertion.
21
+ */
22
+ matches(actual, expected, failureMessage) {
23
+ if (!expected.test(actual)) {
24
+ throw new AssertionError(`'${actual}' does not match ${expected}`, failureMessage);
25
+ }
26
+ },
27
+ /**
28
+ * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
29
+ * `expected`).
30
+ *
31
+ * Performs no type guarding.
32
+ *
33
+ * @example
34
+ *
35
+ * ```ts
36
+ * import {assert} from '@augment-vir/assert';
37
+ *
38
+ * assert.mismatches('hi', /^h/); // fails
39
+ * assert.mismatches('hi', /^g/); // passes
40
+ * ```
41
+ *
42
+ * @throws {@link AssertionError} If the assertion fails.
43
+ * @see
44
+ * - {@link assert.matches} : the opposite assertion.
45
+ */
46
+ mismatches(actual, expected, failureMessage) {
47
+ if (expected.test(actual)) {
48
+ throw new AssertionError(`'${actual}' matches ${expected}`, failureMessage);
49
+ }
50
+ },
16
51
  };
17
52
  export const regexpGuards = {
18
53
  assert: assertions,
@@ -34,7 +69,9 @@ export const regexpGuards = {
34
69
  * @see
35
70
  * - {@link check.mismatches} : the opposite check.
36
71
  */
37
- matches: autoGuardSymbol,
72
+ matches(actual, expected) {
73
+ return !!expected.test(actual);
74
+ },
38
75
  /**
39
76
  * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
40
77
  * `expected`).
@@ -53,7 +90,9 @@ export const regexpGuards = {
53
90
  * @see
54
91
  * - {@link check.matches} : the opposite check.
55
92
  */
56
- mismatches: autoGuardSymbol,
93
+ mismatches(actual, expected) {
94
+ return !expected.test(actual);
95
+ },
57
96
  },
58
97
  assertWrap: {
59
98
  /**
@@ -76,7 +115,12 @@ export const regexpGuards = {
76
115
  * @see
77
116
  * - {@link assertWrap.mismatches} : the opposite assertion.
78
117
  */
79
- matches: autoGuardSymbol,
118
+ matches(actual, expected, failureMessage) {
119
+ if (!expected.test(actual)) {
120
+ throw new AssertionError(`'${actual}' does not match ${expected}`, failureMessage);
121
+ }
122
+ return actual;
123
+ },
80
124
  /**
81
125
  * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
82
126
  * `expected`). Returns the string if the assertion passes.
@@ -97,7 +141,12 @@ export const regexpGuards = {
97
141
  * @see
98
142
  * - {@link assertWrap.matches} : the opposite assertion.
99
143
  */
100
- mismatches: autoGuardSymbol,
144
+ mismatches(actual, expected, failureMessage) {
145
+ if (expected.test(actual)) {
146
+ throw new AssertionError(`'${actual}' matches ${expected}`, failureMessage);
147
+ }
148
+ return actual;
149
+ },
101
150
  },
102
151
  checkWrap: {
103
152
  /**
@@ -119,7 +168,14 @@ export const regexpGuards = {
119
168
  * @see
120
169
  * - {@link checkWrap.mismatches} : the opposite check.
121
170
  */
122
- matches: autoGuardSymbol,
171
+ matches(actual, expected) {
172
+ if (expected.test(actual)) {
173
+ return actual;
174
+ }
175
+ else {
176
+ return undefined;
177
+ }
178
+ },
123
179
  /**
124
180
  * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
125
181
  * `expected`). Returns the string if the check passes, otherwise `undefined`.
@@ -139,7 +195,14 @@ export const regexpGuards = {
139
195
  * @see
140
196
  * - {@link checkWrap.matches} : the opposite check.
141
197
  */
142
- mismatches: autoGuardSymbol,
198
+ mismatches(actual, expected) {
199
+ if (expected.test(actual)) {
200
+ return undefined;
201
+ }
202
+ else {
203
+ return actual;
204
+ }
205
+ },
143
206
  },
144
207
  waitUntil: {
145
208
  /**
@@ -163,7 +226,7 @@ export const regexpGuards = {
163
226
  * @see
164
227
  * - {@link waitUntil.mismatches} : the opposite assertion.
165
228
  */
166
- matches: autoGuardSymbol,
229
+ matches: createWaitUntil(assertions.matches, true),
167
230
  /**
168
231
  * Repeatedly calls a callback until its output is a string that does _not_ match a RegExp
169
232
  * (first input, `expected`). Once the callback output passes, it is returned. If the
@@ -185,6 +248,6 @@ export const regexpGuards = {
185
248
  * @see
186
249
  * - {@link waitUntil.matches} : the opposite assertion.
187
250
  */
188
- mismatches: autoGuardSymbol,
251
+ mismatches: createWaitUntil(assertions.mismatches, true),
189
252
  },
190
253
  };