@augment-vir/assert 30.0.0 → 30.0.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.
- 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 +21 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringify } from '@augment-vir/core';
|
|
2
2
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
-
import { autoGuard } from '../guard-types/guard-override.js';
|
|
3
|
+
import { autoGuard, autoGuardSymbol } from '../guard-types/guard-override.js';
|
|
4
4
|
function isFalsy(input, failureMessage) {
|
|
5
5
|
if (input) {
|
|
6
6
|
throw new AssertionError(`'${stringify(input)}' is not truthy.`, failureMessage);
|
|
@@ -22,26 +22,383 @@ function isFalse(input, failureMessage) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
const assertions = {
|
|
25
|
+
isFalse,
|
|
25
26
|
isFalsy,
|
|
26
|
-
isTruthy,
|
|
27
27
|
isTrue,
|
|
28
|
-
|
|
28
|
+
isTruthy,
|
|
29
29
|
};
|
|
30
30
|
export const booleanGuards = {
|
|
31
|
-
assertions,
|
|
32
|
-
|
|
31
|
+
assert: assertions,
|
|
32
|
+
check: {
|
|
33
|
+
/**
|
|
34
|
+
* Checks that a value is exactly `false`.
|
|
35
|
+
*
|
|
36
|
+
* Type guards the value.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import {check} from '@augment-vir/assert';
|
|
42
|
+
*
|
|
43
|
+
* check.isFalse(true); // returns `false`
|
|
44
|
+
* check.isFalse(false); // returns `true`
|
|
45
|
+
* check.isFalse(1); // returns `false`
|
|
46
|
+
* check.isFalse(0); // returns `false`
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see
|
|
50
|
+
* - {@link check.isTrue} : the opposite check.
|
|
51
|
+
* - {@link check.isFalsy} : a less exact check.
|
|
52
|
+
*/
|
|
53
|
+
isFalse: autoGuardSymbol,
|
|
54
|
+
/**
|
|
55
|
+
* Checks that a value is falsy.
|
|
56
|
+
*
|
|
57
|
+
* Type guards the value when possible.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import {check} from '@augment-vir/assert';
|
|
63
|
+
*
|
|
64
|
+
* check.isFalsy(true); // returns `false`
|
|
65
|
+
* check.isFalsy(false); // returns `true`
|
|
66
|
+
* check.isFalsy(1); // returns `false`
|
|
67
|
+
* check.isFalsy(0); // returns `true`
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @see
|
|
71
|
+
* - {@link check.isTruthy} : the opposite check.
|
|
72
|
+
* - {@link check.isFalse} : a more exact check.
|
|
73
|
+
*/
|
|
74
|
+
isFalsy: autoGuardSymbol,
|
|
75
|
+
/**
|
|
76
|
+
* Checks that a value is exactly `true`.
|
|
77
|
+
*
|
|
78
|
+
* Type guards the value.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import {check} from '@augment-vir/assert';
|
|
84
|
+
*
|
|
85
|
+
* check.isTrue(true); // returns `true`
|
|
86
|
+
* check.isTrue(false); // returns `false`
|
|
87
|
+
* check.isTrue(1); // returns `false`
|
|
88
|
+
* check.isTrue(0); // returns `false`
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @see
|
|
92
|
+
* - {@link check.isFalse} : the opposite check.
|
|
93
|
+
* - {@link check.isTruthy} : a less exact check.
|
|
94
|
+
*/
|
|
95
|
+
isTrue: autoGuardSymbol,
|
|
96
|
+
/**
|
|
97
|
+
* Checks that a value is truthy.
|
|
98
|
+
*
|
|
99
|
+
* Type guards the value.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* import {check} from '@augment-vir/assert';
|
|
105
|
+
*
|
|
106
|
+
* check.isTruthy(true); // passes
|
|
107
|
+
* check.isTruthy(false); // fails
|
|
108
|
+
* check.isTruthy(1); // passes
|
|
109
|
+
* check.isTruthy(0); // fails
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @see
|
|
113
|
+
* - {@link check.isFalsy} : the opposite check.
|
|
114
|
+
* - {@link check.isTrue} : a more exact check.
|
|
115
|
+
*/
|
|
33
116
|
isTruthy: autoGuard(),
|
|
34
117
|
},
|
|
35
|
-
|
|
118
|
+
assertWrap: {
|
|
119
|
+
/**
|
|
120
|
+
* Asserts that a value is exactly `false`. Returns the value if the assertion passes.
|
|
121
|
+
*
|
|
122
|
+
* Type guards the value.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
128
|
+
*
|
|
129
|
+
* assertWrap.isFalse(true); // throws an error
|
|
130
|
+
* assertWrap.isFalse(false); // returns `false`
|
|
131
|
+
* assertWrap.isFalse(1); // throws an error
|
|
132
|
+
* assertWrap.isFalse(0); // throws an error
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @returns The value if the assertion passes.
|
|
136
|
+
* @throws {@link AssertionError} If the value is not `false`.
|
|
137
|
+
* @see
|
|
138
|
+
* - {@link assertWrap.isTrue} : the opposite assertion.
|
|
139
|
+
* - {@link assertWrap.isFalsy} : a less exact assertion.
|
|
140
|
+
*/
|
|
141
|
+
isFalse: autoGuardSymbol,
|
|
142
|
+
/**
|
|
143
|
+
* Asserts that a value is falsy. Returns the value if the assertion passes.
|
|
144
|
+
*
|
|
145
|
+
* Type guards the value when possible.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
*
|
|
149
|
+
* ```ts
|
|
150
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
151
|
+
*
|
|
152
|
+
* assertWrap.isFalsy(true); // throws an error
|
|
153
|
+
* assertWrap.isFalsy(false); // returns `false`
|
|
154
|
+
* assertWrap.isFalsy(1); // throws an error
|
|
155
|
+
* assertWrap.isFalsy(0); // returns `0`
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @returns The value if the assertion passes.
|
|
159
|
+
* @throws {@link AssertionError} If the value is not falsy.
|
|
160
|
+
* @see
|
|
161
|
+
* - {@link assertWrap.isTruthy} : the opposite assertion.
|
|
162
|
+
* - {@link assertWrap.isFalse} : a more exact assertion.
|
|
163
|
+
*/
|
|
36
164
|
isFalsy: autoGuard(),
|
|
165
|
+
/**
|
|
166
|
+
* Asserts that a value is exactly `true`. Returns the value if the assertion passes.
|
|
167
|
+
*
|
|
168
|
+
* Type guards the value.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
174
|
+
*
|
|
175
|
+
* assertWrap.isTrue(true); // returns `true`
|
|
176
|
+
* assertWrap.isTrue(false); // throws an error
|
|
177
|
+
* assertWrap.isTrue(1); // throws an error
|
|
178
|
+
* assertWrap.isTrue(0); // throws an error
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @returns The value if the assertion passes.
|
|
182
|
+
* @throws {@link AssertionError} If the value is not `true`.
|
|
183
|
+
* @see
|
|
184
|
+
* - {@link assertWrap.isFalse} : the opposite assertion.
|
|
185
|
+
* - {@link assertWrap.isTruthy} : a less exact assertion.
|
|
186
|
+
*/
|
|
187
|
+
isTrue: autoGuardSymbol,
|
|
188
|
+
/**
|
|
189
|
+
* Asserts that a value is truthy. Returns the value if the assertion passes.
|
|
190
|
+
*
|
|
191
|
+
* Type guards the value.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
197
|
+
*
|
|
198
|
+
* assertWrap.isTruthy(true); // returns `true`
|
|
199
|
+
* assertWrap.isTruthy(false); // throws an error
|
|
200
|
+
* assertWrap.isTruthy(1); // returns `1`
|
|
201
|
+
* assertWrap.isTruthy(0); // throws an error
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @returns The value if the assertion passes.
|
|
205
|
+
* @throws {@link AssertionError} If the value is not truthy.
|
|
206
|
+
* @see
|
|
207
|
+
* - {@link assertWrap.isFalsy} : the opposite assertion.
|
|
208
|
+
* - {@link assertWrap.isTrue} : a more exact assertion.
|
|
209
|
+
*/
|
|
37
210
|
isTruthy: autoGuard(),
|
|
38
211
|
},
|
|
39
|
-
|
|
212
|
+
checkWrap: {
|
|
213
|
+
/**
|
|
214
|
+
* Checks that a value is exactly `false`. Returns the value if the check passes, otherwise
|
|
215
|
+
* `undefined`.
|
|
216
|
+
*
|
|
217
|
+
* Type guards the value.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
223
|
+
*
|
|
224
|
+
* checkWrap.isFalse(true); // returns `false`
|
|
225
|
+
* checkWrap.isFalse(false); // returns `true`
|
|
226
|
+
* checkWrap.isFalse(1); // returns `false`
|
|
227
|
+
* checkWrap.isFalse(0); // returns `false`
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
231
|
+
* @see
|
|
232
|
+
* - {@link checkWrap.isTrue} : the opposite check.
|
|
233
|
+
* - {@link checkWrap.isFalsy} : a less exact check.
|
|
234
|
+
*/
|
|
235
|
+
isFalse: autoGuardSymbol,
|
|
236
|
+
/**
|
|
237
|
+
* Checks that a value is falsy. Returns the value if the check passes, otherwise
|
|
238
|
+
* `undefined`.
|
|
239
|
+
*
|
|
240
|
+
* Type guards the value when possible.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
246
|
+
*
|
|
247
|
+
* checkWrap.isFalsy(true); // returns `false`
|
|
248
|
+
* checkWrap.isFalsy(false); // returns `true`
|
|
249
|
+
* checkWrap.isFalsy(1); // returns `false`
|
|
250
|
+
* checkWrap.isFalsy(0); // returns `true`
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
254
|
+
* @see
|
|
255
|
+
* - {@link checkWrap.isTruthy} : the opposite check.
|
|
256
|
+
* - {@link checkWrap.isFalse} : a more exact check.
|
|
257
|
+
*/
|
|
40
258
|
isFalsy: autoGuard(),
|
|
259
|
+
/**
|
|
260
|
+
* Checks that a value is exactly `true`. Returns the value if the check passes, otherwise
|
|
261
|
+
* `undefined`.
|
|
262
|
+
*
|
|
263
|
+
* Type guards the value.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
269
|
+
*
|
|
270
|
+
* checkWrap.isTrue(true); // returns `true`
|
|
271
|
+
* checkWrap.isTrue(false); // returns `false`
|
|
272
|
+
* checkWrap.isTrue(1); // returns `false`
|
|
273
|
+
* checkWrap.isTrue(0); // returns `false`
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
277
|
+
* @see
|
|
278
|
+
* - {@link checkWrap.isFalse} : the opposite check.
|
|
279
|
+
* - {@link checkWrap.isTruthy} : a less exact check.
|
|
280
|
+
*/
|
|
281
|
+
isTrue: autoGuardSymbol,
|
|
282
|
+
/**
|
|
283
|
+
* Checks that a value is truthy. Returns the value if the check passes, otherwise
|
|
284
|
+
* `undefined`.
|
|
285
|
+
*
|
|
286
|
+
* Type guards the value.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
292
|
+
*
|
|
293
|
+
* checkWrap.isTruthy(true); // passes
|
|
294
|
+
* checkWrap.isTruthy(false); // fails
|
|
295
|
+
* checkWrap.isTruthy(1); // passes
|
|
296
|
+
* checkWrap.isTruthy(0); // fails
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @returns The value if the check passes, otherwise `undefined`.
|
|
300
|
+
* @see
|
|
301
|
+
* - {@link checkWrap.isFalsy} : the opposite check.
|
|
302
|
+
* - {@link checkWrap.isTrue} : a more exact check.
|
|
303
|
+
*/
|
|
41
304
|
isTruthy: autoGuard(),
|
|
42
305
|
},
|
|
43
|
-
|
|
306
|
+
waitUntil: {
|
|
307
|
+
/**
|
|
308
|
+
* Repeatedly calls a callback until its output is exactly `false`. Once the callback output
|
|
309
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
310
|
+
*
|
|
311
|
+
* Type guards the value.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
317
|
+
*
|
|
318
|
+
* await waitUntil.isFalse(() => true); // throws an error
|
|
319
|
+
* await waitUntil.isFalse(() => false); // returns `false`
|
|
320
|
+
* await waitUntil.isFalse(() => 1); // throws an error
|
|
321
|
+
* await waitUntil.isFalse(() => 0); // throws an error
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @returns The callback output once it passes.
|
|
325
|
+
* @throws {@link AssertionError} On timeout.
|
|
326
|
+
* @see
|
|
327
|
+
* - {@link waitUntil.isTrue} : the opposite assertion.
|
|
328
|
+
* - {@link waitUntil.isFalsy} : a less exact assertion.
|
|
329
|
+
*/
|
|
330
|
+
isFalse: autoGuardSymbol,
|
|
331
|
+
/**
|
|
332
|
+
* Repeatedly calls a callback until its output is falsy. Once the callback output passes,
|
|
333
|
+
* it is returned. If the attempts time out, an error is thrown.
|
|
334
|
+
*
|
|
335
|
+
* Type guards the value.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
*
|
|
339
|
+
* ```ts
|
|
340
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
341
|
+
*
|
|
342
|
+
* await waitUntil.isFalsy(() => true); // throws an error
|
|
343
|
+
* await waitUntil.isFalsy(() => false); // returns `false`
|
|
344
|
+
* await waitUntil.isFalsy(() => 1); // throws an error
|
|
345
|
+
* await waitUntil.isFalsy(() => 0); // returns `0`
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @returns The callback output once it passes.
|
|
349
|
+
* @throws {@link AssertionError} On timeout.
|
|
350
|
+
* @see
|
|
351
|
+
* - {@link waitUntil.isTruthy} : the opposite assertion.
|
|
352
|
+
* - {@link waitUntil.isFalse} : a more exact assertion.
|
|
353
|
+
*/
|
|
44
354
|
isFalsy: autoGuard(),
|
|
355
|
+
/**
|
|
356
|
+
* Repeatedly calls a callback until its output is exactly `true`. Once the callback output
|
|
357
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
358
|
+
*
|
|
359
|
+
* Type guards the value.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
*
|
|
363
|
+
* ```ts
|
|
364
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
365
|
+
*
|
|
366
|
+
* await waitUntil.isTrue(() => true); // returns `true`
|
|
367
|
+
* await waitUntil.isTrue(() => false); // throws an error
|
|
368
|
+
* await waitUntil.isTrue(() => 1); // throws an error
|
|
369
|
+
* await waitUntil.isTrue(() => 0); // throws an error
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* @returns The callback output once it passes.
|
|
373
|
+
* @throws {@link AssertionError} On timeout.
|
|
374
|
+
* @see
|
|
375
|
+
* - {@link waitUntil.isFalse} : the opposite assertion.
|
|
376
|
+
* - {@link waitUntil.isTruthy} : a less exact assertion.
|
|
377
|
+
*/
|
|
378
|
+
isTrue: autoGuardSymbol,
|
|
379
|
+
/**
|
|
380
|
+
* Repeatedly calls a callback until its output is truthy. Once the callback output passes,
|
|
381
|
+
* it is returned. If the attempts time out, an error is thrown.
|
|
382
|
+
*
|
|
383
|
+
* Type guards the value.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
*
|
|
387
|
+
* ```ts
|
|
388
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
389
|
+
*
|
|
390
|
+
* await waitUntil.isTruthy(() => true); // returns `true`
|
|
391
|
+
* await waitUntil.isTruthy(() => false); // throws an error
|
|
392
|
+
* await waitUntil.isTruthy(() => 1); // returns `1`
|
|
393
|
+
* await waitUntil.isTruthy(() => 0); // throws an error
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @returns The callback output once it passes.
|
|
397
|
+
* @throws {@link AssertionError} On timeout.
|
|
398
|
+
* @see
|
|
399
|
+
* - {@link waitUntil.isFalsy} : the opposite assertion.
|
|
400
|
+
* - {@link waitUntil.isTrue} : a more exact assertion.
|
|
401
|
+
*/
|
|
45
402
|
isTruthy: autoGuard(),
|
|
46
403
|
},
|
|
47
404
|
};
|