@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
|
@@ -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 isNotArray(actual, failureMessage) {
|
|
5
5
|
assertNotRuntimeType(actual, 'array', failureMessage);
|
|
6
6
|
}
|
|
@@ -45,6 +45,9 @@ function isFunction(actual, failureMessage) {
|
|
|
45
45
|
}
|
|
46
46
|
function isNumber(actual, failureMessage) {
|
|
47
47
|
assertRuntimeType(actual, 'number', failureMessage);
|
|
48
|
+
if (isNaN(actual)) {
|
|
49
|
+
throw new AssertionError('Value is NaN.', failureMessage);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
function isObject(actual, failureMessage) {
|
|
50
53
|
assertRuntimeType(actual, 'object', failureMessage);
|
|
@@ -76,30 +79,540 @@ const assertions = {
|
|
|
76
79
|
isNotBigInt,
|
|
77
80
|
isNotBoolean,
|
|
78
81
|
isNotFunction,
|
|
82
|
+
isNotNull,
|
|
79
83
|
isNotNumber,
|
|
80
84
|
isNotObject,
|
|
81
85
|
isNotString,
|
|
82
86
|
isNotSymbol,
|
|
83
87
|
isNotUndefined,
|
|
84
|
-
isNotNull,
|
|
85
88
|
};
|
|
86
89
|
export const runtimeTypeGuards = {
|
|
87
|
-
assertions,
|
|
88
|
-
|
|
90
|
+
assert: assertions,
|
|
91
|
+
check: {
|
|
92
|
+
/**
|
|
93
|
+
* Checks that a value is an array.
|
|
94
|
+
*
|
|
95
|
+
* Type guards the value.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* import {check} from '@augment-vir/assert';
|
|
101
|
+
*
|
|
102
|
+
* check.isArray([]); // returns `true`
|
|
103
|
+
* check.isArray({length: 4}); // returns `false`
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @see
|
|
107
|
+
* - {@link check.isNotArray} : the opposite check.
|
|
108
|
+
*/
|
|
109
|
+
isArray: autoGuardSymbol,
|
|
110
|
+
/**
|
|
111
|
+
* Checks that a value is a BigInt.
|
|
112
|
+
*
|
|
113
|
+
* Type guards the value.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* import {check} from '@augment-vir/assert';
|
|
119
|
+
*
|
|
120
|
+
* check.isBigInt(123n); // returns `true`
|
|
121
|
+
* check.isBigInt(123); // returns `false`
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @see
|
|
125
|
+
* - {@link check.isNotBigInt} : the opposite check.
|
|
126
|
+
*/
|
|
127
|
+
isBigInt: autoGuardSymbol,
|
|
128
|
+
/**
|
|
129
|
+
* Checks that a value is a boolean.
|
|
130
|
+
*
|
|
131
|
+
* Type guards the value.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* import {check} from '@augment-vir/assert';
|
|
137
|
+
*
|
|
138
|
+
* check.isBoolean(true); // returns `true`
|
|
139
|
+
* check.isBoolean('true'); // returns `false`
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @see
|
|
143
|
+
* - {@link check.isNotBoolean} : the opposite check.
|
|
144
|
+
*/
|
|
145
|
+
isBoolean: autoGuardSymbol,
|
|
146
|
+
/**
|
|
147
|
+
* Checks that a value is a function.
|
|
148
|
+
*
|
|
149
|
+
* Type guards the value.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
*
|
|
153
|
+
* ```ts
|
|
154
|
+
* import {check} from '@augment-vir/assert';
|
|
155
|
+
*
|
|
156
|
+
* check.isFunction(() => {}); // returns `true`
|
|
157
|
+
* check.isFunction({}); // returns `false`
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @see
|
|
161
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
162
|
+
*/
|
|
89
163
|
isFunction: autoGuard(),
|
|
164
|
+
/**
|
|
165
|
+
* Checks that a value is exactly `null`.
|
|
166
|
+
*
|
|
167
|
+
* Type guards the value.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* import {check} from '@augment-vir/assert';
|
|
173
|
+
*
|
|
174
|
+
* check.isNull(null); // returns `true`
|
|
175
|
+
* check.isNull(undefined); // returns `false`
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @see
|
|
179
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
180
|
+
*/
|
|
181
|
+
isNull: autoGuardSymbol,
|
|
182
|
+
/**
|
|
183
|
+
* Checks that a value is a number. This excludes `NaN`.
|
|
184
|
+
*
|
|
185
|
+
* Type guards the value.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import {check} from '@augment-vir/assert';
|
|
191
|
+
*
|
|
192
|
+
* check.isNumber(123); // returns `true`
|
|
193
|
+
* check.isNumber(123n); // returns `false`
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @see
|
|
197
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
198
|
+
*/
|
|
199
|
+
isNumber: autoGuardSymbol,
|
|
200
|
+
/**
|
|
201
|
+
* Checks that a value is an object. This excludes arrays.
|
|
202
|
+
*
|
|
203
|
+
* Type guards the value.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* import {check} from '@augment-vir/assert';
|
|
209
|
+
*
|
|
210
|
+
* check.isObject({}); // returns `true`
|
|
211
|
+
* check.isObject([]); // returns `false`
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @see
|
|
215
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
216
|
+
*/
|
|
217
|
+
isObject: autoGuardSymbol,
|
|
218
|
+
/**
|
|
219
|
+
* Checks that a value is a string.
|
|
220
|
+
*
|
|
221
|
+
* Type guards the value.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* import {check} from '@augment-vir/assert';
|
|
227
|
+
*
|
|
228
|
+
* check.isString(''); // returns `true`
|
|
229
|
+
* check.isString(5); // returns `false`
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @see
|
|
233
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
234
|
+
*/
|
|
235
|
+
isString: autoGuardSymbol,
|
|
236
|
+
/**
|
|
237
|
+
* Checks that a value is a symbol.
|
|
238
|
+
*
|
|
239
|
+
* Type guards the value.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* import {check} from '@augment-vir/assert';
|
|
245
|
+
*
|
|
246
|
+
* check.isSymbol(Symbol('my-symbol')); // returns `true`
|
|
247
|
+
* check.isSymbol('my-symbol'); // returns `false`
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @see
|
|
251
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
252
|
+
*/
|
|
253
|
+
isSymbol: autoGuardSymbol,
|
|
254
|
+
/**
|
|
255
|
+
* Checks that a value is exactly `undefined`.
|
|
256
|
+
*
|
|
257
|
+
* Type guards the value.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
*
|
|
261
|
+
* ```ts
|
|
262
|
+
* import {check} from '@augment-vir/assert';
|
|
263
|
+
*
|
|
264
|
+
* check.isUndefined(undefined); // returns `true`
|
|
265
|
+
* check.isUndefined(null); // returns `false`
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @see
|
|
269
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
270
|
+
*/
|
|
271
|
+
isUndefined: autoGuardSymbol,
|
|
272
|
+
/**
|
|
273
|
+
* Checks that a value is _not_ an array.
|
|
274
|
+
*
|
|
275
|
+
* Type guards the value.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
*
|
|
279
|
+
* ```ts
|
|
280
|
+
* import {check} from '@augment-vir/assert';
|
|
281
|
+
*
|
|
282
|
+
* check.isNotArray([]); // returns `false`
|
|
283
|
+
* check.isNotArray({length: 4}); // returns `true`
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @see
|
|
287
|
+
* - {@link check.isArray} : the opposite check.
|
|
288
|
+
*/
|
|
90
289
|
isNotArray: autoGuard(),
|
|
290
|
+
/**
|
|
291
|
+
* Checks that a value is _not_ a BigInt.
|
|
292
|
+
*
|
|
293
|
+
* Type guards the value.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
*
|
|
297
|
+
* ```ts
|
|
298
|
+
* import {check} from '@augment-vir/assert';
|
|
299
|
+
*
|
|
300
|
+
* check.isNotBigInt(123n); // returns `false`
|
|
301
|
+
* check.isNotBigInt(123); // returns `true`
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @see
|
|
305
|
+
* - {@link check.isBigInt} : the opposite check.
|
|
306
|
+
*/
|
|
91
307
|
isNotBigInt: autoGuard(),
|
|
308
|
+
/**
|
|
309
|
+
* Checks that a value is _not_ a boolean.
|
|
310
|
+
*
|
|
311
|
+
* Type guards the value.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* import {check} from '@augment-vir/assert';
|
|
317
|
+
*
|
|
318
|
+
* check.isNotBoolean(true); // returns `false`
|
|
319
|
+
* check.isNotBoolean('true'); // returns `true`
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* @see
|
|
323
|
+
* - {@link check.isBoolean} : the opposite check.
|
|
324
|
+
*/
|
|
92
325
|
isNotBoolean: autoGuard(),
|
|
326
|
+
/**
|
|
327
|
+
* Checks that a value is _not_ a function.
|
|
328
|
+
*
|
|
329
|
+
* Type guards the value.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* import {check} from '@augment-vir/assert';
|
|
335
|
+
*
|
|
336
|
+
* check.isNotFunction(() => {}); // returns `false`
|
|
337
|
+
* check.isNotFunction({}); // returns `true`
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @see
|
|
341
|
+
* - {@link check.isFunction} : the opposite check.
|
|
342
|
+
*/
|
|
93
343
|
isNotFunction: autoGuard(),
|
|
344
|
+
/**
|
|
345
|
+
* Checks that a value is _not_ exactly `null`.
|
|
346
|
+
*
|
|
347
|
+
* Type guards the value.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* import {check} from '@augment-vir/assert';
|
|
353
|
+
*
|
|
354
|
+
* check.isNotNull(null); // returns `false`
|
|
355
|
+
* check.isNotNull(undefined); // returns `true`
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* @see
|
|
359
|
+
* - {@link check.isFunction} : the opposite check.
|
|
360
|
+
*/
|
|
94
361
|
isNotNull: autoGuard(),
|
|
362
|
+
/**
|
|
363
|
+
* Checks that a value is _not_ a number. This includes `NaN`.
|
|
364
|
+
*
|
|
365
|
+
* Type guards the value.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* import {check} from '@augment-vir/assert';
|
|
371
|
+
*
|
|
372
|
+
* check.isNotNumber(123); // returns `false`
|
|
373
|
+
* check.isNotNumber(123n); // returns `true`
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @see
|
|
377
|
+
* - {@link check.isNotFunction} : the opposite check.
|
|
378
|
+
*/
|
|
95
379
|
isNotNumber: autoGuard(),
|
|
380
|
+
/**
|
|
381
|
+
* Checks that a value is _not_ an object. This includes arrays.
|
|
382
|
+
*
|
|
383
|
+
* Type guards the value.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
*
|
|
387
|
+
* ```ts
|
|
388
|
+
* import {check} from '@augment-vir/assert';
|
|
389
|
+
*
|
|
390
|
+
* check.isNotObject({}); // returns `false`
|
|
391
|
+
* check.isNotObject([]); // returns `true`
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @see
|
|
395
|
+
* - {@link check.isFunction} : the opposite check.
|
|
396
|
+
*/
|
|
96
397
|
isNotObject: autoGuard(),
|
|
398
|
+
/**
|
|
399
|
+
* Checks that a value is _not_ a string.
|
|
400
|
+
*
|
|
401
|
+
* Type guards the value.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
*
|
|
405
|
+
* ```ts
|
|
406
|
+
* import {check} from '@augment-vir/assert';
|
|
407
|
+
*
|
|
408
|
+
* check.isNotString(''); // returns `false`
|
|
409
|
+
* check.isNotString(5); // returns `true`
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @see
|
|
413
|
+
* - {@link check.isFunction} : the opposite check.
|
|
414
|
+
*/
|
|
97
415
|
isNotString: autoGuard(),
|
|
98
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Checks that a value is _not_ a symbol.
|
|
418
|
+
*
|
|
419
|
+
* Type guards the value.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
*
|
|
423
|
+
* ```ts
|
|
424
|
+
* import {check} from '@augment-vir/assert';
|
|
425
|
+
*
|
|
426
|
+
* check.isNotSymbol(Symbol('my-symbol')); // returns `false`
|
|
427
|
+
* check.isNotSymbol('my-symbol'); // returns `true`
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* @see
|
|
431
|
+
* - {@link check.isFunction} : the opposite check.
|
|
432
|
+
*/
|
|
99
433
|
isNotSymbol: autoGuard(),
|
|
434
|
+
/**
|
|
435
|
+
* Checks that a value is _not_ exactly `undefined`.
|
|
436
|
+
*
|
|
437
|
+
* Type guards the value.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
*
|
|
441
|
+
* ```ts
|
|
442
|
+
* import {check} from '@augment-vir/assert';
|
|
443
|
+
*
|
|
444
|
+
* check.isNotUndefined(undefined); // returns `false`
|
|
445
|
+
* check.isNotUndefined(null); // returns `true`
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @see
|
|
449
|
+
* - {@link check.isFunction} : the opposite check.
|
|
450
|
+
*/
|
|
451
|
+
isNotUndefined: autoGuard(),
|
|
100
452
|
},
|
|
101
|
-
|
|
453
|
+
assertWrap: {
|
|
454
|
+
/**
|
|
455
|
+
* Asserts that a value is an array. Returns the value if the assertion passes.
|
|
456
|
+
*
|
|
457
|
+
* Type guards the value.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
*
|
|
461
|
+
* ```ts
|
|
462
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
463
|
+
*
|
|
464
|
+
* assertWrap.isArray([]); // returns `[]`
|
|
465
|
+
* assertWrap.isArray({length: 4}); // throws an error
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* @returns The value if the assertion passes.
|
|
469
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
470
|
+
* @see
|
|
471
|
+
* - {@link assertWrap.isNotArray} : the opposite assertion.
|
|
472
|
+
*/
|
|
473
|
+
isArray: autoGuardSymbol,
|
|
474
|
+
/**
|
|
475
|
+
* Asserts that a value is a BigInt. Returns the value if the assertion passes.
|
|
476
|
+
*
|
|
477
|
+
* Type guards the value.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
*
|
|
481
|
+
* ```ts
|
|
482
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
483
|
+
*
|
|
484
|
+
* assertWrap.isBigInt(123n); // returns `123n`
|
|
485
|
+
* assertWrap.isBigInt(123); // throws an error
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @returns The value if the assertion passes.
|
|
489
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
490
|
+
* @see
|
|
491
|
+
* - {@link assertWrap.isNotBigInt} : the opposite assertion.
|
|
492
|
+
*/
|
|
493
|
+
isBigInt: autoGuardSymbol,
|
|
494
|
+
/**
|
|
495
|
+
* Asserts that a value is a boolean. Returns the value if the assertion passes.
|
|
496
|
+
*
|
|
497
|
+
* Type guards the value.
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
*
|
|
501
|
+
* ```ts
|
|
502
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
503
|
+
*
|
|
504
|
+
* assertWrap.isBoolean(true); // returns `true`
|
|
505
|
+
* assertWrap.isBoolean('true'); // throws an error
|
|
506
|
+
* ```
|
|
507
|
+
*
|
|
508
|
+
* @returns The value if the assertion passes.
|
|
509
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
510
|
+
* @see
|
|
511
|
+
* - {@link assertWrap.isNotBoolean} : the opposite assertion.
|
|
512
|
+
*/
|
|
513
|
+
isBoolean: autoGuardSymbol,
|
|
514
|
+
/**
|
|
515
|
+
* Asserts that a value is a function. Returns the value if the assertion passes.
|
|
516
|
+
*
|
|
517
|
+
* Type guards the value.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
*
|
|
521
|
+
* ```ts
|
|
522
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
523
|
+
*
|
|
524
|
+
* assertWrap.isFunction(() => {}); // returns `() => {}`
|
|
525
|
+
* assertWrap.isFunction({}); // throws an error
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @returns The value if the assertion passes.
|
|
529
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
530
|
+
* @see
|
|
531
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
532
|
+
*/
|
|
102
533
|
isFunction: autoGuard(),
|
|
534
|
+
/**
|
|
535
|
+
* Asserts that a value is exactly `null. Returns the value if the assertion passes.
|
|
536
|
+
*
|
|
537
|
+
* Type guards the value.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
*
|
|
541
|
+
* ```ts
|
|
542
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
543
|
+
*
|
|
544
|
+
* assertWrap.isNull(null); // returns `null`
|
|
545
|
+
* assertWrap.isNull(undefined); // throws an error
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* @returns The value if the assertion passes.
|
|
549
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
550
|
+
* @see
|
|
551
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
552
|
+
*/
|
|
553
|
+
isNull: autoGuardSymbol,
|
|
554
|
+
/**
|
|
555
|
+
* Asserts that a value is a number. This excludes `NaN. Returns the value if the assertion
|
|
556
|
+
* passes.
|
|
557
|
+
*
|
|
558
|
+
* Type guards the value.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
*
|
|
562
|
+
* ```ts
|
|
563
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
564
|
+
*
|
|
565
|
+
* assertWrap.isNumber(123); // returns `123`
|
|
566
|
+
* assertWrap.isNumber(123n); // throws an error
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* @returns The value if the assertion passes.
|
|
570
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
571
|
+
* @see
|
|
572
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
573
|
+
*/
|
|
574
|
+
isNumber: autoGuardSymbol,
|
|
575
|
+
/**
|
|
576
|
+
* Asserts that a value is an object. This excludes arrays. Returns the value if the
|
|
577
|
+
* assertion passes.
|
|
578
|
+
*
|
|
579
|
+
* Type guards the value.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
*
|
|
583
|
+
* ```ts
|
|
584
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
585
|
+
*
|
|
586
|
+
* assertWrap.isObject({}); // returns `{}`
|
|
587
|
+
* assertWrap.isObject([]); // throws an error
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @returns The value if the assertion passes.
|
|
591
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
592
|
+
* @see
|
|
593
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
594
|
+
*/
|
|
595
|
+
isObject: autoGuardSymbol,
|
|
596
|
+
/**
|
|
597
|
+
* Asserts that a value is a string. Returns the value if the assertion passes.
|
|
598
|
+
*
|
|
599
|
+
* Type guards the value.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
*
|
|
603
|
+
* ```ts
|
|
604
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
605
|
+
*
|
|
606
|
+
* assertWrap.isString(''); // returns `''`
|
|
607
|
+
* assertWrap.isString(5); // throws an error
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* @returns The value if the assertion passes.
|
|
611
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
612
|
+
* @see
|
|
613
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
614
|
+
*/
|
|
615
|
+
isString: autoGuardSymbol,
|
|
103
616
|
/**
|
|
104
617
|
* Trying to assign a unique symbol to another variable kills the `unique` part of the
|
|
105
618
|
* symbol. this seems to be a bug with TypeScript itself.
|
|
@@ -109,53 +622,1061 @@ export const runtimeTypeGuards = {
|
|
|
109
622
|
* @example Const mySymbol = Symbol('mine'); const mySymbol2 = mySymbol; // this is no
|
|
110
623
|
* longer `unique symbol`
|
|
111
624
|
*/
|
|
625
|
+
/**
|
|
626
|
+
* Asserts that a value is a symbol. Returns the value if the assertion passes.
|
|
627
|
+
*
|
|
628
|
+
* Type guards the value.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
*
|
|
632
|
+
* ```ts
|
|
633
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
634
|
+
*
|
|
635
|
+
* assertWrap.isSymbol(Symbol('my-symbol')); // returns the created symbol
|
|
636
|
+
* assertWrap.isSymbol('my-symbol'); // throws an error
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @returns The value if the assertion passes.
|
|
640
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
641
|
+
* @see
|
|
642
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
643
|
+
*/
|
|
112
644
|
isSymbol: autoGuard(),
|
|
113
|
-
isNotArray: autoGuard(),
|
|
114
|
-
isNotBigInt: autoGuard(),
|
|
115
|
-
isNotBoolean: autoGuard(),
|
|
116
|
-
isNotFunction: autoGuard(),
|
|
117
|
-
isNotNull: autoGuard(),
|
|
118
|
-
isNotNumber: autoGuard(),
|
|
119
|
-
isNotObject: autoGuard(),
|
|
120
|
-
isNotString: autoGuard(),
|
|
121
|
-
isNotUndefined: autoGuard(),
|
|
122
|
-
isNotSymbol: autoGuard(),
|
|
123
|
-
},
|
|
124
|
-
checkWrapOverrides: {
|
|
125
|
-
isFunction: autoGuard(),
|
|
126
645
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
646
|
+
* Asserts that a value is exactly `undefined. Returns the value if the assertion passes.
|
|
647
|
+
*
|
|
648
|
+
* Type guards the value.
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
*
|
|
652
|
+
* ```ts
|
|
653
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
654
|
+
*
|
|
655
|
+
* assertWrap.isUndefined(undefined); // returns `undefined`
|
|
656
|
+
* assertWrap.isUndefined(null); // throws an error
|
|
657
|
+
* ```
|
|
658
|
+
*
|
|
659
|
+
* @returns The value if the assertion passes.
|
|
660
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
661
|
+
* @see
|
|
662
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
130
663
|
*/
|
|
131
|
-
isUndefined:
|
|
664
|
+
isUndefined: autoGuardSymbol,
|
|
132
665
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
666
|
+
* Asserts that a value is _not_ an array. Returns the value if the assertion passes.
|
|
667
|
+
*
|
|
668
|
+
* Type guards the value.
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
*
|
|
672
|
+
* ```ts
|
|
673
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
674
|
+
*
|
|
675
|
+
* assertWrap.isNotArray([]); // throws an error
|
|
676
|
+
* assertWrap.isNotArray({length: 4}); // returns `{length: 4}`
|
|
677
|
+
* ```
|
|
678
|
+
*
|
|
679
|
+
* @returns The value if the assertion passes.
|
|
680
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
681
|
+
* @see
|
|
682
|
+
* - {@link assertWrap.isArray} : the opposite assertion.
|
|
135
683
|
*/
|
|
136
|
-
isNotUndefined: undefined,
|
|
137
684
|
isNotArray: autoGuard(),
|
|
685
|
+
/**
|
|
686
|
+
* Asserts that a value is _not_ a BigInt. Returns the value if the assertion passes.
|
|
687
|
+
*
|
|
688
|
+
* Type guards the value.
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
*
|
|
692
|
+
* ```ts
|
|
693
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
694
|
+
*
|
|
695
|
+
* assertWrap.isNotBigInt(123n); // throws an error
|
|
696
|
+
* assertWrap.isNotBigInt(123); // returns `123`
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @returns The value if the assertion passes.
|
|
700
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
701
|
+
* @see
|
|
702
|
+
* - {@link assertWrap.isBigInt} : the opposite assertion.
|
|
703
|
+
*/
|
|
138
704
|
isNotBigInt: autoGuard(),
|
|
705
|
+
/**
|
|
706
|
+
* Asserts that a value is _not_ a boolean. Returns the value if the assertion passes.
|
|
707
|
+
*
|
|
708
|
+
* Type guards the value.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
*
|
|
712
|
+
* ```ts
|
|
713
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
714
|
+
*
|
|
715
|
+
* assertWrap.isNotBoolean(true); // throws an error
|
|
716
|
+
* assertWrap.isNotBoolean('true'); // returns `'true'`
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* @returns The value if the assertion passes.
|
|
720
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
721
|
+
* @see
|
|
722
|
+
* - {@link assertWrap.isBoolean} : the opposite assertion.
|
|
723
|
+
*/
|
|
139
724
|
isNotBoolean: autoGuard(),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
725
|
+
/**
|
|
726
|
+
* Asserts that a value is _not_ a function. Returns the value if the assertion passes.
|
|
727
|
+
*
|
|
728
|
+
* Type guards the value.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
*
|
|
732
|
+
* ```ts
|
|
733
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
734
|
+
*
|
|
735
|
+
* assertWrap.isNotFunction(() => {}); // throws an error
|
|
736
|
+
* assertWrap.isNotFunction({}); // returns `{}`
|
|
737
|
+
* ```
|
|
738
|
+
*
|
|
739
|
+
* @returns The value if the assertion passes.
|
|
740
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
741
|
+
* @see
|
|
742
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
743
|
+
*/
|
|
744
|
+
isNotFunction: autoGuard(),
|
|
745
|
+
/**
|
|
746
|
+
* Asserts that a value is _not_ exactly `null. Returns the value if the assertion passes.
|
|
747
|
+
*
|
|
748
|
+
* Type guards the value.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
*
|
|
752
|
+
* ```ts
|
|
753
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
754
|
+
*
|
|
755
|
+
* assertWrap.isNotNull(null); // throws an error
|
|
756
|
+
* assertWrap.isNotNull(undefined); // returns `undefined`
|
|
757
|
+
* ```
|
|
758
|
+
*
|
|
759
|
+
* @returns The value if the assertion passes.
|
|
760
|
+
* @throws {@link AssertionError} If the assertion failed. @see
|
|
761
|
+
* @see
|
|
762
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
763
|
+
*/
|
|
764
|
+
isNotNull: autoGuard(),
|
|
765
|
+
/**
|
|
766
|
+
* Asserts that a value is _not_ a number. This includes `NaN. Returns the value if the
|
|
767
|
+
* assertion passes.
|
|
768
|
+
*
|
|
769
|
+
* Type guards the value.
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
*
|
|
773
|
+
* ```ts
|
|
774
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
775
|
+
*
|
|
776
|
+
* assertWrap.isNotNumber(123); // throws an error
|
|
777
|
+
* assertWrap.isNotNumber(123n); // returns `123n`
|
|
778
|
+
* ```
|
|
779
|
+
*
|
|
780
|
+
* @returns The value if the assertion passes.
|
|
781
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
782
|
+
* @see
|
|
783
|
+
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
784
|
+
*/
|
|
785
|
+
isNotNumber: autoGuard(),
|
|
786
|
+
/**
|
|
787
|
+
* Asserts that a value is _not_ an object. This includes arrays. Returns the value if the
|
|
788
|
+
* assertion passes.
|
|
789
|
+
*
|
|
790
|
+
* Type guards the value.
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
*
|
|
794
|
+
* ```ts
|
|
795
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
796
|
+
*
|
|
797
|
+
* assertWrap.isNotObject({}); // throws an error
|
|
798
|
+
* assertWrap.isNotObject([]); // returns `[]`
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @returns The value if the assertion passes.
|
|
802
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
803
|
+
* @see
|
|
804
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
805
|
+
*/
|
|
806
|
+
isNotObject: autoGuard(),
|
|
807
|
+
/**
|
|
808
|
+
* Asserts that a value is _not_ a string. Returns the value if the assertion passes.
|
|
809
|
+
*
|
|
810
|
+
* Type guards the value.
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
*
|
|
814
|
+
* ```ts
|
|
815
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
816
|
+
*
|
|
817
|
+
* assertWrap.isNotString(''); // throws an error
|
|
818
|
+
* assertWrap.isNotString(5); // returns `5`
|
|
819
|
+
* ```
|
|
820
|
+
*
|
|
821
|
+
* @returns The value if the assertion passes.
|
|
822
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
823
|
+
* @see
|
|
824
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
825
|
+
*/
|
|
826
|
+
isNotString: autoGuard(),
|
|
827
|
+
/**
|
|
828
|
+
* Asserts that a value is _not_ a symbol. Returns the value if the assertion passes.
|
|
829
|
+
*
|
|
830
|
+
* Type guards the value.
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
*
|
|
834
|
+
* ```ts
|
|
835
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
836
|
+
*
|
|
837
|
+
* assertWrap.isNotSymbol(Symbol('my-symbol')); // throws an error
|
|
838
|
+
* assertWrap.isNotSymbol('my-symbol'); // returns `'my-symbol'`
|
|
839
|
+
* ```
|
|
840
|
+
*
|
|
841
|
+
* @returns The value if the assertion passes.
|
|
842
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
843
|
+
* @see
|
|
844
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
845
|
+
*/
|
|
145
846
|
isNotSymbol: autoGuard(),
|
|
847
|
+
/**
|
|
848
|
+
* Asserts that a value is _not_ exactly `undefined. Returns the value if the assertion
|
|
849
|
+
* passes.
|
|
850
|
+
*
|
|
851
|
+
* Type guards the value.
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
*
|
|
855
|
+
* ```ts
|
|
856
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
857
|
+
*
|
|
858
|
+
* assertWrap.isNotUndefined(undefined); // throws an error
|
|
859
|
+
* assertWrap.isNotUndefined(null); // returns `null`
|
|
860
|
+
* ```
|
|
861
|
+
*
|
|
862
|
+
* @returns The value if the assertion passes.
|
|
863
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
864
|
+
* @see
|
|
865
|
+
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
866
|
+
*/
|
|
867
|
+
isNotUndefined: autoGuard(),
|
|
146
868
|
},
|
|
147
|
-
|
|
869
|
+
checkWrap: {
|
|
870
|
+
/**
|
|
871
|
+
* Checks that a value is an array. Returns the value if the check passes, otherwise
|
|
872
|
+
* `undefined`.
|
|
873
|
+
*
|
|
874
|
+
* Type guards the value.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
*
|
|
878
|
+
* ```ts
|
|
879
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
880
|
+
*
|
|
881
|
+
* checkWrap.isArray([]); // returns `[]`
|
|
882
|
+
* checkWrap.isArray({length: 4}); // returns `undefined`
|
|
883
|
+
* ```
|
|
884
|
+
*
|
|
885
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
886
|
+
* @see
|
|
887
|
+
* - {@link checkWrap.isNotArray} : the opposite check.
|
|
888
|
+
*/
|
|
889
|
+
isArray: autoGuardSymbol,
|
|
890
|
+
/**
|
|
891
|
+
* Checks that a value is a BigInt. Returns the value if the check passes, otherwise
|
|
892
|
+
* `undefined`.
|
|
893
|
+
*
|
|
894
|
+
* Type guards the value.
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
*
|
|
898
|
+
* ```ts
|
|
899
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
900
|
+
*
|
|
901
|
+
* checkWrap.isBigInt(123n); // returns `123n`
|
|
902
|
+
* checkWrap.isBigInt(123); // returns `undefined`
|
|
903
|
+
* ```
|
|
904
|
+
*
|
|
905
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
906
|
+
* @see
|
|
907
|
+
* - {@link checkWrap.isNotBigInt} : the opposite check.
|
|
908
|
+
*/
|
|
909
|
+
isBigInt: autoGuardSymbol,
|
|
910
|
+
/**
|
|
911
|
+
* Checks that a value is a boolean. Returns the value if the check passes, otherwise
|
|
912
|
+
* `undefined`.
|
|
913
|
+
*
|
|
914
|
+
* Type guards the value.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
*
|
|
918
|
+
* ```ts
|
|
919
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
920
|
+
*
|
|
921
|
+
* checkWrap.isBoolean(true); // returns `true`
|
|
922
|
+
* checkWrap.isBoolean('true'); // returns `undefined`
|
|
923
|
+
* ```
|
|
924
|
+
*
|
|
925
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
926
|
+
* @see
|
|
927
|
+
* - {@link checkWrap.isNotBoolean} : the opposite check.
|
|
928
|
+
*/
|
|
929
|
+
isBoolean: autoGuardSymbol,
|
|
930
|
+
/**
|
|
931
|
+
* Checks that a value is a function. Returns the value if the check passes, otherwise
|
|
932
|
+
* `undefined`.
|
|
933
|
+
*
|
|
934
|
+
* Type guards the value.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
*
|
|
938
|
+
* ```ts
|
|
939
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
940
|
+
*
|
|
941
|
+
* checkWrap.isFunction(() => {}); // returns `() => {}`
|
|
942
|
+
* checkWrap.isFunction({}); // returns `undefined`
|
|
943
|
+
* ```
|
|
944
|
+
*
|
|
945
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
946
|
+
* @see
|
|
947
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
948
|
+
*/
|
|
148
949
|
isFunction: autoGuard(),
|
|
950
|
+
/**
|
|
951
|
+
* Checks that a value is exactly `null. Returns the value if the check passes, otherwise
|
|
952
|
+
* `undefined`.
|
|
953
|
+
*
|
|
954
|
+
* Type guards the value.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
*
|
|
958
|
+
* ```ts
|
|
959
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
960
|
+
*
|
|
961
|
+
* checkWrap.isNull(null); // returns `null`
|
|
962
|
+
* checkWrap.isNull(undefined); // returns `undefined`
|
|
963
|
+
* ```
|
|
964
|
+
*
|
|
965
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
966
|
+
* @see
|
|
967
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
968
|
+
*/
|
|
969
|
+
isNull: autoGuardSymbol,
|
|
970
|
+
/**
|
|
971
|
+
* Checks that a value is a number. This excludes `NaN. Returns the value if the check
|
|
972
|
+
* passes, otherwise `undefined`.
|
|
973
|
+
*
|
|
974
|
+
* Type guards the value.
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
*
|
|
978
|
+
* ```ts
|
|
979
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
980
|
+
*
|
|
981
|
+
* checkWrap.isNumber(123); // returns `123`
|
|
982
|
+
* checkWrap.isNumber(123n); // returns `undefined`
|
|
983
|
+
* ```
|
|
984
|
+
*
|
|
985
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
986
|
+
* @see
|
|
987
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
988
|
+
*/
|
|
989
|
+
isNumber: autoGuardSymbol,
|
|
990
|
+
/**
|
|
991
|
+
* Checks that a value is an object. This excludes arrays. Returns the value if the check
|
|
992
|
+
* passes, otherwise `undefined`.
|
|
993
|
+
*
|
|
994
|
+
* Type guards the value.
|
|
995
|
+
*
|
|
996
|
+
* @example
|
|
997
|
+
*
|
|
998
|
+
* ```ts
|
|
999
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1000
|
+
*
|
|
1001
|
+
* checkWrap.isObject({}); // returns `{}`
|
|
1002
|
+
* checkWrap.isObject([]); // returns `undefined`
|
|
1003
|
+
* ```
|
|
1004
|
+
*
|
|
1005
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1006
|
+
* @see
|
|
1007
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1008
|
+
*/
|
|
1009
|
+
isObject: autoGuardSymbol,
|
|
1010
|
+
/**
|
|
1011
|
+
* Checks that a value is a string. Returns the value if the check passes, otherwise
|
|
1012
|
+
* `undefined`.
|
|
1013
|
+
*
|
|
1014
|
+
* Type guards the value.
|
|
1015
|
+
*
|
|
1016
|
+
* @example
|
|
1017
|
+
*
|
|
1018
|
+
* ```ts
|
|
1019
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1020
|
+
*
|
|
1021
|
+
* checkWrap.isString(''); // returns `''`
|
|
1022
|
+
* checkWrap.isString(5); // returns `undefined`
|
|
1023
|
+
* ```
|
|
1024
|
+
*
|
|
1025
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1026
|
+
* @see
|
|
1027
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1028
|
+
*/
|
|
1029
|
+
isString: autoGuardSymbol,
|
|
1030
|
+
/**
|
|
1031
|
+
* Checks that a value is a symbol. Returns the value if the check passes, otherwise
|
|
1032
|
+
* `undefined`.
|
|
1033
|
+
*
|
|
1034
|
+
* Type guards the value.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
*
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1040
|
+
*
|
|
1041
|
+
* checkWrap.isSymbol(Symbol('my-symbol')); // returns the created symbol
|
|
1042
|
+
* checkWrap.isSymbol('my-symbol'); // returns `undefined`
|
|
1043
|
+
* ```
|
|
1044
|
+
*
|
|
1045
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1046
|
+
* @see
|
|
1047
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1048
|
+
*/
|
|
1049
|
+
isSymbol: autoGuardSymbol,
|
|
1050
|
+
/**
|
|
1051
|
+
* It doesn't make any sense for `checkWrap.isUndefined` to exist. If the input is
|
|
1052
|
+
* `undefined`, it returns `undefined`. If the input isn't `undefined`, it still returns
|
|
1053
|
+
* `undefined`.
|
|
1054
|
+
*/
|
|
1055
|
+
/**
|
|
1056
|
+
* Checks that a value is exactly `undefined. Returns the value if the check passes,
|
|
1057
|
+
* otherwise `undefined`.
|
|
1058
|
+
*
|
|
1059
|
+
* Type guards the value.
|
|
1060
|
+
*
|
|
1061
|
+
* @example
|
|
1062
|
+
*
|
|
1063
|
+
* ```ts
|
|
1064
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1065
|
+
*
|
|
1066
|
+
* checkWrap.isUndefined(undefined); // returns `undefined`
|
|
1067
|
+
* checkWrap.isUndefined(null); // returns `undefined`
|
|
1068
|
+
* ```
|
|
1069
|
+
*
|
|
1070
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1071
|
+
* @see
|
|
1072
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1073
|
+
*/
|
|
1074
|
+
isUndefined: undefined,
|
|
1075
|
+
/**
|
|
1076
|
+
* Checks that a value is _not_ an array. Returns the value if the check passes, otherwise
|
|
1077
|
+
* `undefined`.
|
|
1078
|
+
*
|
|
1079
|
+
* Type guards the value.
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
*
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1085
|
+
*
|
|
1086
|
+
* checkWrap.isNotArray([]); // returns `undefined`
|
|
1087
|
+
* checkWrap.isNotArray({length: 4}); // returns `{length: 4}`
|
|
1088
|
+
* ```
|
|
1089
|
+
*
|
|
1090
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1091
|
+
* @see
|
|
1092
|
+
* - {@link checkWrap.isArray} : the opposite check.
|
|
1093
|
+
*/
|
|
149
1094
|
isNotArray: autoGuard(),
|
|
1095
|
+
/**
|
|
1096
|
+
* Checks that a value is _not_ a BigInt. Returns the value if the check passes, otherwise
|
|
1097
|
+
* `undefined`.
|
|
1098
|
+
*
|
|
1099
|
+
* Type guards the value.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
*
|
|
1103
|
+
* ```ts
|
|
1104
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1105
|
+
*
|
|
1106
|
+
* checkWrap.isNotBigInt(123n); // returns `undefined`
|
|
1107
|
+
* checkWrap.isNotBigInt(123); // returns `123`
|
|
1108
|
+
* ```
|
|
1109
|
+
*
|
|
1110
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1111
|
+
* @see
|
|
1112
|
+
* - {@link checkWrap.isBigInt} : the opposite check.
|
|
1113
|
+
*/
|
|
150
1114
|
isNotBigInt: autoGuard(),
|
|
1115
|
+
/**
|
|
1116
|
+
* Checks that a value is _not_ a boolean. Returns the value if the check passes, otherwise
|
|
1117
|
+
* `undefined`.
|
|
1118
|
+
*
|
|
1119
|
+
* Type guards the value.
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
*
|
|
1123
|
+
* ```ts
|
|
1124
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1125
|
+
*
|
|
1126
|
+
* checkWrap.isNotBoolean(true); // returns `undefined`
|
|
1127
|
+
* checkWrap.isNotBoolean('true'); // returns `'true'`
|
|
1128
|
+
* ```
|
|
1129
|
+
*
|
|
1130
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1131
|
+
* @see
|
|
1132
|
+
* - {@link checkWrap.isBoolean} : the opposite check.
|
|
1133
|
+
*/
|
|
151
1134
|
isNotBoolean: autoGuard(),
|
|
1135
|
+
/**
|
|
1136
|
+
* Checks that a value is _not_ a function. Returns the value if the check passes, otherwise
|
|
1137
|
+
* `undefined`.
|
|
1138
|
+
*
|
|
1139
|
+
* Type guards the value.
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
*
|
|
1143
|
+
* ```ts
|
|
1144
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1145
|
+
*
|
|
1146
|
+
* checkWrap.isNotFunction(() => {}); // returns `undefined`
|
|
1147
|
+
* checkWrap.isNotFunction({}); // returns `{}`
|
|
1148
|
+
* ```
|
|
1149
|
+
*
|
|
1150
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1151
|
+
* @see
|
|
1152
|
+
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1153
|
+
*/
|
|
152
1154
|
isNotFunction: autoGuard(),
|
|
1155
|
+
/**
|
|
1156
|
+
* Checks that a value is _not_ exactly `null. Returns the value if the check passes,
|
|
1157
|
+
* otherwise `undefined`.
|
|
1158
|
+
*
|
|
1159
|
+
* Type guards the value.
|
|
1160
|
+
*
|
|
1161
|
+
* @example
|
|
1162
|
+
*
|
|
1163
|
+
* ```ts
|
|
1164
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1165
|
+
*
|
|
1166
|
+
* checkWrap.isNotNull(null); // returns `undefined`
|
|
1167
|
+
* checkWrap.isNotNull(undefined); // returns `undefined`
|
|
1168
|
+
* ```
|
|
1169
|
+
*
|
|
1170
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1171
|
+
* @see
|
|
1172
|
+
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1173
|
+
*/
|
|
153
1174
|
isNotNull: autoGuard(),
|
|
1175
|
+
/**
|
|
1176
|
+
* Checks that a value is _not_ a number. This includes `NaN. Returns the value if the check
|
|
1177
|
+
* passes, otherwise `undefined`.
|
|
1178
|
+
*
|
|
1179
|
+
* Type guards the value.
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
*
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1185
|
+
*
|
|
1186
|
+
* checkWrap.isNotNumber(123); // returns `undefined`
|
|
1187
|
+
* checkWrap.isNotNumber(123n); // returns `123n`
|
|
1188
|
+
* ```
|
|
1189
|
+
*
|
|
1190
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1191
|
+
* @see
|
|
1192
|
+
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1193
|
+
*/
|
|
154
1194
|
isNotNumber: autoGuard(),
|
|
1195
|
+
/**
|
|
1196
|
+
* Checks that a value is _not_ an object. This includes arrays. Returns the value if the
|
|
1197
|
+
* check passes, otherwise `undefined`.
|
|
1198
|
+
*
|
|
1199
|
+
* Type guards the value.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
*
|
|
1203
|
+
* ```ts
|
|
1204
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1205
|
+
*
|
|
1206
|
+
* checkWrap.isNotObject({}); // returns `undefined`
|
|
1207
|
+
* checkWrap.isNotObject([]); // returns `[]`
|
|
1208
|
+
* ```
|
|
1209
|
+
*
|
|
1210
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1211
|
+
* @see
|
|
1212
|
+
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1213
|
+
*/
|
|
155
1214
|
isNotObject: autoGuard(),
|
|
1215
|
+
/**
|
|
1216
|
+
* Checks that a value is _not_ a string. Returns the value if the check passes, otherwise
|
|
1217
|
+
* `undefined`.
|
|
1218
|
+
*
|
|
1219
|
+
* Type guards the value.
|
|
1220
|
+
*
|
|
1221
|
+
* @example
|
|
1222
|
+
*
|
|
1223
|
+
* ```ts
|
|
1224
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1225
|
+
*
|
|
1226
|
+
* checkWrap.isNotString(''); // returns `undefined`
|
|
1227
|
+
* checkWrap.isNotString(5); // returns `5`
|
|
1228
|
+
* ```
|
|
1229
|
+
*
|
|
1230
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1231
|
+
* @see
|
|
1232
|
+
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1233
|
+
*/
|
|
156
1234
|
isNotString: autoGuard(),
|
|
157
|
-
|
|
1235
|
+
/**
|
|
1236
|
+
* Checks that a value is _not_ a symbol. Returns the value if the check passes, otherwise
|
|
1237
|
+
* `undefined`.
|
|
1238
|
+
*
|
|
1239
|
+
* Type guards the value.
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
*
|
|
1243
|
+
* ```ts
|
|
1244
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1245
|
+
*
|
|
1246
|
+
* checkWrap.isNotSymbol(Symbol('my-symbol')); // returns `undefined`
|
|
1247
|
+
* checkWrap.checkWrap('my-symbol'); // returns `'my-symbol'`
|
|
1248
|
+
* ```
|
|
1249
|
+
*
|
|
1250
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1251
|
+
* @see
|
|
1252
|
+
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1253
|
+
*/
|
|
1254
|
+
isNotSymbol: autoGuard(),
|
|
1255
|
+
/**
|
|
1256
|
+
* It doesn't make any sense for `checkWrap.isNotUndefined` to exist. If the input is not
|
|
1257
|
+
* `undefined`, then it still returns `undefined`.
|
|
1258
|
+
*/
|
|
1259
|
+
isNotUndefined: undefined,
|
|
1260
|
+
},
|
|
1261
|
+
waitUntil: {
|
|
1262
|
+
/**
|
|
1263
|
+
* Repeatedly calls a callback until its output is an array. Once the callback output
|
|
1264
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1265
|
+
*
|
|
1266
|
+
* Type guards the value.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
*
|
|
1270
|
+
* ```ts
|
|
1271
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1272
|
+
*
|
|
1273
|
+
* await waitUntil.isArray(() => []); // passes
|
|
1274
|
+
* await waitUntil.isArray(() => {
|
|
1275
|
+
* return {length: 4};
|
|
1276
|
+
* }); // throws an error
|
|
1277
|
+
* ```
|
|
1278
|
+
*
|
|
1279
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1280
|
+
* @see
|
|
1281
|
+
* - {@link waitUntil.isNotArray} : the opposite assertion.
|
|
1282
|
+
*/
|
|
1283
|
+
isArray: autoGuardSymbol,
|
|
1284
|
+
/**
|
|
1285
|
+
* Repeatedly calls a callback until its output is a BigInt. Once the callback output
|
|
1286
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1287
|
+
*
|
|
1288
|
+
* Type guards the value.
|
|
1289
|
+
*
|
|
1290
|
+
* @example
|
|
1291
|
+
*
|
|
1292
|
+
* ```ts
|
|
1293
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1294
|
+
*
|
|
1295
|
+
* await waitUntil.isBigInt(() => 123n); // returns `123n`
|
|
1296
|
+
* await waitUntil.isBigInt(() => 123); // throws an error
|
|
1297
|
+
* ```
|
|
1298
|
+
*
|
|
1299
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1300
|
+
* @see
|
|
1301
|
+
* - {@link waitUntil.isNotBigInt} : the opposite assertion.
|
|
1302
|
+
*/
|
|
1303
|
+
isBigInt: autoGuardSymbol,
|
|
1304
|
+
/**
|
|
1305
|
+
* Repeatedly calls a callback until its output is a boolean. Once the callback output
|
|
1306
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1307
|
+
*
|
|
1308
|
+
* Type guards the value.
|
|
1309
|
+
*
|
|
1310
|
+
* @example
|
|
1311
|
+
*
|
|
1312
|
+
* ```ts
|
|
1313
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1314
|
+
*
|
|
1315
|
+
* await waitUntil.isBoolean(() => true); // returns `true`
|
|
1316
|
+
* await waitUntil.isBoolean(() => 'true'); // throws an error
|
|
1317
|
+
* ```
|
|
1318
|
+
*
|
|
1319
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1320
|
+
* @see
|
|
1321
|
+
* - {@link waitUntil.isNotBoolean} : the opposite assertion.
|
|
1322
|
+
*/
|
|
1323
|
+
isBoolean: autoGuardSymbol,
|
|
1324
|
+
/**
|
|
1325
|
+
* Repeatedly calls a callback until its output is a function. Once the callback output
|
|
1326
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1327
|
+
*
|
|
1328
|
+
* Type guards the value.
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
*
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1334
|
+
*
|
|
1335
|
+
* await waitUntil.isFunction(() => () => {
|
|
1336
|
+
* return {};
|
|
1337
|
+
* }); // returns `{}`
|
|
1338
|
+
* await waitUntil.isFunction(() => {
|
|
1339
|
+
* return {};
|
|
1340
|
+
* }); // throws an error
|
|
1341
|
+
* ```
|
|
1342
|
+
*
|
|
1343
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1344
|
+
* @see
|
|
1345
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1346
|
+
*/
|
|
1347
|
+
isFunction: autoGuard(),
|
|
1348
|
+
/**
|
|
1349
|
+
* Repeatedly calls a callback until its output is exactly `null`. Once the callback output
|
|
1350
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1351
|
+
*
|
|
1352
|
+
* Type guards the value.
|
|
1353
|
+
*
|
|
1354
|
+
* @example
|
|
1355
|
+
*
|
|
1356
|
+
* ```ts
|
|
1357
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1358
|
+
*
|
|
1359
|
+
* await waitUntil.isNull(() => null); // returns `null`
|
|
1360
|
+
* await waitUntil.isNull(() => undefined); // throws an error
|
|
1361
|
+
* ```
|
|
1362
|
+
*
|
|
1363
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1364
|
+
* @see
|
|
1365
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1366
|
+
*/
|
|
1367
|
+
isNull: autoGuardSymbol,
|
|
1368
|
+
/**
|
|
1369
|
+
* Repeatedly calls a callback until its output is a number. This excludes `NaN`. Once the
|
|
1370
|
+
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1371
|
+
*
|
|
1372
|
+
* Type guards the value.
|
|
1373
|
+
*
|
|
1374
|
+
* @example
|
|
1375
|
+
*
|
|
1376
|
+
* ```ts
|
|
1377
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1378
|
+
*
|
|
1379
|
+
* await waitUntil.isNumber(() => 123); // returns `123`
|
|
1380
|
+
* await waitUntil.isNumber(() => 123n); // throws an error
|
|
1381
|
+
* ```
|
|
1382
|
+
*
|
|
1383
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1384
|
+
* @see
|
|
1385
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1386
|
+
*/
|
|
1387
|
+
isNumber: autoGuardSymbol,
|
|
1388
|
+
/**
|
|
1389
|
+
* Repeatedly calls a callback until its output is an object. This excludes arrays. Once the
|
|
1390
|
+
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1391
|
+
*
|
|
1392
|
+
* Type guards the value.
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
*
|
|
1396
|
+
* ```ts
|
|
1397
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1398
|
+
*
|
|
1399
|
+
* await waitUntil.isObject(() => {
|
|
1400
|
+
* return {};
|
|
1401
|
+
* }); // returns `{}`
|
|
1402
|
+
* await waitUntil.isObject(() => []); // throws an error
|
|
1403
|
+
* ```
|
|
1404
|
+
*
|
|
1405
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1406
|
+
* @see
|
|
1407
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1408
|
+
*/
|
|
1409
|
+
isObject: autoGuardSymbol,
|
|
1410
|
+
/**
|
|
1411
|
+
* Repeatedly calls a callback until its output is a string. Once the callback output
|
|
1412
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1413
|
+
*
|
|
1414
|
+
* Type guards the value.
|
|
1415
|
+
*
|
|
1416
|
+
* @example
|
|
1417
|
+
*
|
|
1418
|
+
* ```ts
|
|
1419
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1420
|
+
*
|
|
1421
|
+
* await waitUntil.isString(() => ''); // returns `''`
|
|
1422
|
+
* await waitUntil.isString(() => 5); // throws an error
|
|
1423
|
+
* ```
|
|
1424
|
+
*
|
|
1425
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1426
|
+
* @see
|
|
1427
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1428
|
+
*/
|
|
1429
|
+
isString: autoGuardSymbol,
|
|
1430
|
+
/**
|
|
1431
|
+
* Repeatedly calls a callback until its output is a symbol. Once the callback output
|
|
1432
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1433
|
+
*
|
|
1434
|
+
* Type guards the value.
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
*
|
|
1438
|
+
* ```ts
|
|
1439
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1440
|
+
*
|
|
1441
|
+
* await waitUntil.isSymbol(() => Symbol('my-symbol')); // returns the created symbol
|
|
1442
|
+
* await waitUntil.isSymbol(() => 'my-symbol'); // throws an error
|
|
1443
|
+
* ```
|
|
1444
|
+
*
|
|
1445
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1446
|
+
* @see
|
|
1447
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1448
|
+
*/
|
|
1449
|
+
isSymbol: autoGuardSymbol,
|
|
1450
|
+
/**
|
|
1451
|
+
* Repeatedly calls a callback until its output is exactly `undefined`. Once the callback
|
|
1452
|
+
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1453
|
+
*
|
|
1454
|
+
* Type guards the value.
|
|
1455
|
+
*
|
|
1456
|
+
* @example
|
|
1457
|
+
*
|
|
1458
|
+
* ```ts
|
|
1459
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1460
|
+
*
|
|
1461
|
+
* await waitUntil.isUndefined(() => undefined); // returns `undefined`
|
|
1462
|
+
* await waitUntil.isUndefined(() => null); // throws an error
|
|
1463
|
+
* ```
|
|
1464
|
+
*
|
|
1465
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1466
|
+
* @see
|
|
1467
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1468
|
+
*/
|
|
1469
|
+
isUndefined: autoGuardSymbol,
|
|
1470
|
+
/**
|
|
1471
|
+
* Repeatedly calls a callback until its output is _not_ an array. Once the callback output
|
|
1472
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1473
|
+
*
|
|
1474
|
+
* Type guards the value.
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1477
|
+
*
|
|
1478
|
+
* ```ts
|
|
1479
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1480
|
+
*
|
|
1481
|
+
* await waitUntil.isNotArray(() => []); // throws an error
|
|
1482
|
+
* await waitUntil.isNotArray(() => {
|
|
1483
|
+
* return {length: 4};
|
|
1484
|
+
* }); // returns `{length: 4}`
|
|
1485
|
+
* ```
|
|
1486
|
+
*
|
|
1487
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1488
|
+
* @see
|
|
1489
|
+
* - {@link waitUntil.isArray} : the opposite assertion.
|
|
1490
|
+
*/
|
|
1491
|
+
isNotArray: autoGuard(),
|
|
1492
|
+
/**
|
|
1493
|
+
* Repeatedly calls a callback until its output is _not_ a BigInt. Once the callback output
|
|
1494
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1495
|
+
*
|
|
1496
|
+
* Type guards the value.
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
*
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1502
|
+
*
|
|
1503
|
+
* await waitUntil.isNotBigInt(() => 123n); // throws an error
|
|
1504
|
+
* await waitUntil.isNotBigInt(() => 123); // returns `123`
|
|
1505
|
+
* ```
|
|
1506
|
+
*
|
|
1507
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1508
|
+
* @see
|
|
1509
|
+
* - {@link waitUntil.isBigInt} : the opposite assertion.
|
|
1510
|
+
*/
|
|
1511
|
+
isNotBigInt: autoGuard(),
|
|
1512
|
+
/**
|
|
1513
|
+
* Repeatedly calls a callback until its output is _not_ a boolean. Once the callback output
|
|
1514
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1515
|
+
*
|
|
1516
|
+
* Type guards the value.
|
|
1517
|
+
*
|
|
1518
|
+
* @example
|
|
1519
|
+
*
|
|
1520
|
+
* ```ts
|
|
1521
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1522
|
+
*
|
|
1523
|
+
* await waitUntil.isNotBoolean(() => true); // throws an error
|
|
1524
|
+
* await waitUntil.isNotBoolean(() => 'true'); // returns `'true'`
|
|
1525
|
+
* ```
|
|
1526
|
+
*
|
|
1527
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1528
|
+
* @see
|
|
1529
|
+
* - {@link waitUntil.isBoolean} : the opposite assertion.
|
|
1530
|
+
*/
|
|
1531
|
+
isNotBoolean: autoGuard(),
|
|
1532
|
+
/**
|
|
1533
|
+
* Repeatedly calls a callback until its output is _not_ a function. Once the callback
|
|
1534
|
+
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1535
|
+
*
|
|
1536
|
+
* Type guards the value.
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
*
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1542
|
+
*
|
|
1543
|
+
* await waitUntil.isNotFunction(() => () => {
|
|
1544
|
+
* return {};
|
|
1545
|
+
* }); // throws an error
|
|
1546
|
+
* await waitUntil.isNotFunction(() => {
|
|
1547
|
+
* return {};
|
|
1548
|
+
* }); // returns `{}`
|
|
1549
|
+
* ```
|
|
1550
|
+
*
|
|
1551
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1552
|
+
* @see
|
|
1553
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1554
|
+
*/
|
|
1555
|
+
isNotFunction: autoGuard(),
|
|
1556
|
+
/**
|
|
1557
|
+
* Repeatedly calls a callback until its output is _not_ exactly `null`. Once the callback
|
|
1558
|
+
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1559
|
+
*
|
|
1560
|
+
* Type guards the value.
|
|
1561
|
+
*
|
|
1562
|
+
* @example
|
|
1563
|
+
*
|
|
1564
|
+
* ```ts
|
|
1565
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1566
|
+
*
|
|
1567
|
+
* await waitUntil.isNotNull(() => null); // throws an error
|
|
1568
|
+
* await waitUntil.isNotNull(() => undefined); // returns `undefined`
|
|
1569
|
+
* ```
|
|
1570
|
+
*
|
|
1571
|
+
* @throws {@link AssertionError} If the assertion failed. @see
|
|
1572
|
+
* @see
|
|
1573
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1574
|
+
*/
|
|
1575
|
+
isNotNull: autoGuard(),
|
|
1576
|
+
/**
|
|
1577
|
+
* Repeatedly calls a callback until its output is _not_ a number. This includes `NaN`. Once
|
|
1578
|
+
* the callback output passes, it is returned. If the attempts time out, an error is
|
|
1579
|
+
* thrown.
|
|
1580
|
+
*
|
|
1581
|
+
* Type guards the value.
|
|
1582
|
+
*
|
|
1583
|
+
* @example
|
|
1584
|
+
*
|
|
1585
|
+
* ```ts
|
|
1586
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1587
|
+
*
|
|
1588
|
+
* await waitUntil.isNotNumber(() => 123); // throws an error
|
|
1589
|
+
* await waitUntil.isNotNumber(() => 123n); // returns `123n`
|
|
1590
|
+
* ```
|
|
1591
|
+
*
|
|
1592
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1593
|
+
* @see
|
|
1594
|
+
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1595
|
+
*/
|
|
1596
|
+
isNotNumber: autoGuard(),
|
|
1597
|
+
/**
|
|
1598
|
+
* Repeatedly calls a callback until its output is _not_ an object. This includes arrays.
|
|
1599
|
+
* Once the callback output passes, it is returned. If the attempts time out, an error is
|
|
1600
|
+
* thrown.
|
|
1601
|
+
*
|
|
1602
|
+
* Type guards the value.
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
*
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1608
|
+
*
|
|
1609
|
+
* await waitUntil.isNotObject(() => {
|
|
1610
|
+
* return {};
|
|
1611
|
+
* }); // throws an error
|
|
1612
|
+
* await waitUntil.isNotObject(() => []); // returns `[]`
|
|
1613
|
+
* ```
|
|
1614
|
+
*
|
|
1615
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1616
|
+
* @see
|
|
1617
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1618
|
+
*/
|
|
1619
|
+
isNotObject: autoGuard(),
|
|
1620
|
+
/**
|
|
1621
|
+
* Repeatedly calls a callback until its output is _not_ a string. Once the callback output
|
|
1622
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1623
|
+
*
|
|
1624
|
+
* Type guards the value.
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
*
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1630
|
+
*
|
|
1631
|
+
* await waitUntil.isNotString(() => ''); // throws an error
|
|
1632
|
+
* await waitUntil.isNotString(() => 5); // returns `5`
|
|
1633
|
+
* ```
|
|
1634
|
+
*
|
|
1635
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1636
|
+
* @see
|
|
1637
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1638
|
+
*/
|
|
1639
|
+
isNotString: autoGuard(),
|
|
1640
|
+
/**
|
|
1641
|
+
* Repeatedly calls a callback until its output is _not_ a symbol. Once the callback output
|
|
1642
|
+
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
1643
|
+
*
|
|
1644
|
+
* Type guards the value.
|
|
1645
|
+
*
|
|
1646
|
+
* @example
|
|
1647
|
+
*
|
|
1648
|
+
* ```ts
|
|
1649
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1650
|
+
*
|
|
1651
|
+
* await waitUntil.isNotSymbol(() => Symbol('my-symbol')); // throws an error
|
|
1652
|
+
* await waitUntil.isNotSymbol(() => 'my-symbol'); // returns `'my-symbol'`
|
|
1653
|
+
* ```
|
|
1654
|
+
*
|
|
1655
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1656
|
+
* @see
|
|
1657
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1658
|
+
*/
|
|
158
1659
|
isNotSymbol: autoGuard(),
|
|
1660
|
+
/**
|
|
1661
|
+
* Repeatedly calls a callback until its output is _not_ exactly `undefined`. Once the
|
|
1662
|
+
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
1663
|
+
*
|
|
1664
|
+
* Type guards the value.
|
|
1665
|
+
*
|
|
1666
|
+
* @example
|
|
1667
|
+
*
|
|
1668
|
+
* ```ts
|
|
1669
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1670
|
+
*
|
|
1671
|
+
* await waitUntil.isNotUndefined(() => undefined); // throws an error
|
|
1672
|
+
* await waitUntil.isNotUndefined(() => null); // returns `null`
|
|
1673
|
+
* ```
|
|
1674
|
+
*
|
|
1675
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1676
|
+
* @see
|
|
1677
|
+
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1678
|
+
*/
|
|
1679
|
+
isNotUndefined: autoGuard(),
|
|
159
1680
|
},
|
|
160
1681
|
};
|
|
161
1682
|
/**
|
|
@@ -166,7 +1687,8 @@ export const runtimeTypeGuards = {
|
|
|
166
1687
|
* both distinct from `object`.
|
|
167
1688
|
*
|
|
168
1689
|
* @category Assert : Util
|
|
169
|
-
* @
|
|
1690
|
+
* @category Package : @augment-vir/assert
|
|
1691
|
+
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
170
1692
|
*/
|
|
171
1693
|
export var RuntimeType;
|
|
172
1694
|
(function (RuntimeType) {
|
|
@@ -202,6 +1724,7 @@ export var RuntimeType;
|
|
|
202
1724
|
* from `object`.
|
|
203
1725
|
*
|
|
204
1726
|
* @category Assert : Util
|
|
1727
|
+
* @category Package : @augment-vir/assert
|
|
205
1728
|
* @example
|
|
206
1729
|
*
|
|
207
1730
|
* ```ts
|
|
@@ -211,7 +1734,7 @@ export var RuntimeType;
|
|
|
211
1734
|
* getRuntimeType({a: 'a'}); // RuntimeType.Object
|
|
212
1735
|
* ```
|
|
213
1736
|
*
|
|
214
|
-
* @package
|
|
1737
|
+
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
215
1738
|
*/
|
|
216
1739
|
export function getRuntimeType(actual) {
|
|
217
1740
|
if (actual === null) {
|