@augment-vir/assert 30.0.0 → 30.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 (65) hide show
  1. package/README.md +11 -0
  2. package/dist/assertions/boolean.d.ts +443 -17
  3. package/dist/assertions/boolean.js +365 -8
  4. package/dist/assertions/boundary.d.ts +657 -13
  5. package/dist/assertions/boundary.js +537 -5
  6. package/dist/assertions/enum.d.ts +236 -8
  7. package/dist/assertions/enum.js +197 -5
  8. package/dist/assertions/equality/entry-equality.d.ts +287 -11
  9. package/dist/assertions/equality/entry-equality.js +243 -6
  10. package/dist/assertions/equality/json-equality.d.ts +244 -15
  11. package/dist/assertions/equality/json-equality.js +207 -11
  12. package/dist/assertions/equality/simple-equality.d.ts +849 -28
  13. package/dist/assertions/equality/simple-equality.js +712 -6
  14. package/dist/assertions/equality/ts-type-equality.d.ts +37 -1
  15. package/dist/assertions/equality/ts-type-equality.js +13 -1
  16. package/dist/assertions/extendable-assertions.d.ts +288 -120
  17. package/dist/assertions/extendable-assertions.js +32 -60
  18. package/dist/assertions/http.d.ts +217 -10
  19. package/dist/assertions/http.js +182 -6
  20. package/dist/assertions/instance.d.ts +189 -8
  21. package/dist/assertions/instance.js +159 -5
  22. package/dist/assertions/keys.d.ts +658 -13
  23. package/dist/assertions/keys.js +556 -5
  24. package/dist/assertions/length.d.ts +381 -9
  25. package/dist/assertions/length.js +309 -5
  26. package/dist/assertions/nullish.d.ts +169 -7
  27. package/dist/assertions/nullish.js +137 -6
  28. package/dist/assertions/numeric.d.ts +965 -11
  29. package/dist/assertions/numeric.js +819 -1
  30. package/dist/assertions/output.d.ts +107 -7
  31. package/dist/assertions/output.js +92 -5
  32. package/dist/assertions/primitive.d.ts +416 -13
  33. package/dist/assertions/primitive.js +352 -6
  34. package/dist/assertions/promise.d.ts +640 -21
  35. package/dist/assertions/promise.js +536 -15
  36. package/dist/assertions/regexp.d.ts +202 -3
  37. package/dist/assertions/regexp.js +173 -1
  38. package/dist/assertions/runtime-type.d.ts +1822 -41
  39. package/dist/assertions/runtime-type.js +1558 -35
  40. package/dist/assertions/throws.d.ts +265 -17
  41. package/dist/assertions/throws.js +229 -17
  42. package/dist/assertions/uuid.d.ts +233 -10
  43. package/dist/assertions/uuid.js +195 -6
  44. package/dist/assertions/values.d.ts +1086 -15
  45. package/dist/assertions/values.js +907 -6
  46. package/dist/augments/assertion.error.d.ts +2 -1
  47. package/dist/augments/assertion.error.js +2 -1
  48. package/dist/augments/guards/assert-wrap.d.ts +82 -37
  49. package/dist/augments/guards/assert-wrap.js +13 -2
  50. package/dist/augments/guards/assert.d.ts +30 -14
  51. package/dist/augments/guards/assert.js +21 -4
  52. package/dist/augments/guards/check-wrap.d.ts +94 -51
  53. package/dist/augments/guards/check-wrap.js +11 -3
  54. package/dist/augments/guards/check.d.ts +87 -37
  55. package/dist/augments/guards/check.js +9 -2
  56. package/dist/augments/guards/wait-until.d.ts +110 -103
  57. package/dist/augments/guards/wait-until.js +18 -3
  58. package/dist/augments/if-equals.d.ts +4 -2
  59. package/dist/guard-types/assert-wrap-function.d.ts +5 -2
  60. package/dist/guard-types/check-function.d.ts +5 -2
  61. package/dist/guard-types/check-wrap-wrapper-function.d.ts +4 -1
  62. package/dist/guard-types/guard-group.d.ts +7 -8
  63. package/dist/guard-types/wait-until-function.d.ts +8 -3
  64. package/dist/guard-types/wait-until-function.js +1 -1
  65. package/package.json +17 -4
@@ -1,19 +1,218 @@
1
+ import { autoGuardSymbol } from '../guard-types/guard-override.js';
1
2
  declare function matches(actual: string, expected: RegExp, failureMessage?: string | undefined): void;
2
3
  declare function mismatches(actual: string, expected: RegExp, failureMessage?: string | undefined): void;
3
4
  export declare const regexpGuards: {
4
- assertions: {
5
+ assert: {
5
6
  /**
6
- * Checks if a string (`actual`) matches a RegExp (`expected`).
7
+ * Asserts that a string (first input, `actual`) matches a RegExp (second input, `expected`).
7
8
  *
8
9
  * Performs no type guarding.
10
+ *
11
+ * @example
12
+ *
13
+ * ```ts
14
+ * import {assert} from '@augment-vir/assert';
15
+ *
16
+ * assert.matches('hi', /^h/); // passes
17
+ * assert.matches('hi', /^g/); // fails
18
+ * ```
19
+ *
20
+ * @throws {@link AssertionError} If the assertion fails.
21
+ * @see
22
+ * - {@link assert.mismatches} : the opposite assertion.
9
23
  */
10
24
  matches: typeof matches;
11
25
  /**
12
- * Checks if a string (`actual`) does _not_ match a RegExp (`expected`).
26
+ * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
27
+ * `expected`).
13
28
  *
14
29
  * Performs no type guarding.
30
+ *
31
+ * @example
32
+ *
33
+ * ```ts
34
+ * import {assert} from '@augment-vir/assert';
35
+ *
36
+ * assert.mismatches('hi', /^h/); // fails
37
+ * assert.mismatches('hi', /^g/); // passes
38
+ * ```
39
+ *
40
+ * @throws {@link AssertionError} If the assertion fails.
41
+ * @see
42
+ * - {@link assert.matches} : the opposite assertion.
15
43
  */
16
44
  mismatches: typeof mismatches;
17
45
  };
46
+ check: {
47
+ /**
48
+ * Checks that a string (first input, `actual`) matches a RegExp (second input, `expected`).
49
+ *
50
+ * Performs no type guarding.
51
+ *
52
+ * @example
53
+ *
54
+ * ```ts
55
+ * import {check} from '@augment-vir/assert';
56
+ *
57
+ * check.matches('hi', /^h/); // returns `true`
58
+ * check.matches('hi', /^g/); // returns `false`
59
+ * ```
60
+ *
61
+ * @see
62
+ * - {@link check.mismatches} : the opposite check.
63
+ */
64
+ matches: typeof autoGuardSymbol;
65
+ /**
66
+ * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
67
+ * `expected`).
68
+ *
69
+ * Performs no type guarding.
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * import {check} from '@augment-vir/assert';
75
+ *
76
+ * check.mismatches('hi', /^h/); // returns `false`
77
+ * check.mismatches('hi', /^g/); // returns `true`
78
+ * ```
79
+ *
80
+ * @see
81
+ * - {@link check.matches} : the opposite check.
82
+ */
83
+ mismatches: typeof autoGuardSymbol;
84
+ };
85
+ assertWrap: {
86
+ /**
87
+ * Asserts that a string (first input, `actual`) matches a RegExp (second input,
88
+ * `expected`). Returns the string if the assertion passes.
89
+ *
90
+ * Performs no type guarding.
91
+ *
92
+ * @example
93
+ *
94
+ * ```ts
95
+ * import {assertWrap} from '@augment-vir/assert';
96
+ *
97
+ * assertWrap.matches('hi', /^h/); // returns `'hi'`
98
+ * assertWrap.matches('hi', /^g/); // throws an error
99
+ * ```
100
+ *
101
+ * @returns The value if the assertion passes.
102
+ * @throws {@link AssertionError} If the assertion fails.
103
+ * @see
104
+ * - {@link assertWrap.mismatches} : the opposite assertion.
105
+ */
106
+ matches: typeof autoGuardSymbol;
107
+ /**
108
+ * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
109
+ * `expected`). Returns the string if the assertion passes.
110
+ *
111
+ * Performs no type guarding.
112
+ *
113
+ * @example
114
+ *
115
+ * ```ts
116
+ * import {assertWrap} from '@augment-vir/assert';
117
+ *
118
+ * assertWrap.mismatches('hi', /^h/); // throws an error
119
+ * assertWrap.mismatches('hi', /^g/); // returns `'hi'`
120
+ * ```
121
+ *
122
+ * @returns The value if the assertion passes.
123
+ * @throws {@link AssertionError} If the assertion fails.
124
+ * @see
125
+ * - {@link assertWrap.matches} : the opposite assertion.
126
+ */
127
+ mismatches: typeof autoGuardSymbol;
128
+ };
129
+ checkWrap: {
130
+ /**
131
+ * Checks that a string (first input, `actual`) matches a RegExp (second input, `expected`).
132
+ * Returns the string if the check passes, otherwise `undefined`.
133
+ *
134
+ * Performs no type guarding.
135
+ *
136
+ * @example
137
+ *
138
+ * ```ts
139
+ * import {checkWrap} from '@augment-vir/assert';
140
+ *
141
+ * checkWrap.matches('hi', /^h/); // returns `'hi'`
142
+ * checkWrap.matches('hi', /^g/); // returns `undefined`
143
+ * ```
144
+ *
145
+ * @returns The value if the check passes, otherwise `undefined`.
146
+ * @see
147
+ * - {@link checkWrap.mismatches} : the opposite check.
148
+ */
149
+ matches: typeof autoGuardSymbol;
150
+ /**
151
+ * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
152
+ * `expected`). Returns the string if the check passes, otherwise `undefined`.
153
+ *
154
+ * Performs no type guarding.
155
+ *
156
+ * @example
157
+ *
158
+ * ```ts
159
+ * import {checkWrap} from '@augment-vir/assert';
160
+ *
161
+ * checkWrap.mismatches('hi', /^h/); // returns `undefined`
162
+ * checkWrap.mismatches('hi', /^g/); // returns `'hi'`
163
+ * ```
164
+ *
165
+ * @returns The value if the check passes, otherwise `undefined`.
166
+ * @see
167
+ * - {@link checkWrap.matches} : the opposite check.
168
+ */
169
+ mismatches: typeof autoGuardSymbol;
170
+ };
171
+ waitUntil: {
172
+ /**
173
+ * Repeatedly calls a callback until its output is a string that matches a RegExp (first
174
+ * input, `expected`). Once the callback output passes, it is returned. If the attempts time
175
+ * out, an error is thrown.
176
+ *
177
+ * Performs no type guarding.
178
+ *
179
+ * @example
180
+ *
181
+ * ```ts
182
+ * import {waitUntil} from '@augment-vir/assert';
183
+ *
184
+ * await waitUntil.matches(/^h/, () => 'hi'); // returns `'hi'`
185
+ * await waitUntil.matches(/^g/, () => 'hi'); // throws an error
186
+ * ```
187
+ *
188
+ * @returns The callback output once it passes.
189
+ * @throws {@link AssertionError} If the assertion fails.
190
+ * @see
191
+ * - {@link waitUntil.mismatches} : the opposite assertion.
192
+ */
193
+ matches: typeof autoGuardSymbol;
194
+ /**
195
+ * Repeatedly calls a callback until its output is a string that does _not_ match a RegExp
196
+ * (first input, `expected`). Once the callback output passes, it is returned. If the
197
+ * attempts time out, an error is thrown.
198
+ *
199
+ * Performs no type guarding.
200
+ *
201
+ * @example
202
+ *
203
+ * ```ts
204
+ * import {waitUntil} from '@augment-vir/assert';
205
+ *
206
+ * await waitUntil.mismatches(/^h/, () => 'hi'); // throws an error
207
+ * await waitUntil.mismatches(/^g/, () => 'hi'); // returns `'hi'`
208
+ * ```
209
+ *
210
+ * @returns The callback output once it passes.
211
+ * @throws {@link AssertionError} If the assertion fails.
212
+ * @see
213
+ * - {@link waitUntil.matches} : the opposite assertion.
214
+ */
215
+ mismatches: typeof autoGuardSymbol;
216
+ };
18
217
  };
19
218
  export {};
@@ -1,4 +1,5 @@
1
1
  import { AssertionError } from '../augments/assertion.error.js';
2
+ import { autoGuardSymbol } from '../guard-types/guard-override.js';
2
3
  function matches(actual, expected, failureMessage) {
3
4
  if (!expected.test(actual)) {
4
5
  throw new AssertionError(`'${actual}' does not match ${expected}`, failureMessage);
@@ -14,5 +15,176 @@ const assertions = {
14
15
  mismatches,
15
16
  };
16
17
  export const regexpGuards = {
17
- assertions,
18
+ assert: assertions,
19
+ check: {
20
+ /**
21
+ * Checks that a string (first input, `actual`) matches a RegExp (second input, `expected`).
22
+ *
23
+ * Performs no type guarding.
24
+ *
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * import {check} from '@augment-vir/assert';
29
+ *
30
+ * check.matches('hi', /^h/); // returns `true`
31
+ * check.matches('hi', /^g/); // returns `false`
32
+ * ```
33
+ *
34
+ * @see
35
+ * - {@link check.mismatches} : the opposite check.
36
+ */
37
+ matches: autoGuardSymbol,
38
+ /**
39
+ * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
40
+ * `expected`).
41
+ *
42
+ * Performs no type guarding.
43
+ *
44
+ * @example
45
+ *
46
+ * ```ts
47
+ * import {check} from '@augment-vir/assert';
48
+ *
49
+ * check.mismatches('hi', /^h/); // returns `false`
50
+ * check.mismatches('hi', /^g/); // returns `true`
51
+ * ```
52
+ *
53
+ * @see
54
+ * - {@link check.matches} : the opposite check.
55
+ */
56
+ mismatches: autoGuardSymbol,
57
+ },
58
+ assertWrap: {
59
+ /**
60
+ * Asserts that a string (first input, `actual`) matches a RegExp (second input,
61
+ * `expected`). Returns the string if the assertion passes.
62
+ *
63
+ * Performs no type guarding.
64
+ *
65
+ * @example
66
+ *
67
+ * ```ts
68
+ * import {assertWrap} from '@augment-vir/assert';
69
+ *
70
+ * assertWrap.matches('hi', /^h/); // returns `'hi'`
71
+ * assertWrap.matches('hi', /^g/); // throws an error
72
+ * ```
73
+ *
74
+ * @returns The value if the assertion passes.
75
+ * @throws {@link AssertionError} If the assertion fails.
76
+ * @see
77
+ * - {@link assertWrap.mismatches} : the opposite assertion.
78
+ */
79
+ matches: autoGuardSymbol,
80
+ /**
81
+ * Asserts that a string (first input, `actual`) does _not_ match a RegExp (second input,
82
+ * `expected`). Returns the string if the assertion passes.
83
+ *
84
+ * Performs no type guarding.
85
+ *
86
+ * @example
87
+ *
88
+ * ```ts
89
+ * import {assertWrap} from '@augment-vir/assert';
90
+ *
91
+ * assertWrap.mismatches('hi', /^h/); // throws an error
92
+ * assertWrap.mismatches('hi', /^g/); // returns `'hi'`
93
+ * ```
94
+ *
95
+ * @returns The value if the assertion passes.
96
+ * @throws {@link AssertionError} If the assertion fails.
97
+ * @see
98
+ * - {@link assertWrap.matches} : the opposite assertion.
99
+ */
100
+ mismatches: autoGuardSymbol,
101
+ },
102
+ checkWrap: {
103
+ /**
104
+ * Checks that a string (first input, `actual`) matches a RegExp (second input, `expected`).
105
+ * Returns the string if the check passes, otherwise `undefined`.
106
+ *
107
+ * Performs no type guarding.
108
+ *
109
+ * @example
110
+ *
111
+ * ```ts
112
+ * import {checkWrap} from '@augment-vir/assert';
113
+ *
114
+ * checkWrap.matches('hi', /^h/); // returns `'hi'`
115
+ * checkWrap.matches('hi', /^g/); // returns `undefined`
116
+ * ```
117
+ *
118
+ * @returns The value if the check passes, otherwise `undefined`.
119
+ * @see
120
+ * - {@link checkWrap.mismatches} : the opposite check.
121
+ */
122
+ matches: autoGuardSymbol,
123
+ /**
124
+ * Checks that a string (first input, `actual`) does _not_ match a RegExp (second input,
125
+ * `expected`). Returns the string if the check passes, otherwise `undefined`.
126
+ *
127
+ * Performs no type guarding.
128
+ *
129
+ * @example
130
+ *
131
+ * ```ts
132
+ * import {checkWrap} from '@augment-vir/assert';
133
+ *
134
+ * checkWrap.mismatches('hi', /^h/); // returns `undefined`
135
+ * checkWrap.mismatches('hi', /^g/); // returns `'hi'`
136
+ * ```
137
+ *
138
+ * @returns The value if the check passes, otherwise `undefined`.
139
+ * @see
140
+ * - {@link checkWrap.matches} : the opposite check.
141
+ */
142
+ mismatches: autoGuardSymbol,
143
+ },
144
+ waitUntil: {
145
+ /**
146
+ * Repeatedly calls a callback until its output is a string that matches a RegExp (first
147
+ * input, `expected`). Once the callback output passes, it is returned. If the attempts time
148
+ * out, an error is thrown.
149
+ *
150
+ * Performs no type guarding.
151
+ *
152
+ * @example
153
+ *
154
+ * ```ts
155
+ * import {waitUntil} from '@augment-vir/assert';
156
+ *
157
+ * await waitUntil.matches(/^h/, () => 'hi'); // returns `'hi'`
158
+ * await waitUntil.matches(/^g/, () => 'hi'); // throws an error
159
+ * ```
160
+ *
161
+ * @returns The callback output once it passes.
162
+ * @throws {@link AssertionError} If the assertion fails.
163
+ * @see
164
+ * - {@link waitUntil.mismatches} : the opposite assertion.
165
+ */
166
+ matches: autoGuardSymbol,
167
+ /**
168
+ * Repeatedly calls a callback until its output is a string that does _not_ match a RegExp
169
+ * (first input, `expected`). Once the callback output passes, it is returned. If the
170
+ * attempts time out, an error is thrown.
171
+ *
172
+ * Performs no type guarding.
173
+ *
174
+ * @example
175
+ *
176
+ * ```ts
177
+ * import {waitUntil} from '@augment-vir/assert';
178
+ *
179
+ * await waitUntil.mismatches(/^h/, () => 'hi'); // throws an error
180
+ * await waitUntil.mismatches(/^g/, () => 'hi'); // returns `'hi'`
181
+ * ```
182
+ *
183
+ * @returns The callback output once it passes.
184
+ * @throws {@link AssertionError} If the assertion fails.
185
+ * @see
186
+ * - {@link waitUntil.matches} : the opposite assertion.
187
+ */
188
+ mismatches: autoGuardSymbol,
189
+ },
18
190
  };