@augment-vir/assert 30.8.4 → 31.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/assertions/boolean.d.ts +20 -26
  2. package/dist/assertions/boolean.js +185 -41
  3. package/dist/assertions/boundary.d.ts +40 -256
  4. package/dist/assertions/boundary.js +265 -229
  5. package/dist/assertions/enum.d.ts +12 -13
  6. package/dist/assertions/enum.js +98 -20
  7. package/dist/assertions/equality/entry-equality.d.ts +11 -15
  8. package/dist/assertions/equality/entry-equality.js +210 -43
  9. package/dist/assertions/equality/json-equality.d.ts +11 -15
  10. package/dist/assertions/equality/json-equality.js +144 -43
  11. package/dist/assertions/equality/simple-equality.d.ts +39 -46
  12. package/dist/assertions/equality/simple-equality.js +316 -61
  13. package/dist/assertions/extendable-assertions.d.ts +0 -12
  14. package/dist/assertions/extendable-assertions.js +0 -12
  15. package/dist/assertions/http.d.ts +10 -14
  16. package/dist/assertions/http.js +96 -28
  17. package/dist/assertions/instance.d.ts +10 -18
  18. package/dist/assertions/instance.js +92 -26
  19. package/dist/assertions/keys.d.ts +59 -138
  20. package/dist/assertions/keys.js +279 -163
  21. package/dist/assertions/length.d.ts +30 -212
  22. package/dist/assertions/length.js +117 -175
  23. package/dist/assertions/nullish.d.ts +8 -20
  24. package/dist/assertions/nullish.js +85 -27
  25. package/dist/assertions/numeric.d.ts +67 -81
  26. package/dist/assertions/numeric.js +564 -133
  27. package/dist/assertions/output.d.ts +2 -3
  28. package/dist/assertions/output.js +1 -7
  29. package/dist/assertions/primitive.d.ts +33 -40
  30. package/dist/assertions/primitive.js +232 -66
  31. package/dist/assertions/promise.d.ts +20 -30
  32. package/dist/assertions/promise.js +244 -53
  33. package/dist/assertions/regexp.d.ts +12 -14
  34. package/dist/assertions/regexp.js +84 -21
  35. package/dist/assertions/runtime-type.d.ts +99 -207
  36. package/dist/assertions/runtime-type.js +805 -276
  37. package/dist/assertions/throws.d.ts +24 -25
  38. package/dist/assertions/throws.js +43 -5
  39. package/dist/assertions/uuid.d.ts +11 -16
  40. package/dist/assertions/uuid.js +91 -22
  41. package/dist/assertions/values.d.ts +81 -210
  42. package/dist/assertions/values.js +627 -234
  43. package/dist/augments/assertion-exports.d.ts +0 -1
  44. package/dist/augments/assertion-exports.js +1 -1
  45. package/dist/augments/guards/assert-wrap.d.ts +7 -4
  46. package/dist/augments/guards/assert-wrap.js +5 -4
  47. package/dist/augments/guards/check-wrap.d.ts +7 -5
  48. package/dist/augments/guards/check-wrap.js +5 -4
  49. package/dist/augments/guards/check.d.ts +5 -5
  50. package/dist/augments/guards/check.js +5 -4
  51. package/dist/augments/guards/wait-until.d.ts +8 -4
  52. package/dist/augments/guards/wait-until.js +7 -8
  53. package/dist/guard-types/guard-group.d.ts +5 -2
  54. package/dist/guard-types/wait-until-function.d.ts +2 -10
  55. package/dist/guard-types/wait-until-function.js +1 -9
  56. package/dist/index.d.ts +1 -0
  57. package/package.json +2 -2
  58. package/dist/guard-types/assert-wrap-function.d.ts +0 -12
  59. package/dist/guard-types/assert-wrap-function.js +0 -14
  60. package/dist/guard-types/check-function.d.ts +0 -14
  61. package/dist/guard-types/check-function.js +0 -22
  62. package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
  63. package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
  64. package/dist/guard-types/guard-override.d.ts +0 -4
  65. package/dist/guard-types/guard-override.js +0 -10
@@ -1,24 +1,6 @@
1
1
  import { stringify, } from '@augment-vir/core';
2
2
  import { AssertionError } from '../augments/assertion.error.js';
3
- import { createCheck } from '../guard-types/check-function.js';
4
- import { autoGuard } from '../guard-types/guard-override.js';
5
- function isKeyOf(key, parent, failureMessage) {
6
- try {
7
- hasKey(parent, key);
8
- }
9
- catch {
10
- throw new AssertionError(`'${String(key)}' is not a key of '${stringify(parent)}'.`, failureMessage);
11
- }
12
- }
13
- function isNotKeyOf(key, parent, failureMessage) {
14
- try {
15
- isKeyOf(key, parent);
16
- }
17
- catch {
18
- return;
19
- }
20
- throw new AssertionError(`'${String(key)}' is a key of '${stringify(parent)}'.`, failureMessage);
21
- }
3
+ import { createWaitUntil } from '../guard-types/wait-until-function.js';
22
4
  const hasKeyAttempts = [
23
5
  (object, key) => {
24
6
  return key in object;
@@ -28,10 +10,8 @@ const hasKeyAttempts = [
28
10
  return key in object.constructor.prototype;
29
11
  },
30
12
  ];
31
- /** Check if an object has the given property. */
32
- function hasKey(parent, key, failureMessage) {
33
- const message = `'${stringify(parent)}' does not have key '${String(key)}'.`;
34
- const doesHaveKey = hasKeyAttempts.some((attemptCallback) => {
13
+ function hasKey(parent, key) {
14
+ return hasKeyAttempts.some((attemptCallback) => {
35
15
  try {
36
16
  return attemptCallback(parent, key);
37
17
  }
@@ -39,40 +19,152 @@ function hasKey(parent, key, failureMessage) {
39
19
  return false;
40
20
  }
41
21
  });
42
- if (!doesHaveKey) {
43
- throw new AssertionError(message, failureMessage);
44
- }
45
- }
46
- function lacksKey(parent, key, failureMessage) {
47
- try {
48
- hasKey(parent, key);
49
- }
50
- catch {
51
- return;
52
- }
53
- throw new AssertionError(`'${stringify(parent)}' has key '${String(key)}'.`, failureMessage);
54
- }
55
- const checkHasKey = createCheck(hasKey);
56
- /** Check if an object has all the given properties. */
57
- function hasKeys(parent, keys, failureMessage) {
58
- const missingKeys = keys.filter((key) => !checkHasKey(parent, key));
59
- if (missingKeys.length) {
60
- throw new AssertionError(`'${stringify(parent)}' does not have keys '${missingKeys.join(',')}'.`, failureMessage);
61
- }
62
- }
63
- function lacksKeys(parent, keys, failureMessage) {
64
- const existingKeys = keys.filter((key) => checkHasKey(parent, key));
65
- if (existingKeys.length) {
66
- throw new AssertionError(`'${stringify(parent)}' does not lack keys '${existingKeys.join(',')}'.`, failureMessage);
67
- }
68
22
  }
69
23
  const assertions = {
70
- isKeyOf,
71
- isNotKeyOf,
72
- hasKey,
73
- lacksKey,
74
- hasKeys,
75
- lacksKeys,
24
+ /**
25
+ * Asserts that a key is contained within a parent value.
26
+ *
27
+ * Type guards the key.
28
+ *
29
+ * @example
30
+ *
31
+ * ```ts
32
+ * import {assert} from '@augment-vir/assert';
33
+ *
34
+ * assert.isKeyof('a', {a: 0, b: 1}); // passes
35
+ * assert.isKeyof('c', {a: 0, b: 1}); // fails
36
+ * ```
37
+ *
38
+ * @throws {@link AssertionError} If the key is not in the parent.
39
+ * @see
40
+ * - {@link assert.isNotKeyOf} : the opposite assertion.
41
+ */
42
+ isKeyOf(key, parent, failureMessage) {
43
+ if (!hasKey(parent, key)) {
44
+ throw new AssertionError(`'${String(key)}' is not a key of '${stringify(parent)}'.`, failureMessage);
45
+ }
46
+ },
47
+ /**
48
+ * Asserts that a key is _not_ contained within a parent value.
49
+ *
50
+ * Type guards the key.
51
+ *
52
+ * @example
53
+ *
54
+ * ```ts
55
+ * import {assert} from '@augment-vir/assert';
56
+ *
57
+ * assert.isNotKeyOf('a', {a: 0, b: 1}); // fails
58
+ * assert.isNotKeyOf('c', {a: 0, b: 1}); // passes
59
+ * ```
60
+ *
61
+ * @throws {@link AssertionError} If the key is in the parent.
62
+ * @see
63
+ * - {@link assert.isKeyOf} : the opposite assertion.
64
+ */
65
+ isNotKeyOf(key, parent, failureMessage) {
66
+ if (hasKey(parent, key)) {
67
+ throw new AssertionError(`'${String(key)}' is a key of '${stringify(parent)}'.`, failureMessage);
68
+ }
69
+ },
70
+ /**
71
+ * Asserts that a parent value has the key.
72
+ *
73
+ * Type guards the parent value.
74
+ *
75
+ * @example
76
+ *
77
+ * ```ts
78
+ * import {assert} from '@augment-vir/assert';
79
+ *
80
+ * assert.hasKey({a: 0, b: 1}, 'a'); // passes
81
+ * assert.hasKey({a: 0, b: 1}, 'c'); // fails
82
+ * ```
83
+ *
84
+ * @throws {@link AssertionError} If the parent does not have the key.
85
+ * @see
86
+ * - {@link assert.lacksKey} : the opposite assertion.
87
+ * - {@link assert.hasKeys} : the multi-key assertion.
88
+ */
89
+ hasKey(parent, key, failureMessage) {
90
+ if (!hasKey(parent, key)) {
91
+ throw new AssertionError(`'${stringify(parent)}' does not have key '${String(key)}'.`, failureMessage);
92
+ }
93
+ },
94
+ /**
95
+ * Asserts that a parent value does not have the key.
96
+ *
97
+ * Type guards the parent value.
98
+ *
99
+ * @example
100
+ *
101
+ * ```ts
102
+ * import {assert} from '@augment-vir/assert';
103
+ *
104
+ * assert.lacksKey({a: 0, b: 1}, 'a'); // fails
105
+ * assert.lacksKey({a: 0, b: 1}, 'c'); // passes
106
+ * ```
107
+ *
108
+ * @throws {@link AssertionError} If the parent has the key.
109
+ * @see
110
+ * - {@link assert.hasKey} : the opposite assertion.
111
+ * - {@link assert.lacksKeys} : the multi-key assertion.
112
+ */
113
+ lacksKey(parent, key, failureMessage) {
114
+ if (hasKey(parent, key)) {
115
+ throw new AssertionError(`'${stringify(parent)}' has key '${String(key)}'.`, failureMessage);
116
+ }
117
+ },
118
+ /**
119
+ * Asserts that a parent value has all the keys.
120
+ *
121
+ * Type guards the parent value.
122
+ *
123
+ * @example
124
+ *
125
+ * ```ts
126
+ * import {assert} from '@augment-vir/assert';
127
+ *
128
+ * assert.hasKeys({a: 0, b: 1}, ['a', 'b']); // passes
129
+ * assert.hasKeys({a: 0, b: 1}, ['b', 'c']); // fails
130
+ * ```
131
+ *
132
+ * @throws {@link AssertionError} If the parent does not have all the keys.
133
+ * @see
134
+ * - {@link assert.lacksKeys} : the opposite assertion.
135
+ * - {@link assert.hasKey} : the single-key assertion.
136
+ */
137
+ hasKeys(parent, keys, failureMessage) {
138
+ const missingKeys = keys.filter((key) => !hasKey(parent, key));
139
+ if (missingKeys.length) {
140
+ throw new AssertionError(`'${stringify(parent)}' does not have keys '${missingKeys.join(',')}'.`, failureMessage);
141
+ }
142
+ },
143
+ /**
144
+ * Asserts that a parent value none of the keys.
145
+ *
146
+ * Type guards the parent value.
147
+ *
148
+ * @example
149
+ *
150
+ * ```ts
151
+ * import {assert} from '@augment-vir/assert';
152
+ *
153
+ * assert.lacksKeys({a: 0, b: 1}, ['b', 'c']); // fails
154
+ * assert.lacksKeys({a: 0, b: 1}, ['c', 'd']); // passes
155
+ * ```
156
+ *
157
+ * @throws {@link AssertionError} If the parent has any of the keys.
158
+ * @see
159
+ * - {@link assert.hasKeys} : the opposite assertion.
160
+ * - {@link assert.lacksKey} : the single-key assertion.
161
+ */
162
+ lacksKeys(parent, keys, failureMessage) {
163
+ const existingKeys = keys.filter((key) => hasKey(parent, key));
164
+ if (existingKeys.length) {
165
+ throw new AssertionError(`'${stringify(parent)}' does not lack keys '${existingKeys.join(',')}'.`, failureMessage);
166
+ }
167
+ },
76
168
  };
77
169
  export const keyGuards = {
78
170
  assert: assertions,
@@ -94,7 +186,9 @@ export const keyGuards = {
94
186
  * @see
95
187
  * - {@link check.isNotKeyOf} : the opposite check.
96
188
  */
97
- isKeyOf: autoGuard(),
189
+ isKeyOf(key, parent) {
190
+ return hasKey(parent, key);
191
+ },
98
192
  /**
99
193
  * Checks that a key is _not_ contained within a parent value.
100
194
  *
@@ -112,7 +206,9 @@ export const keyGuards = {
112
206
  * @see
113
207
  * - {@link check.isKeyOf} : the opposite check.
114
208
  */
115
- isNotKeyOf: autoGuard(),
209
+ isNotKeyOf(key, parent) {
210
+ return !hasKey(parent, key);
211
+ },
116
212
  /**
117
213
  * Checks that a parent value has the key.
118
214
  *
@@ -131,7 +227,7 @@ export const keyGuards = {
131
227
  * - {@link check.lacksKey} : the opposite check.
132
228
  * - {@link check.hasKeys} : the multi-key check.
133
229
  */
134
- hasKey: autoGuard(),
230
+ hasKey,
135
231
  /**
136
232
  * Checks that a parent value does not have the key.
137
233
  *
@@ -150,7 +246,9 @@ export const keyGuards = {
150
246
  * - {@link check.hasKey} : the opposite check.
151
247
  * - {@link check.lacksKeys} : the multi-key check.
152
248
  */
153
- lacksKey: autoGuard(),
249
+ lacksKey(parent, key) {
250
+ return !hasKey(parent, key);
251
+ },
154
252
  /**
155
253
  * Checks that a parent value has all the keys.
156
254
  *
@@ -161,21 +259,17 @@ export const keyGuards = {
161
259
  * ```ts
162
260
  * import {check} from '@augment-vir/assert';
163
261
  *
164
- * check.hasKeys({a: 0, b: 1}, [
165
- * 'a',
166
- * 'b',
167
- * ]); // returns `true`
168
- * check.hasKeys({a: 0, b: 1}, [
169
- * 'b',
170
- * 'c',
171
- * ]); // returns `false`
262
+ * check.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `true`
263
+ * check.hasKeys({a: 0, b: 1}, ['b', 'c']); // returns `false`
172
264
  * ```
173
265
  *
174
266
  * @see
175
267
  * - {@link check.lacksKeys} : the opposite check.
176
268
  * - {@link check.hasKey} : the single-key check.
177
269
  */
178
- hasKeys: autoGuard(),
270
+ hasKeys(parent, keys) {
271
+ return keys.every((key) => hasKey(parent, key));
272
+ },
179
273
  /**
180
274
  * Checks that a parent value none of the keys.
181
275
  *
@@ -186,21 +280,17 @@ export const keyGuards = {
186
280
  * ```ts
187
281
  * import {check} from '@augment-vir/assert';
188
282
  *
189
- * check.lacksKeys({a: 0, b: 1}, [
190
- * 'b',
191
- * 'c',
192
- * ]); // returns `false`
193
- * check.lacksKeys({a: 0, b: 1}, [
194
- * 'c',
195
- * 'd',
196
- * ]); // returns `true`
283
+ * check.lacksKeys({a: 0, b: 1}, ['b', 'c']); // returns `false`
284
+ * check.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `true`
197
285
  * ```
198
286
  *
199
287
  * @see
200
288
  * - {@link check.hasKeys} : the opposite check.
201
289
  * - {@link check.lacksKey} : the single-key check.
202
290
  */
203
- lacksKeys: autoGuard(),
291
+ lacksKeys(parent, keys) {
292
+ return keys.every((key) => !hasKey(parent, key));
293
+ },
204
294
  },
205
295
  assertWrap: {
206
296
  /**
@@ -223,7 +313,12 @@ export const keyGuards = {
223
313
  * @see
224
314
  * - {@link assertWrap.isNotKeyOf} : the opposite assertion.
225
315
  */
226
- isKeyOf: autoGuard(),
316
+ isKeyOf(key, parent, failureMessage) {
317
+ if (!hasKey(parent, key)) {
318
+ throw new AssertionError(`'${String(key)}' is not a key of '${stringify(parent)}'.`, failureMessage);
319
+ }
320
+ return key;
321
+ },
227
322
  /**
228
323
  * Asserts that a key is _not_ contained within a parent value. Returns the key if the
229
324
  * assertion passes.
@@ -244,7 +339,12 @@ export const keyGuards = {
244
339
  * @see
245
340
  * - {@link assertWrap.isKeyOf} : the opposite assertion.
246
341
  */
247
- isNotKeyOf: autoGuard(),
342
+ isNotKeyOf(key, parent, failureMessage) {
343
+ if (hasKey(parent, key)) {
344
+ throw new AssertionError(`'${String(key)}' is a key of '${stringify(parent)}'.`, failureMessage);
345
+ }
346
+ return key;
347
+ },
248
348
  /**
249
349
  * Asserts that a parent value has the key. Returns the parent if the assertion passes.
250
350
  *
@@ -265,7 +365,12 @@ export const keyGuards = {
265
365
  * - {@link assertWrap.lacksKey} : the opposite assertion.
266
366
  * - {@link assertWrap.hasKeys} : the multi-key assertion.
267
367
  */
268
- hasKey: autoGuard(),
368
+ hasKey(parent, key, failureMessage) {
369
+ if (!hasKey(parent, key)) {
370
+ throw new AssertionError(`'${stringify(parent)}' does not have key '${String(key)}'.`, failureMessage);
371
+ }
372
+ return parent;
373
+ },
269
374
  /**
270
375
  * Asserts that a parent value does not have the key. Returns the parent if the assertion
271
376
  * passes.
@@ -287,7 +392,12 @@ export const keyGuards = {
287
392
  * - {@link assertWrap.hasKey} : the opposite assertion.
288
393
  * - {@link assertWrap.lacksKeys} : the multi-key assertion.
289
394
  */
290
- lacksKey: autoGuard(),
395
+ lacksKey(parent, key, failureMessage) {
396
+ if (hasKey(parent, key)) {
397
+ throw new AssertionError(`'${stringify(parent)}' has key '${String(key)}'.`, failureMessage);
398
+ }
399
+ return parent;
400
+ },
291
401
  /**
292
402
  * Asserts that a parent value has all the keys. Returns the parent if the assertion passes.
293
403
  *
@@ -298,14 +408,8 @@ export const keyGuards = {
298
408
  * ```ts
299
409
  * import {assertWrap} from '@augment-vir/assert';
300
410
  *
301
- * assertWrap.hasKeys({a: 0, b: 1}, [
302
- * 'a',
303
- * 'b',
304
- * ]); // returns `{a: 0, b: 1}`
305
- * assertWrap.hasKeys({a: 0, b: 1}, [
306
- * 'b',
307
- * 'c',
308
- * ]); // throws an error
411
+ * assertWrap.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `{a: 0, b: 1}`
412
+ * assertWrap.hasKeys({a: 0, b: 1}, ['b', 'c']); // throws an error
309
413
  * ```
310
414
  *
311
415
  * @returns The parent if it has all the keys.
@@ -314,7 +418,13 @@ export const keyGuards = {
314
418
  * - {@link assertWrap.lacksKeys} : the opposite assertion.
315
419
  * - {@link assertWrap.hasKey} : the single-key assertion.
316
420
  */
317
- hasKeys: autoGuard(),
421
+ hasKeys(parent, keys, failureMessage) {
422
+ const missingKeys = keys.filter((key) => !hasKey(parent, key));
423
+ if (missingKeys.length) {
424
+ throw new AssertionError(`'${stringify(parent)}' does not have keys '${missingKeys.join(',')}'.`, failureMessage);
425
+ }
426
+ return parent;
427
+ },
318
428
  /**
319
429
  * Asserts that a parent value none of the keys. Returns the parent if the assertion passes.
320
430
  *
@@ -325,14 +435,8 @@ export const keyGuards = {
325
435
  * ```ts
326
436
  * import {assertWrap} from '@augment-vir/assert';
327
437
  *
328
- * assertWrap.lacksKeys({a: 0, b: 1}, [
329
- * 'b',
330
- * 'c',
331
- * ]); // throws an error
332
- * assertWrap.lacksKeys({a: 0, b: 1}, [
333
- * 'c',
334
- * 'd',
335
- * ]); // returns `{a: 0, b: 1}`
438
+ * assertWrap.lacksKeys({a: 0, b: 1}, ['b', 'c']); // throws an error
439
+ * assertWrap.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `{a: 0, b: 1}`
336
440
  * ```
337
441
  *
338
442
  * @returns The parent if it does not have any of the keys.
@@ -341,7 +445,13 @@ export const keyGuards = {
341
445
  * - {@link assertWrap.hasKeys} : the opposite assertion.
342
446
  * - {@link assertWrap.lacksKey} : the single-key assertion.
343
447
  */
344
- lacksKeys: autoGuard(),
448
+ lacksKeys(parent, keys, failureMessage) {
449
+ const existingKeys = keys.filter((key) => hasKey(parent, key));
450
+ if (existingKeys.length) {
451
+ throw new AssertionError(`'${stringify(parent)}' does not lack keys '${existingKeys.join(',')}'.`, failureMessage);
452
+ }
453
+ return parent;
454
+ },
345
455
  },
346
456
  checkWrap: {
347
457
  /**
@@ -363,7 +473,14 @@ export const keyGuards = {
363
473
  * @see
364
474
  * - {@link checkWrap.isNotKeyOf} : the opposite check.
365
475
  */
366
- isKeyOf: autoGuard(),
476
+ isKeyOf(key, parent) {
477
+ if (hasKey(parent, key)) {
478
+ return key;
479
+ }
480
+ else {
481
+ return undefined;
482
+ }
483
+ },
367
484
  /**
368
485
  * Checks that a key is _not_ contained within a parent value. Returns the key if the check
369
486
  * passes, otherwise `undefined`.
@@ -383,7 +500,14 @@ export const keyGuards = {
383
500
  * @see
384
501
  * - {@link checkWrap.isKeyOf} : the opposite check.
385
502
  */
386
- isNotKeyOf: autoGuard(),
503
+ isNotKeyOf(key, parent) {
504
+ if (hasKey(parent, key)) {
505
+ return undefined;
506
+ }
507
+ else {
508
+ return key;
509
+ }
510
+ },
387
511
  /**
388
512
  * Checks that a parent value has the key. Returns the parent value if the check passes,
389
513
  * otherwise `undefined`.
@@ -404,7 +528,14 @@ export const keyGuards = {
404
528
  * - {@link checkWrap.lacksKey} : the opposite check.
405
529
  * - {@link checkWrap.hasKeys} : the multi-key check.
406
530
  */
407
- hasKey: autoGuard(),
531
+ hasKey(parent, key) {
532
+ if (hasKey(parent, key)) {
533
+ return parent;
534
+ }
535
+ else {
536
+ return undefined;
537
+ }
538
+ },
408
539
  /**
409
540
  * Checks that a parent value does not have the key. Returns the parent value if the check
410
541
  * passes, otherwise `undefined`.
@@ -425,7 +556,14 @@ export const keyGuards = {
425
556
  * - {@link checkWrap.hasKey} : the opposite check.
426
557
  * - {@link checkWrap.lacksKeys} : the multi-key check.
427
558
  */
428
- lacksKey: autoGuard(),
559
+ lacksKey(parent, key) {
560
+ if (hasKey(parent, key)) {
561
+ return undefined;
562
+ }
563
+ else {
564
+ return parent;
565
+ }
566
+ },
429
567
  /**
430
568
  * Checks that a parent value has all the keys. Returns the parent value if the check
431
569
  * passes, otherwise `undefined`.
@@ -437,14 +575,8 @@ export const keyGuards = {
437
575
  * ```ts
438
576
  * import {checkWrap} from '@augment-vir/assert';
439
577
  *
440
- * checkWrap.hasKeys({a: 0, b: 1}, [
441
- * 'a',
442
- * 'b',
443
- * ]); // returns `{a: 0, b: 1}`
444
- * checkWrap.hasKeys({a: 0, b: 1}, [
445
- * 'b',
446
- * 'c',
447
- * ]); // returns `undefined`
578
+ * checkWrap.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `{a: 0, b: 1}`
579
+ * checkWrap.hasKeys({a: 0, b: 1}, ['b', 'c']); // returns `undefined`
448
580
  * ```
449
581
  *
450
582
  * @returns The parent value if the check passes, otherwise `undefined`.
@@ -452,7 +584,14 @@ export const keyGuards = {
452
584
  * - {@link checkWrap.lacksKeys} : the opposite check.
453
585
  * - {@link checkWrap.hasKey} : the single-key check.
454
586
  */
455
- hasKeys: autoGuard(),
587
+ hasKeys(parent, keys) {
588
+ if (keys.every((key) => hasKey(parent, key))) {
589
+ return parent;
590
+ }
591
+ else {
592
+ return undefined;
593
+ }
594
+ },
456
595
  /**
457
596
  * Checks that a parent value none of the keys. Returns the parent value if the check
458
597
  * passes, otherwise `undefined`.
@@ -464,14 +603,8 @@ export const keyGuards = {
464
603
  * ```ts
465
604
  * import {checkWrap} from '@augment-vir/assert';
466
605
  *
467
- * checkWrap.lacksKeys({a: 0, b: 1}, [
468
- * 'b',
469
- * 'c',
470
- * ]); // returns `undefined`
471
- * checkWrap.lacksKeys({a: 0, b: 1}, [
472
- * 'c',
473
- * 'd',
474
- * ]); // returns `{a: 0, b: 1}`
606
+ * checkWrap.lacksKeys({a: 0, b: 1}, ['b', 'c']); // returns `undefined`
607
+ * checkWrap.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `{a: 0, b: 1}`
475
608
  * ```
476
609
  *
477
610
  * @returns The parent value if the check passes, otherwise `undefined`.
@@ -479,7 +612,14 @@ export const keyGuards = {
479
612
  * - {@link checkWrap.hasKeys} : the opposite check.
480
613
  * - {@link checkWrap.lacksKey} : the single-key check.
481
614
  */
482
- lacksKeys: autoGuard(),
615
+ lacksKeys(parent, keys) {
616
+ if (keys.every((key) => !hasKey(parent, key))) {
617
+ return parent;
618
+ }
619
+ else {
620
+ return undefined;
621
+ }
622
+ },
483
623
  },
484
624
  waitUntil: {
485
625
  /**
@@ -503,7 +643,7 @@ export const keyGuards = {
503
643
  * @see
504
644
  * - {@link waitUntil.isNotKeyOf} : the opposite assertion.
505
645
  */
506
- isKeyOf: autoGuard(),
646
+ isKeyOf: createWaitUntil(assertions.isKeyOf),
507
647
  /**
508
648
  * Repeatedly calls a callback until its output is a key that is _not_ contained within the
509
649
  * first, parent value. Once the callback output passes, it is returned. If the attempts
@@ -525,7 +665,7 @@ export const keyGuards = {
525
665
  * @see
526
666
  * - {@link waitUntil.isNotKeyOf} : the opposite assertion.
527
667
  */
528
- isNotKeyOf: autoGuard(),
668
+ isNotKeyOf: createWaitUntil(assertions.isNotKeyOf),
529
669
  /**
530
670
  * Repeatedly calls a callback until its output is a parent value that has the first, key
531
671
  * input. Once the callback output passes, it is returned. If the attempts time out, an
@@ -552,7 +692,7 @@ export const keyGuards = {
552
692
  * - {@link waitUntil.lacksKey} : the opposite assertion.
553
693
  * - {@link waitUntil.hasKeys} : the multi-key assertion.
554
694
  */
555
- hasKey: autoGuard(),
695
+ hasKey: createWaitUntil(assertions.hasKey),
556
696
  /**
557
697
  * Repeatedly calls a callback until its output is a parent value that does not have the
558
698
  * first, key input. Once the callback output passes, it is returned. If the attempts time
@@ -579,7 +719,7 @@ export const keyGuards = {
579
719
  * - {@link waitUntil.hasKey} : the opposite assertion.
580
720
  * - {@link waitUntil.lacksKeys} : the multi-key assertion.
581
721
  */
582
- lacksKey: autoGuard(),
722
+ lacksKey: createWaitUntil(assertions.lacksKey),
583
723
  /**
584
724
  * Repeatedly calls a callback until its output is a parent value that has all of the first,
585
725
  * keys input. Once the callback output passes, it is returned. If the attempts time out, an
@@ -592,24 +732,12 @@ export const keyGuards = {
592
732
  * ```ts
593
733
  * import {waitUntil} from '@augment-vir/assert';
594
734
  *
595
- * await waitUntil.hasKeys(
596
- * [
597
- * 'a',
598
- * 'b',
599
- * ],
600
- * () => {
601
- * return {a: 0, b: 1};
602
- * },
603
- * ); // returns `{a: 0, b: 1}`
604
- * await waitUntil.hasKeys(
605
- * [
606
- * 'b',
607
- * 'c',
608
- * ],
609
- * () => {
610
- * return {a: 0, b: 1};
611
- * },
612
- * ); // throws an error
735
+ * await waitUntil.hasKeys(['a', 'b'], () => {
736
+ * return {a: 0, b: 1};
737
+ * }); // returns `{a: 0, b: 1}`
738
+ * await waitUntil.hasKeys(['b', 'c'], () => {
739
+ * return {a: 0, b: 1};
740
+ * }); // throws an error
613
741
  * ```
614
742
  *
615
743
  * @returns The callback output once it passes.
@@ -618,7 +746,7 @@ export const keyGuards = {
618
746
  * - {@link waitUntil.lacksKeys} : the opposite assertion.
619
747
  * - {@link waitUntil.hasKey} : the single-key assertion.
620
748
  */
621
- hasKeys: autoGuard(),
749
+ hasKeys: createWaitUntil(assertions.hasKeys),
622
750
  /**
623
751
  * Repeatedly calls a callback until its output is a parent value that does not have any of
624
752
  * the first, keys input. Once the callback output passes, it is returned. If the attempts
@@ -631,24 +759,12 @@ export const keyGuards = {
631
759
  * ```ts
632
760
  * import {waitUntil} from '@augment-vir/assert';
633
761
  *
634
- * await waitUntil.hasKeys(
635
- * [
636
- * 'a',
637
- * 'b',
638
- * ],
639
- * () => {
640
- * return {a: 0, b: 1};
641
- * },
642
- * ); // throws an error
643
- * await waitUntil.hasKeys(
644
- * [
645
- * 'b',
646
- * 'c',
647
- * ],
648
- * () => {
649
- * return {a: 0, b: 1};
650
- * },
651
- * ); // returns `{a: 0, b: 1}`
762
+ * await waitUntil.hasKeys(['a', 'b'], () => {
763
+ * return {a: 0, b: 1};
764
+ * }); // throws an error
765
+ * await waitUntil.hasKeys(['b', 'c'], () => {
766
+ * return {a: 0, b: 1};
767
+ * }); // returns `{a: 0, b: 1}`
652
768
  * ```
653
769
  *
654
770
  * @returns The callback output once it passes.
@@ -657,6 +773,6 @@ export const keyGuards = {
657
773
  * - {@link waitUntil.hasKeys} : the opposite assertion.
658
774
  * - {@link waitUntil.lacksKey} : the single-key assertion.
659
775
  */
660
- lacksKeys: autoGuard(),
776
+ lacksKeys: createWaitUntil(assertions.lacksKeys),
661
777
  },
662
778
  };