@augment-vir/assert 31.0.0 → 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 (63) 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 -162
  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 -150
  36. package/dist/assertions/runtime-type.js +805 -229
  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/guards/assert-wrap.d.ts +7 -4
  44. package/dist/augments/guards/assert-wrap.js +5 -4
  45. package/dist/augments/guards/check-wrap.d.ts +7 -5
  46. package/dist/augments/guards/check-wrap.js +5 -4
  47. package/dist/augments/guards/check.d.ts +5 -5
  48. package/dist/augments/guards/check.js +5 -4
  49. package/dist/augments/guards/wait-until.d.ts +8 -4
  50. package/dist/augments/guards/wait-until.js +7 -8
  51. package/dist/guard-types/guard-group.d.ts +5 -2
  52. package/dist/guard-types/wait-until-function.d.ts +2 -10
  53. package/dist/guard-types/wait-until-function.js +1 -9
  54. package/dist/index.d.ts +1 -0
  55. package/package.json +2 -2
  56. package/dist/guard-types/assert-wrap-function.d.ts +0 -12
  57. package/dist/guard-types/assert-wrap-function.js +0 -14
  58. package/dist/guard-types/check-function.d.ts +0 -14
  59. package/dist/guard-types/check-function.js +0 -22
  60. package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
  61. package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
  62. package/dist/guard-types/guard-override.d.ts +0 -4
  63. 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,9 +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 doesHaveKey = hasKeyAttempts.some((attemptCallback) => {
13
+ function hasKey(parent, key) {
14
+ return hasKeyAttempts.some((attemptCallback) => {
34
15
  try {
35
16
  return attemptCallback(parent, key);
36
17
  }
@@ -38,40 +19,152 @@ function hasKey(parent, key, failureMessage) {
38
19
  return false;
39
20
  }
40
21
  });
41
- if (!doesHaveKey) {
42
- throw new AssertionError(`'${stringify(parent)}' does not have key '${String(key)}'.`, failureMessage);
43
- }
44
- }
45
- function lacksKey(parent, key, failureMessage) {
46
- try {
47
- hasKey(parent, key);
48
- }
49
- catch {
50
- return;
51
- }
52
- throw new AssertionError(`'${stringify(parent)}' has key '${String(key)}'.`, failureMessage);
53
- }
54
- const checkHasKey = createCheck(hasKey);
55
- /** Check if an object has all the given properties. */
56
- function hasKeys(parent, keys, failureMessage) {
57
- const missingKeys = keys.filter((key) => !checkHasKey(parent, key));
58
- if (missingKeys.length) {
59
- throw new AssertionError(`'${stringify(parent)}' does not have keys '${missingKeys.join(',')}'.`, failureMessage);
60
- }
61
- }
62
- function lacksKeys(parent, keys, failureMessage) {
63
- const existingKeys = keys.filter((key) => checkHasKey(parent, key));
64
- if (existingKeys.length) {
65
- throw new AssertionError(`'${stringify(parent)}' does not lack keys '${existingKeys.join(',')}'.`, failureMessage);
66
- }
67
22
  }
68
23
  const assertions = {
69
- isKeyOf,
70
- isNotKeyOf,
71
- hasKey,
72
- lacksKey,
73
- hasKeys,
74
- 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
+ },
75
168
  };
76
169
  export const keyGuards = {
77
170
  assert: assertions,
@@ -93,7 +186,9 @@ export const keyGuards = {
93
186
  * @see
94
187
  * - {@link check.isNotKeyOf} : the opposite check.
95
188
  */
96
- isKeyOf: autoGuard(),
189
+ isKeyOf(key, parent) {
190
+ return hasKey(parent, key);
191
+ },
97
192
  /**
98
193
  * Checks that a key is _not_ contained within a parent value.
99
194
  *
@@ -111,7 +206,9 @@ export const keyGuards = {
111
206
  * @see
112
207
  * - {@link check.isKeyOf} : the opposite check.
113
208
  */
114
- isNotKeyOf: autoGuard(),
209
+ isNotKeyOf(key, parent) {
210
+ return !hasKey(parent, key);
211
+ },
115
212
  /**
116
213
  * Checks that a parent value has the key.
117
214
  *
@@ -130,7 +227,7 @@ export const keyGuards = {
130
227
  * - {@link check.lacksKey} : the opposite check.
131
228
  * - {@link check.hasKeys} : the multi-key check.
132
229
  */
133
- hasKey: autoGuard(),
230
+ hasKey,
134
231
  /**
135
232
  * Checks that a parent value does not have the key.
136
233
  *
@@ -149,7 +246,9 @@ export const keyGuards = {
149
246
  * - {@link check.hasKey} : the opposite check.
150
247
  * - {@link check.lacksKeys} : the multi-key check.
151
248
  */
152
- lacksKey: autoGuard(),
249
+ lacksKey(parent, key) {
250
+ return !hasKey(parent, key);
251
+ },
153
252
  /**
154
253
  * Checks that a parent value has all the keys.
155
254
  *
@@ -160,21 +259,17 @@ export const keyGuards = {
160
259
  * ```ts
161
260
  * import {check} from '@augment-vir/assert';
162
261
  *
163
- * check.hasKeys({a: 0, b: 1}, [
164
- * 'a',
165
- * 'b',
166
- * ]); // returns `true`
167
- * check.hasKeys({a: 0, b: 1}, [
168
- * 'b',
169
- * 'c',
170
- * ]); // returns `false`
262
+ * check.hasKeys({a: 0, b: 1}, ['a', 'b']); // returns `true`
263
+ * check.hasKeys({a: 0, b: 1}, ['b', 'c']); // returns `false`
171
264
  * ```
172
265
  *
173
266
  * @see
174
267
  * - {@link check.lacksKeys} : the opposite check.
175
268
  * - {@link check.hasKey} : the single-key check.
176
269
  */
177
- hasKeys: autoGuard(),
270
+ hasKeys(parent, keys) {
271
+ return keys.every((key) => hasKey(parent, key));
272
+ },
178
273
  /**
179
274
  * Checks that a parent value none of the keys.
180
275
  *
@@ -185,21 +280,17 @@ export const keyGuards = {
185
280
  * ```ts
186
281
  * import {check} from '@augment-vir/assert';
187
282
  *
188
- * check.lacksKeys({a: 0, b: 1}, [
189
- * 'b',
190
- * 'c',
191
- * ]); // returns `false`
192
- * check.lacksKeys({a: 0, b: 1}, [
193
- * 'c',
194
- * 'd',
195
- * ]); // returns `true`
283
+ * check.lacksKeys({a: 0, b: 1}, ['b', 'c']); // returns `false`
284
+ * check.lacksKeys({a: 0, b: 1}, ['c', 'd']); // returns `true`
196
285
  * ```
197
286
  *
198
287
  * @see
199
288
  * - {@link check.hasKeys} : the opposite check.
200
289
  * - {@link check.lacksKey} : the single-key check.
201
290
  */
202
- lacksKeys: autoGuard(),
291
+ lacksKeys(parent, keys) {
292
+ return keys.every((key) => !hasKey(parent, key));
293
+ },
203
294
  },
204
295
  assertWrap: {
205
296
  /**
@@ -222,7 +313,12 @@ export const keyGuards = {
222
313
  * @see
223
314
  * - {@link assertWrap.isNotKeyOf} : the opposite assertion.
224
315
  */
225
- 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
+ },
226
322
  /**
227
323
  * Asserts that a key is _not_ contained within a parent value. Returns the key if the
228
324
  * assertion passes.
@@ -243,7 +339,12 @@ export const keyGuards = {
243
339
  * @see
244
340
  * - {@link assertWrap.isKeyOf} : the opposite assertion.
245
341
  */
246
- 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
+ },
247
348
  /**
248
349
  * Asserts that a parent value has the key. Returns the parent if the assertion passes.
249
350
  *
@@ -264,7 +365,12 @@ export const keyGuards = {
264
365
  * - {@link assertWrap.lacksKey} : the opposite assertion.
265
366
  * - {@link assertWrap.hasKeys} : the multi-key assertion.
266
367
  */
267
- 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
+ },
268
374
  /**
269
375
  * Asserts that a parent value does not have the key. Returns the parent if the assertion
270
376
  * passes.
@@ -286,7 +392,12 @@ export const keyGuards = {
286
392
  * - {@link assertWrap.hasKey} : the opposite assertion.
287
393
  * - {@link assertWrap.lacksKeys} : the multi-key assertion.
288
394
  */
289
- 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
+ },
290
401
  /**
291
402
  * Asserts that a parent value has all the keys. Returns the parent if the assertion passes.
292
403
  *
@@ -297,14 +408,8 @@ export const keyGuards = {
297
408
  * ```ts
298
409
  * import {assertWrap} from '@augment-vir/assert';
299
410
  *
300
- * assertWrap.hasKeys({a: 0, b: 1}, [
301
- * 'a',
302
- * 'b',
303
- * ]); // returns `{a: 0, b: 1}`
304
- * assertWrap.hasKeys({a: 0, b: 1}, [
305
- * 'b',
306
- * 'c',
307
- * ]); // 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
308
413
  * ```
309
414
  *
310
415
  * @returns The parent if it has all the keys.
@@ -313,7 +418,13 @@ export const keyGuards = {
313
418
  * - {@link assertWrap.lacksKeys} : the opposite assertion.
314
419
  * - {@link assertWrap.hasKey} : the single-key assertion.
315
420
  */
316
- 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
+ },
317
428
  /**
318
429
  * Asserts that a parent value none of the keys. Returns the parent if the assertion passes.
319
430
  *
@@ -324,14 +435,8 @@ export const keyGuards = {
324
435
  * ```ts
325
436
  * import {assertWrap} from '@augment-vir/assert';
326
437
  *
327
- * assertWrap.lacksKeys({a: 0, b: 1}, [
328
- * 'b',
329
- * 'c',
330
- * ]); // throws an error
331
- * assertWrap.lacksKeys({a: 0, b: 1}, [
332
- * 'c',
333
- * 'd',
334
- * ]); // 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}`
335
440
  * ```
336
441
  *
337
442
  * @returns The parent if it does not have any of the keys.
@@ -340,7 +445,13 @@ export const keyGuards = {
340
445
  * - {@link assertWrap.hasKeys} : the opposite assertion.
341
446
  * - {@link assertWrap.lacksKey} : the single-key assertion.
342
447
  */
343
- 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
+ },
344
455
  },
345
456
  checkWrap: {
346
457
  /**
@@ -362,7 +473,14 @@ export const keyGuards = {
362
473
  * @see
363
474
  * - {@link checkWrap.isNotKeyOf} : the opposite check.
364
475
  */
365
- isKeyOf: autoGuard(),
476
+ isKeyOf(key, parent) {
477
+ if (hasKey(parent, key)) {
478
+ return key;
479
+ }
480
+ else {
481
+ return undefined;
482
+ }
483
+ },
366
484
  /**
367
485
  * Checks that a key is _not_ contained within a parent value. Returns the key if the check
368
486
  * passes, otherwise `undefined`.
@@ -382,7 +500,14 @@ export const keyGuards = {
382
500
  * @see
383
501
  * - {@link checkWrap.isKeyOf} : the opposite check.
384
502
  */
385
- isNotKeyOf: autoGuard(),
503
+ isNotKeyOf(key, parent) {
504
+ if (hasKey(parent, key)) {
505
+ return undefined;
506
+ }
507
+ else {
508
+ return key;
509
+ }
510
+ },
386
511
  /**
387
512
  * Checks that a parent value has the key. Returns the parent value if the check passes,
388
513
  * otherwise `undefined`.
@@ -403,7 +528,14 @@ export const keyGuards = {
403
528
  * - {@link checkWrap.lacksKey} : the opposite check.
404
529
  * - {@link checkWrap.hasKeys} : the multi-key check.
405
530
  */
406
- hasKey: autoGuard(),
531
+ hasKey(parent, key) {
532
+ if (hasKey(parent, key)) {
533
+ return parent;
534
+ }
535
+ else {
536
+ return undefined;
537
+ }
538
+ },
407
539
  /**
408
540
  * Checks that a parent value does not have the key. Returns the parent value if the check
409
541
  * passes, otherwise `undefined`.
@@ -424,7 +556,14 @@ export const keyGuards = {
424
556
  * - {@link checkWrap.hasKey} : the opposite check.
425
557
  * - {@link checkWrap.lacksKeys} : the multi-key check.
426
558
  */
427
- lacksKey: autoGuard(),
559
+ lacksKey(parent, key) {
560
+ if (hasKey(parent, key)) {
561
+ return undefined;
562
+ }
563
+ else {
564
+ return parent;
565
+ }
566
+ },
428
567
  /**
429
568
  * Checks that a parent value has all the keys. Returns the parent value if the check
430
569
  * passes, otherwise `undefined`.
@@ -436,14 +575,8 @@ export const keyGuards = {
436
575
  * ```ts
437
576
  * import {checkWrap} from '@augment-vir/assert';
438
577
  *
439
- * checkWrap.hasKeys({a: 0, b: 1}, [
440
- * 'a',
441
- * 'b',
442
- * ]); // returns `{a: 0, b: 1}`
443
- * checkWrap.hasKeys({a: 0, b: 1}, [
444
- * 'b',
445
- * 'c',
446
- * ]); // 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`
447
580
  * ```
448
581
  *
449
582
  * @returns The parent value if the check passes, otherwise `undefined`.
@@ -451,7 +584,14 @@ export const keyGuards = {
451
584
  * - {@link checkWrap.lacksKeys} : the opposite check.
452
585
  * - {@link checkWrap.hasKey} : the single-key check.
453
586
  */
454
- 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
+ },
455
595
  /**
456
596
  * Checks that a parent value none of the keys. Returns the parent value if the check
457
597
  * passes, otherwise `undefined`.
@@ -463,14 +603,8 @@ export const keyGuards = {
463
603
  * ```ts
464
604
  * import {checkWrap} from '@augment-vir/assert';
465
605
  *
466
- * checkWrap.lacksKeys({a: 0, b: 1}, [
467
- * 'b',
468
- * 'c',
469
- * ]); // returns `undefined`
470
- * checkWrap.lacksKeys({a: 0, b: 1}, [
471
- * 'c',
472
- * 'd',
473
- * ]); // 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}`
474
608
  * ```
475
609
  *
476
610
  * @returns The parent value if the check passes, otherwise `undefined`.
@@ -478,7 +612,14 @@ export const keyGuards = {
478
612
  * - {@link checkWrap.hasKeys} : the opposite check.
479
613
  * - {@link checkWrap.lacksKey} : the single-key check.
480
614
  */
481
- 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
+ },
482
623
  },
483
624
  waitUntil: {
484
625
  /**
@@ -502,7 +643,7 @@ export const keyGuards = {
502
643
  * @see
503
644
  * - {@link waitUntil.isNotKeyOf} : the opposite assertion.
504
645
  */
505
- isKeyOf: autoGuard(),
646
+ isKeyOf: createWaitUntil(assertions.isKeyOf),
506
647
  /**
507
648
  * Repeatedly calls a callback until its output is a key that is _not_ contained within the
508
649
  * first, parent value. Once the callback output passes, it is returned. If the attempts
@@ -524,7 +665,7 @@ export const keyGuards = {
524
665
  * @see
525
666
  * - {@link waitUntil.isNotKeyOf} : the opposite assertion.
526
667
  */
527
- isNotKeyOf: autoGuard(),
668
+ isNotKeyOf: createWaitUntil(assertions.isNotKeyOf),
528
669
  /**
529
670
  * Repeatedly calls a callback until its output is a parent value that has the first, key
530
671
  * input. Once the callback output passes, it is returned. If the attempts time out, an
@@ -551,7 +692,7 @@ export const keyGuards = {
551
692
  * - {@link waitUntil.lacksKey} : the opposite assertion.
552
693
  * - {@link waitUntil.hasKeys} : the multi-key assertion.
553
694
  */
554
- hasKey: autoGuard(),
695
+ hasKey: createWaitUntil(assertions.hasKey),
555
696
  /**
556
697
  * Repeatedly calls a callback until its output is a parent value that does not have the
557
698
  * first, key input. Once the callback output passes, it is returned. If the attempts time
@@ -578,7 +719,7 @@ export const keyGuards = {
578
719
  * - {@link waitUntil.hasKey} : the opposite assertion.
579
720
  * - {@link waitUntil.lacksKeys} : the multi-key assertion.
580
721
  */
581
- lacksKey: autoGuard(),
722
+ lacksKey: createWaitUntil(assertions.lacksKey),
582
723
  /**
583
724
  * Repeatedly calls a callback until its output is a parent value that has all of the first,
584
725
  * keys input. Once the callback output passes, it is returned. If the attempts time out, an
@@ -591,24 +732,12 @@ export const keyGuards = {
591
732
  * ```ts
592
733
  * import {waitUntil} from '@augment-vir/assert';
593
734
  *
594
- * await waitUntil.hasKeys(
595
- * [
596
- * 'a',
597
- * 'b',
598
- * ],
599
- * () => {
600
- * return {a: 0, b: 1};
601
- * },
602
- * ); // returns `{a: 0, b: 1}`
603
- * await waitUntil.hasKeys(
604
- * [
605
- * 'b',
606
- * 'c',
607
- * ],
608
- * () => {
609
- * return {a: 0, b: 1};
610
- * },
611
- * ); // 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
612
741
  * ```
613
742
  *
614
743
  * @returns The callback output once it passes.
@@ -617,7 +746,7 @@ export const keyGuards = {
617
746
  * - {@link waitUntil.lacksKeys} : the opposite assertion.
618
747
  * - {@link waitUntil.hasKey} : the single-key assertion.
619
748
  */
620
- hasKeys: autoGuard(),
749
+ hasKeys: createWaitUntil(assertions.hasKeys),
621
750
  /**
622
751
  * Repeatedly calls a callback until its output is a parent value that does not have any of
623
752
  * the first, keys input. Once the callback output passes, it is returned. If the attempts
@@ -630,24 +759,12 @@ export const keyGuards = {
630
759
  * ```ts
631
760
  * import {waitUntil} from '@augment-vir/assert';
632
761
  *
633
- * await waitUntil.hasKeys(
634
- * [
635
- * 'a',
636
- * 'b',
637
- * ],
638
- * () => {
639
- * return {a: 0, b: 1};
640
- * },
641
- * ); // throws an error
642
- * await waitUntil.hasKeys(
643
- * [
644
- * 'b',
645
- * 'c',
646
- * ],
647
- * () => {
648
- * return {a: 0, b: 1};
649
- * },
650
- * ); // 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}`
651
768
  * ```
652
769
  *
653
770
  * @returns The callback output once it passes.
@@ -656,6 +773,6 @@ export const keyGuards = {
656
773
  * - {@link waitUntil.hasKeys} : the opposite assertion.
657
774
  * - {@link waitUntil.lacksKey} : the single-key assertion.
658
775
  */
659
- lacksKeys: autoGuard(),
776
+ lacksKeys: createWaitUntil(assertions.lacksKeys),
660
777
  },
661
778
  };