@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.
- package/README.md +11 -0
- package/dist/assertions/boolean.d.ts +443 -17
- package/dist/assertions/boolean.js +365 -8
- package/dist/assertions/boundary.d.ts +657 -13
- package/dist/assertions/boundary.js +537 -5
- package/dist/assertions/enum.d.ts +236 -8
- package/dist/assertions/enum.js +197 -5
- package/dist/assertions/equality/entry-equality.d.ts +287 -11
- package/dist/assertions/equality/entry-equality.js +243 -6
- package/dist/assertions/equality/json-equality.d.ts +244 -15
- package/dist/assertions/equality/json-equality.js +207 -11
- package/dist/assertions/equality/simple-equality.d.ts +849 -28
- package/dist/assertions/equality/simple-equality.js +712 -6
- package/dist/assertions/equality/ts-type-equality.d.ts +37 -1
- package/dist/assertions/equality/ts-type-equality.js +13 -1
- package/dist/assertions/extendable-assertions.d.ts +288 -120
- package/dist/assertions/extendable-assertions.js +32 -60
- package/dist/assertions/http.d.ts +217 -10
- package/dist/assertions/http.js +182 -6
- package/dist/assertions/instance.d.ts +189 -8
- package/dist/assertions/instance.js +159 -5
- package/dist/assertions/keys.d.ts +658 -13
- package/dist/assertions/keys.js +556 -5
- package/dist/assertions/length.d.ts +381 -9
- package/dist/assertions/length.js +309 -5
- package/dist/assertions/nullish.d.ts +169 -7
- package/dist/assertions/nullish.js +137 -6
- package/dist/assertions/numeric.d.ts +965 -11
- package/dist/assertions/numeric.js +819 -1
- package/dist/assertions/output.d.ts +107 -7
- package/dist/assertions/output.js +92 -5
- package/dist/assertions/primitive.d.ts +416 -13
- package/dist/assertions/primitive.js +352 -6
- package/dist/assertions/promise.d.ts +640 -21
- package/dist/assertions/promise.js +536 -15
- package/dist/assertions/regexp.d.ts +202 -3
- package/dist/assertions/regexp.js +173 -1
- package/dist/assertions/runtime-type.d.ts +1822 -41
- package/dist/assertions/runtime-type.js +1558 -35
- package/dist/assertions/throws.d.ts +265 -17
- package/dist/assertions/throws.js +229 -17
- package/dist/assertions/uuid.d.ts +233 -10
- package/dist/assertions/uuid.js +195 -6
- package/dist/assertions/values.d.ts +1086 -15
- package/dist/assertions/values.js +907 -6
- package/dist/augments/assertion.error.d.ts +2 -1
- package/dist/augments/assertion.error.js +2 -1
- package/dist/augments/guards/assert-wrap.d.ts +82 -37
- package/dist/augments/guards/assert-wrap.js +13 -2
- package/dist/augments/guards/assert.d.ts +30 -14
- package/dist/augments/guards/assert.js +21 -4
- package/dist/augments/guards/check-wrap.d.ts +94 -51
- package/dist/augments/guards/check-wrap.js +11 -3
- package/dist/augments/guards/check.d.ts +87 -37
- package/dist/augments/guards/check.js +9 -2
- package/dist/augments/guards/wait-until.d.ts +110 -103
- package/dist/augments/guards/wait-until.js +18 -3
- package/dist/augments/if-equals.d.ts +4 -2
- package/dist/guard-types/assert-wrap-function.d.ts +5 -2
- package/dist/guard-types/check-function.d.ts +5 -2
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +4 -1
- package/dist/guard-types/guard-group.d.ts +7 -8
- package/dist/guard-types/wait-until-function.d.ts +8 -3
- package/dist/guard-types/wait-until-function.js +1 -1
- package/package.json +17 -4
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @augment-vir/assert
|
|
2
|
+
|
|
3
|
+
A collection of assertions for test and production code alike. These main exports are the following:
|
|
4
|
+
|
|
5
|
+
- [`assert`](https://electrovir.github.io/augment-vir/functions/assert.html): a collection of assertion methods with type guards when possible. Example: [`assert.isDefined()`](https://electrovir.github.io/augment-vir/functions/assert.html#isDefined)
|
|
6
|
+
- [`check`](https://electrovir.github.io/augment-vir/functions/check.html): a collection of boolean check methods with type guards when possible. Example: [`check.isBoolean()`](https://electrovir.github.io/augment-vir/functions/check.html#isBoolean)
|
|
7
|
+
- [`assertWrap`](https://electrovir.github.io/augment-vir/functions/assertWrap.html): a collection of assertions that return the asserted value if the assertion passes. Examples [`assertWrap.isArray()`](https://electrovir.github.io/augment-vir/functions/assertWrap.html#isArray)
|
|
8
|
+
- [`checkWrap`](https://electrovir.github.io/augment-vir/functions/checkWrap.html): a collection of checks that return the checked value if it passes or `undefined`. Example: [`checkWrap.isInfinite()`](https://electrovir.github.io/augment-vir/functions/checkWrap.html#isInfinite)
|
|
9
|
+
- [`waitUntil`](https://electrovir.github.io/augment-vir/functions/waitUntil.html): a collection of assertion methods that try to wait until the assertion becomes true. Example: [`waitUntil.isTruthy()`](https://electrovir.github.io/augment-vir/functions/waitUntil.html#isTruthy)
|
|
10
|
+
|
|
11
|
+
See the docs under `Assert`, or `Package: @augment-vir/assert` here: https://electrovir.github.io/augment-vir
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { MaybePromise, NarrowToExpected } from '@augment-vir/core';
|
|
2
|
+
import { autoGuardSymbol } from '../guard-types/guard-override.js';
|
|
2
3
|
import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
3
4
|
/**
|
|
4
5
|
* All falsy values in JavaScript. This does not include `NaN` because there is no dedicated type
|
|
5
6
|
* for it in TypeScript.
|
|
6
7
|
*
|
|
7
8
|
* @category Assert : Util
|
|
9
|
+
* @category Package : @augment-vir/assert
|
|
8
10
|
* @example
|
|
9
11
|
*
|
|
10
12
|
* ```ts
|
|
@@ -13,13 +15,14 @@ import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
|
13
15
|
* const falsy: FalsyValue = 0;
|
|
14
16
|
* ```
|
|
15
17
|
*
|
|
16
|
-
* @package
|
|
18
|
+
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
17
19
|
*/
|
|
18
20
|
export type FalsyValue = undefined | null | false | 0 | '' | -0 | 0n;
|
|
19
21
|
/**
|
|
20
22
|
* Narrows the given type parameter `T` to all its falsy sub-types.
|
|
21
23
|
*
|
|
22
24
|
* @category Assert : Util
|
|
25
|
+
* @category Package : @augment-vir/assert
|
|
23
26
|
* @example
|
|
24
27
|
*
|
|
25
28
|
* ```ts
|
|
@@ -29,12 +32,14 @@ export type FalsyValue = undefined | null | false | 0 | '' | -0 | 0n;
|
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
31
34
|
* @param T The original type to narrow.
|
|
32
|
-
* @package
|
|
35
|
+
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
33
36
|
*/
|
|
34
|
-
export type Falsy<T> = NarrowToExpected<T, FalsyValue>;
|
|
37
|
+
export type Falsy<T> = NarrowToExpected<T, FalsyValue>;
|
|
38
|
+
/**
|
|
35
39
|
* Narrows the given type parameter `T` to all its truthy sub-types.
|
|
36
40
|
*
|
|
37
41
|
* @category Assert : Util
|
|
42
|
+
* @category Package : @augment-vir/assert
|
|
38
43
|
* @example
|
|
39
44
|
*
|
|
40
45
|
* ```ts
|
|
@@ -44,7 +49,7 @@ export type Falsy<T> = NarrowToExpected<T, FalsyValue>; /**
|
|
|
44
49
|
* ```
|
|
45
50
|
*
|
|
46
51
|
* @param T The original type to narrow.
|
|
47
|
-
* @package
|
|
52
|
+
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
48
53
|
*/
|
|
49
54
|
export type Truthy<T> = Exclude<T, FalsyValue>;
|
|
50
55
|
declare function isFalsy(input: unknown, failureMessage?: string | undefined): asserts input is FalsyValue;
|
|
@@ -52,45 +57,466 @@ declare function isTruthy<const Actual>(input: Actual, failureMessage?: string |
|
|
|
52
57
|
declare function isTrue(input: unknown, failureMessage?: string | undefined): asserts input is true;
|
|
53
58
|
declare function isFalse(input: unknown, failureMessage?: string | undefined): asserts input is false;
|
|
54
59
|
export declare const booleanGuards: {
|
|
55
|
-
|
|
60
|
+
assert: {
|
|
56
61
|
/**
|
|
57
|
-
*
|
|
62
|
+
* Asserts that a value is exactly `false`.
|
|
58
63
|
*
|
|
59
|
-
* Type guards the value
|
|
64
|
+
* Type guards the value.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import {assert} from '@augment-vir/assert';
|
|
70
|
+
*
|
|
71
|
+
* assert.isFalse(true); // fails
|
|
72
|
+
* assert.isFalse(false); // passes
|
|
73
|
+
* assert.isFalse(1); // fails
|
|
74
|
+
* assert.isFalse(0); // fails
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @throws {@link AssertionError} If the value is not `false`.
|
|
78
|
+
* @see
|
|
79
|
+
* - {@link assert.isTrue} : the opposite assertion.
|
|
80
|
+
* - {@link assert.isFalsy} : a less exact assertion.
|
|
60
81
|
*/
|
|
61
|
-
|
|
82
|
+
isFalse: typeof isFalse;
|
|
62
83
|
/**
|
|
63
|
-
*
|
|
84
|
+
* Asserts that a value is falsy.
|
|
64
85
|
*
|
|
65
86
|
* Type guards the value when possible.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import {assert} from '@augment-vir/assert';
|
|
92
|
+
*
|
|
93
|
+
* assert.isFalsy(true); // fails
|
|
94
|
+
* assert.isFalsy(false); // passes
|
|
95
|
+
* assert.isFalsy(1); // fails
|
|
96
|
+
* assert.isFalsy(0); // passes
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @throws {@link AssertionError} If the value is not falsy.
|
|
100
|
+
* @see
|
|
101
|
+
* - {@link assert.isTruthy} : the opposite assertion.
|
|
102
|
+
* - {@link assert.isFalse} : a more exact assertion.
|
|
66
103
|
*/
|
|
67
|
-
|
|
104
|
+
isFalsy: typeof isFalsy;
|
|
68
105
|
/**
|
|
69
|
-
*
|
|
106
|
+
* Asserts that a value is exactly `true`.
|
|
70
107
|
*
|
|
71
108
|
* Type guards the value.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* import {assert} from '@augment-vir/assert';
|
|
114
|
+
*
|
|
115
|
+
* assert.isTrue(true); // passes
|
|
116
|
+
* assert.isTrue(false); // fails
|
|
117
|
+
* assert.isTrue(1); // fails
|
|
118
|
+
* assert.isTrue(0); // fails
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @throws {@link AssertionError} If the value is not `true`.
|
|
122
|
+
* @see
|
|
123
|
+
* - {@link assert.isFalse} : the opposite assertion.
|
|
124
|
+
* - {@link assert.isTruthy} : a less exact assertion.
|
|
72
125
|
*/
|
|
73
126
|
isTrue: typeof isTrue;
|
|
74
127
|
/**
|
|
75
|
-
*
|
|
128
|
+
* Asserts that a value is truthy.
|
|
76
129
|
*
|
|
77
130
|
* Type guards the value.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* import {assert} from '@augment-vir/assert';
|
|
136
|
+
*
|
|
137
|
+
* assert.isTruthy(true); // passes
|
|
138
|
+
* assert.isTruthy(false); // fails
|
|
139
|
+
* assert.isTruthy(1); // passes
|
|
140
|
+
* assert.isTruthy(0); // fails
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @throws {@link AssertionError} If the value is not truthy.
|
|
144
|
+
* @see
|
|
145
|
+
* - {@link assert.isFalsy} : the opposite assertion.
|
|
146
|
+
* - {@link assert.isTrue} : a more exact assertion.
|
|
78
147
|
*/
|
|
79
|
-
|
|
148
|
+
isTruthy: typeof isTruthy;
|
|
80
149
|
};
|
|
81
|
-
|
|
150
|
+
check: {
|
|
151
|
+
/**
|
|
152
|
+
* Checks that a value is exactly `false`.
|
|
153
|
+
*
|
|
154
|
+
* Type guards the value.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* import {check} from '@augment-vir/assert';
|
|
160
|
+
*
|
|
161
|
+
* check.isFalse(true); // returns `false`
|
|
162
|
+
* check.isFalse(false); // returns `true`
|
|
163
|
+
* check.isFalse(1); // returns `false`
|
|
164
|
+
* check.isFalse(0); // returns `false`
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @see
|
|
168
|
+
* - {@link check.isTrue} : the opposite check.
|
|
169
|
+
* - {@link check.isFalsy} : a less exact check.
|
|
170
|
+
*/
|
|
171
|
+
isFalse: typeof autoGuardSymbol;
|
|
172
|
+
/**
|
|
173
|
+
* Checks that a value is falsy.
|
|
174
|
+
*
|
|
175
|
+
* Type guards the value when possible.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* import {check} from '@augment-vir/assert';
|
|
181
|
+
*
|
|
182
|
+
* check.isFalsy(true); // returns `false`
|
|
183
|
+
* check.isFalsy(false); // returns `true`
|
|
184
|
+
* check.isFalsy(1); // returns `false`
|
|
185
|
+
* check.isFalsy(0); // returns `true`
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @see
|
|
189
|
+
* - {@link check.isTruthy} : the opposite check.
|
|
190
|
+
* - {@link check.isFalse} : a more exact check.
|
|
191
|
+
*/
|
|
192
|
+
isFalsy: typeof autoGuardSymbol;
|
|
193
|
+
/**
|
|
194
|
+
* Checks that a value is exactly `true`.
|
|
195
|
+
*
|
|
196
|
+
* Type guards the value.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* import {check} from '@augment-vir/assert';
|
|
202
|
+
*
|
|
203
|
+
* check.isTrue(true); // returns `true`
|
|
204
|
+
* check.isTrue(false); // returns `false`
|
|
205
|
+
* check.isTrue(1); // returns `false`
|
|
206
|
+
* check.isTrue(0); // returns `false`
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @see
|
|
210
|
+
* - {@link check.isFalse} : the opposite check.
|
|
211
|
+
* - {@link check.isTruthy} : a less exact check.
|
|
212
|
+
*/
|
|
213
|
+
isTrue: typeof autoGuardSymbol;
|
|
214
|
+
/**
|
|
215
|
+
* Checks that a value is truthy.
|
|
216
|
+
*
|
|
217
|
+
* Type guards the value.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* import {check} from '@augment-vir/assert';
|
|
223
|
+
*
|
|
224
|
+
* check.isTruthy(true); // passes
|
|
225
|
+
* check.isTruthy(false); // fails
|
|
226
|
+
* check.isTruthy(1); // passes
|
|
227
|
+
* check.isTruthy(0); // fails
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @see
|
|
231
|
+
* - {@link check.isFalsy} : the opposite check.
|
|
232
|
+
* - {@link check.isTrue} : a more exact check.
|
|
233
|
+
*/
|
|
82
234
|
isTruthy: <T>(input: T) => input is Truthy<T>;
|
|
83
235
|
};
|
|
84
|
-
|
|
236
|
+
assertWrap: {
|
|
237
|
+
/**
|
|
238
|
+
* Asserts that a value is exactly `false`. Returns the value if the assertion passes.
|
|
239
|
+
*
|
|
240
|
+
* Type guards the value.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
246
|
+
*
|
|
247
|
+
* assertWrap.isFalse(true); // throws an error
|
|
248
|
+
* assertWrap.isFalse(false); // returns `false`
|
|
249
|
+
* assertWrap.isFalse(1); // throws an error
|
|
250
|
+
* assertWrap.isFalse(0); // throws an error
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @returns The value if the assertion passes.
|
|
254
|
+
* @throws {@link AssertionError} If the value is not `false`.
|
|
255
|
+
* @see
|
|
256
|
+
* - {@link assertWrap.isTrue} : the opposite assertion.
|
|
257
|
+
* - {@link assertWrap.isFalsy} : a less exact assertion.
|
|
258
|
+
*/
|
|
259
|
+
isFalse: typeof autoGuardSymbol;
|
|
260
|
+
/**
|
|
261
|
+
* Asserts that a value is falsy. Returns the value if the assertion passes.
|
|
262
|
+
*
|
|
263
|
+
* Type guards the value when possible.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
269
|
+
*
|
|
270
|
+
* assertWrap.isFalsy(true); // throws an error
|
|
271
|
+
* assertWrap.isFalsy(false); // returns `false`
|
|
272
|
+
* assertWrap.isFalsy(1); // throws an error
|
|
273
|
+
* assertWrap.isFalsy(0); // returns `0`
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @returns The value if the assertion passes.
|
|
277
|
+
* @throws {@link AssertionError} If the value is not falsy.
|
|
278
|
+
* @see
|
|
279
|
+
* - {@link assertWrap.isTruthy} : the opposite assertion.
|
|
280
|
+
* - {@link assertWrap.isFalse} : a more exact assertion.
|
|
281
|
+
*/
|
|
85
282
|
isFalsy: <T>(input: T, failureMessage?: string | undefined) => Falsy<T>;
|
|
283
|
+
/**
|
|
284
|
+
* Asserts that a value is exactly `true`. Returns the value if the assertion passes.
|
|
285
|
+
*
|
|
286
|
+
* Type guards the value.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
292
|
+
*
|
|
293
|
+
* assertWrap.isTrue(true); // returns `true`
|
|
294
|
+
* assertWrap.isTrue(false); // throws an error
|
|
295
|
+
* assertWrap.isTrue(1); // throws an error
|
|
296
|
+
* assertWrap.isTrue(0); // throws an error
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @returns The value if the assertion passes.
|
|
300
|
+
* @throws {@link AssertionError} If the value is not `true`.
|
|
301
|
+
* @see
|
|
302
|
+
* - {@link assertWrap.isFalse} : the opposite assertion.
|
|
303
|
+
* - {@link assertWrap.isTruthy} : a less exact assertion.
|
|
304
|
+
*/
|
|
305
|
+
isTrue: typeof autoGuardSymbol;
|
|
306
|
+
/**
|
|
307
|
+
* Asserts that a value is truthy. Returns the value if the assertion passes.
|
|
308
|
+
*
|
|
309
|
+
* Type guards the value.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
*
|
|
313
|
+
* ```ts
|
|
314
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
315
|
+
*
|
|
316
|
+
* assertWrap.isTruthy(true); // returns `true`
|
|
317
|
+
* assertWrap.isTruthy(false); // throws an error
|
|
318
|
+
* assertWrap.isTruthy(1); // returns `1`
|
|
319
|
+
* assertWrap.isTruthy(0); // throws an error
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* @returns The value if the assertion passes.
|
|
323
|
+
* @throws {@link AssertionError} If the value is not truthy.
|
|
324
|
+
* @see
|
|
325
|
+
* - {@link assertWrap.isFalsy} : the opposite assertion.
|
|
326
|
+
* - {@link assertWrap.isTrue} : a more exact assertion.
|
|
327
|
+
*/
|
|
86
328
|
isTruthy: <T>(input: T, failureMessage?: string | undefined) => Truthy<T>;
|
|
87
329
|
};
|
|
88
|
-
|
|
330
|
+
checkWrap: {
|
|
331
|
+
/**
|
|
332
|
+
* Checks that a value is exactly `false`. Returns the value if the check passes, otherwise
|
|
333
|
+
* `undefined`.
|
|
334
|
+
*
|
|
335
|
+
* Type guards the value.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
*
|
|
339
|
+
* ```ts
|
|
340
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
341
|
+
*
|
|
342
|
+
* checkWrap.isFalse(true); // returns `false`
|
|
343
|
+
* checkWrap.isFalse(false); // returns `true`
|
|
344
|
+
* checkWrap.isFalse(1); // returns `false`
|
|
345
|
+
* checkWrap.isFalse(0); // returns `false`
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
349
|
+
* @see
|
|
350
|
+
* - {@link checkWrap.isTrue} : the opposite check.
|
|
351
|
+
* - {@link checkWrap.isFalsy} : a less exact check.
|
|
352
|
+
*/
|
|
353
|
+
isFalse: typeof autoGuardSymbol;
|
|
354
|
+
/**
|
|
355
|
+
* Checks that a value is falsy. Returns the value if the check passes, otherwise
|
|
356
|
+
* `undefined`.
|
|
357
|
+
*
|
|
358
|
+
* Type guards the value when possible.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
364
|
+
*
|
|
365
|
+
* checkWrap.isFalsy(true); // returns `false`
|
|
366
|
+
* checkWrap.isFalsy(false); // returns `true`
|
|
367
|
+
* checkWrap.isFalsy(1); // returns `false`
|
|
368
|
+
* checkWrap.isFalsy(0); // returns `true`
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
372
|
+
* @see
|
|
373
|
+
* - {@link checkWrap.isTruthy} : the opposite check.
|
|
374
|
+
* - {@link checkWrap.isFalse} : a more exact check.
|
|
375
|
+
*/
|
|
89
376
|
isFalsy: <T>(input: T) => Falsy<T> | undefined;
|
|
377
|
+
/**
|
|
378
|
+
* Checks that a value is exactly `true`. Returns the value if the check passes, otherwise
|
|
379
|
+
* `undefined`.
|
|
380
|
+
*
|
|
381
|
+
* Type guards the value.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
*
|
|
385
|
+
* ```ts
|
|
386
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
387
|
+
*
|
|
388
|
+
* checkWrap.isTrue(true); // returns `true`
|
|
389
|
+
* checkWrap.isTrue(false); // returns `false`
|
|
390
|
+
* checkWrap.isTrue(1); // returns `false`
|
|
391
|
+
* checkWrap.isTrue(0); // returns `false`
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
395
|
+
* @see
|
|
396
|
+
* - {@link checkWrap.isFalse} : the opposite check.
|
|
397
|
+
* - {@link checkWrap.isTruthy} : a less exact check.
|
|
398
|
+
*/
|
|
399
|
+
isTrue: typeof autoGuardSymbol;
|
|
400
|
+
/**
|
|
401
|
+
* Checks that a value is truthy. Returns the value if the check passes, otherwise
|
|
402
|
+
* `undefined`.
|
|
403
|
+
*
|
|
404
|
+
* Type guards the value.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
*
|
|
408
|
+
* ```ts
|
|
409
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
410
|
+
*
|
|
411
|
+
* checkWrap.isTruthy(true); // passes
|
|
412
|
+
* checkWrap.isTruthy(false); // fails
|
|
413
|
+
* checkWrap.isTruthy(1); // passes
|
|
414
|
+
* checkWrap.isTruthy(0); // fails
|
|
415
|
+
* ```
|
|
416
|
+
*
|
|
417
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
418
|
+
* @see
|
|
419
|
+
* - {@link checkWrap.isFalsy} : the opposite check.
|
|
420
|
+
* - {@link checkWrap.isTrue} : a more exact check.
|
|
421
|
+
*/
|
|
90
422
|
isTruthy: <T>(input: T) => Truthy<T> | undefined;
|
|
91
423
|
};
|
|
92
|
-
|
|
424
|
+
waitUntil: {
|
|
425
|
+
/**
|
|
426
|
+
* Repeatedly calls a callback until its output is exactly `false`. Once the callback output
|
|
427
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
428
|
+
*
|
|
429
|
+
* Type guards the value.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
*
|
|
433
|
+
* ```ts
|
|
434
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
435
|
+
*
|
|
436
|
+
* await waitUntil.isFalse(() => true); // throws an error
|
|
437
|
+
* await waitUntil.isFalse(() => false); // returns `false`
|
|
438
|
+
* await waitUntil.isFalse(() => 1); // throws an error
|
|
439
|
+
* await waitUntil.isFalse(() => 0); // throws an error
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* @returns The callback output once it passes.
|
|
443
|
+
* @throws {@link AssertionError} On timeout.
|
|
444
|
+
* @see
|
|
445
|
+
* - {@link waitUntil.isTrue} : the opposite assertion.
|
|
446
|
+
* - {@link waitUntil.isFalsy} : a less exact assertion.
|
|
447
|
+
*/
|
|
448
|
+
isFalse: typeof autoGuardSymbol;
|
|
449
|
+
/**
|
|
450
|
+
* Repeatedly calls a callback until its output is falsy. Once the callback output passes,
|
|
451
|
+
* it is returned. If the attempts time out, an error is thrown.
|
|
452
|
+
*
|
|
453
|
+
* Type guards the value.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
458
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
459
|
+
*
|
|
460
|
+
* await waitUntil.isFalsy(() => true); // throws an error
|
|
461
|
+
* await waitUntil.isFalsy(() => false); // returns `false`
|
|
462
|
+
* await waitUntil.isFalsy(() => 1); // throws an error
|
|
463
|
+
* await waitUntil.isFalsy(() => 0); // returns `0`
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* @returns The callback output once it passes.
|
|
467
|
+
* @throws {@link AssertionError} On timeout.
|
|
468
|
+
* @see
|
|
469
|
+
* - {@link waitUntil.isTruthy} : the opposite assertion.
|
|
470
|
+
* - {@link waitUntil.isFalse} : a more exact assertion.
|
|
471
|
+
*/
|
|
93
472
|
isFalsy: <Actual>(callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Falsy<Actual>>;
|
|
473
|
+
/**
|
|
474
|
+
* Repeatedly calls a callback until its output is exactly `true`. Once the callback output
|
|
475
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
476
|
+
*
|
|
477
|
+
* Type guards the value.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
*
|
|
481
|
+
* ```ts
|
|
482
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
483
|
+
*
|
|
484
|
+
* await waitUntil.isTrue(() => true); // returns `true`
|
|
485
|
+
* await waitUntil.isTrue(() => false); // throws an error
|
|
486
|
+
* await waitUntil.isTrue(() => 1); // throws an error
|
|
487
|
+
* await waitUntil.isTrue(() => 0); // throws an error
|
|
488
|
+
* ```
|
|
489
|
+
*
|
|
490
|
+
* @returns The callback output once it passes.
|
|
491
|
+
* @throws {@link AssertionError} On timeout.
|
|
492
|
+
* @see
|
|
493
|
+
* - {@link waitUntil.isFalse} : the opposite assertion.
|
|
494
|
+
* - {@link waitUntil.isTruthy} : a less exact assertion.
|
|
495
|
+
*/
|
|
496
|
+
isTrue: typeof autoGuardSymbol;
|
|
497
|
+
/**
|
|
498
|
+
* Repeatedly calls a callback until its output is truthy. Once the callback output passes,
|
|
499
|
+
* it is returned. If the attempts time out, an error is thrown.
|
|
500
|
+
*
|
|
501
|
+
* Type guards the value.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
*
|
|
505
|
+
* ```ts
|
|
506
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
507
|
+
*
|
|
508
|
+
* await waitUntil.isTruthy(() => true); // returns `true`
|
|
509
|
+
* await waitUntil.isTruthy(() => false); // throws an error
|
|
510
|
+
* await waitUntil.isTruthy(() => 1); // returns `1`
|
|
511
|
+
* await waitUntil.isTruthy(() => 0); // throws an error
|
|
512
|
+
* ```
|
|
513
|
+
*
|
|
514
|
+
* @returns The callback output once it passes.
|
|
515
|
+
* @throws {@link AssertionError} On timeout.
|
|
516
|
+
* @see
|
|
517
|
+
* - {@link waitUntil.isFalsy} : the opposite assertion.
|
|
518
|
+
* - {@link waitUntil.isTrue} : a more exact assertion.
|
|
519
|
+
*/
|
|
94
520
|
isTruthy: <Actual>(callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Truthy<Actual>>;
|
|
95
521
|
};
|
|
96
522
|
};
|