@augment-vir/assert 30.0.0 → 30.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +11 -0
  2. package/dist/assertions/boolean.d.ts +443 -17
  3. package/dist/assertions/boolean.js +365 -8
  4. package/dist/assertions/boundary.d.ts +657 -13
  5. package/dist/assertions/boundary.js +537 -5
  6. package/dist/assertions/enum.d.ts +236 -8
  7. package/dist/assertions/enum.js +197 -5
  8. package/dist/assertions/equality/entry-equality.d.ts +287 -11
  9. package/dist/assertions/equality/entry-equality.js +243 -6
  10. package/dist/assertions/equality/json-equality.d.ts +244 -15
  11. package/dist/assertions/equality/json-equality.js +207 -11
  12. package/dist/assertions/equality/simple-equality.d.ts +849 -28
  13. package/dist/assertions/equality/simple-equality.js +712 -6
  14. package/dist/assertions/equality/ts-type-equality.d.ts +37 -1
  15. package/dist/assertions/equality/ts-type-equality.js +13 -1
  16. package/dist/assertions/extendable-assertions.d.ts +288 -120
  17. package/dist/assertions/extendable-assertions.js +32 -60
  18. package/dist/assertions/http.d.ts +217 -10
  19. package/dist/assertions/http.js +182 -6
  20. package/dist/assertions/instance.d.ts +189 -8
  21. package/dist/assertions/instance.js +159 -5
  22. package/dist/assertions/keys.d.ts +658 -13
  23. package/dist/assertions/keys.js +556 -5
  24. package/dist/assertions/length.d.ts +381 -9
  25. package/dist/assertions/length.js +309 -5
  26. package/dist/assertions/nullish.d.ts +169 -7
  27. package/dist/assertions/nullish.js +137 -6
  28. package/dist/assertions/numeric.d.ts +965 -11
  29. package/dist/assertions/numeric.js +819 -1
  30. package/dist/assertions/output.d.ts +107 -7
  31. package/dist/assertions/output.js +92 -5
  32. package/dist/assertions/primitive.d.ts +416 -13
  33. package/dist/assertions/primitive.js +352 -6
  34. package/dist/assertions/promise.d.ts +640 -21
  35. package/dist/assertions/promise.js +536 -15
  36. package/dist/assertions/regexp.d.ts +202 -3
  37. package/dist/assertions/regexp.js +173 -1
  38. package/dist/assertions/runtime-type.d.ts +1822 -41
  39. package/dist/assertions/runtime-type.js +1558 -35
  40. package/dist/assertions/throws.d.ts +265 -17
  41. package/dist/assertions/throws.js +229 -17
  42. package/dist/assertions/uuid.d.ts +233 -10
  43. package/dist/assertions/uuid.js +195 -6
  44. package/dist/assertions/values.d.ts +1086 -15
  45. package/dist/assertions/values.js +907 -6
  46. package/dist/augments/assertion.error.d.ts +2 -1
  47. package/dist/augments/assertion.error.js +2 -1
  48. package/dist/augments/guards/assert-wrap.d.ts +82 -37
  49. package/dist/augments/guards/assert-wrap.js +13 -2
  50. package/dist/augments/guards/assert.d.ts +30 -14
  51. package/dist/augments/guards/assert.js +21 -4
  52. package/dist/augments/guards/check-wrap.d.ts +94 -51
  53. package/dist/augments/guards/check-wrap.js +11 -3
  54. package/dist/augments/guards/check.d.ts +87 -37
  55. package/dist/augments/guards/check.js +9 -2
  56. package/dist/augments/guards/wait-until.d.ts +110 -103
  57. package/dist/augments/guards/wait-until.js +18 -3
  58. package/dist/augments/if-equals.d.ts +4 -2
  59. package/dist/guard-types/assert-wrap-function.d.ts +5 -2
  60. package/dist/guard-types/check-function.d.ts +5 -2
  61. package/dist/guard-types/check-wrap-wrapper-function.d.ts +4 -1
  62. package/dist/guard-types/guard-group.d.ts +7 -8
  63. package/dist/guard-types/wait-until-function.d.ts +8 -3
  64. package/dist/guard-types/wait-until-function.js +1 -1
  65. package/package.json +21 -8
@@ -4,34 +4,262 @@ import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
4
4
  export declare function isEnumValue<const Expected extends EnumBaseType>(child: unknown, checkEnum: Expected, failureMessage?: string | undefined): asserts child is Expected[keyof Expected];
5
5
  declare function isNotEnumValue<const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined): asserts child is Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
6
6
  export declare const enumGuards: {
7
- assertions: {
7
+ assert: {
8
8
  /**
9
- * Check if a child value is a valid member of a specific enum.
9
+ * Asserts that a child value is an enum member.
10
10
  *
11
11
  * Type guards the child value.
12
+ *
13
+ * @example
14
+ *
15
+ * ```ts
16
+ * import {assert} from '@augment-vir/assert';
17
+ *
18
+ * enum MyEnum {
19
+ * A = 'a',
20
+ * B = 'b',
21
+ * }
22
+ *
23
+ * assert.isEnumValue('a', MyEnum); // passes
24
+ * assert.isEnumValue('A', MyEnum); // fails
25
+ * ```
26
+ *
27
+ * @throws {@link AssertionError} If the child is not an enum member.
28
+ * @see
29
+ * - {@link assert.isNotEnumValue} : the opposite assertion.
12
30
  */
13
31
  isEnumValue: typeof isEnumValue;
14
32
  /**
15
- * Check if a child value is _not_ a valid member of a specific enum.
33
+ * Asserts that a child value is _not_ an enum member.
34
+ *
35
+ * Type guards the child value.
36
+ *
37
+ * @example
38
+ *
39
+ * ```ts
40
+ * import {assert} from '@augment-vir/assert';
41
+ *
42
+ * enum MyEnum {
43
+ * A = 'a',
44
+ * B = 'b',
45
+ * }
46
+ *
47
+ * assert.isNotEnumValue('a', MyEnum); // fails
48
+ * assert.isNotEnumValue('A', MyEnum); // passes
49
+ * ```
16
50
  *
17
- * Type guards the child value when possible.
51
+ * @throws {@link AssertionError} If the child is an enum member.
52
+ * @see
53
+ * - {@link assert.isEnumValue} : the opposite assertion.
18
54
  */
19
55
  isNotEnumValue: typeof isNotEnumValue;
20
56
  };
21
- checkOverrides: {
57
+ check: {
58
+ /**
59
+ * Checks that a child value is an enum member.
60
+ *
61
+ * Type guards the child value.
62
+ *
63
+ * @example
64
+ *
65
+ * ```ts
66
+ * import {check} from '@augment-vir/assert';
67
+ *
68
+ * enum MyEnum {
69
+ * A = 'a',
70
+ * B = 'b',
71
+ * }
72
+ *
73
+ * check.isEnumValue('a', MyEnum); // returns `true`
74
+ * check.isEnumValue('A', MyEnum); // returns `false`
75
+ * ```
76
+ *
77
+ * @see
78
+ * - {@link check.isNotEnumValue} : the opposite check.
79
+ */
22
80
  isEnumValue: <const Expected extends EnumBaseType>(child: unknown, checkEnum: Expected) => child is Expected[keyof Expected];
81
+ /**
82
+ * Checks that a child value is _not_ an enum member.
83
+ *
84
+ * Type guards the child value.
85
+ *
86
+ * @example
87
+ *
88
+ * ```ts
89
+ * import {check} from '@augment-vir/assert';
90
+ *
91
+ * enum MyEnum {
92
+ * A = 'a',
93
+ * B = 'b',
94
+ * }
95
+ *
96
+ * check.isNotEnumValue('a', MyEnum); // returns `false`
97
+ * check.isNotEnumValue('A', MyEnum); // returns `true`
98
+ * ```
99
+ *
100
+ * @see
101
+ * - {@link check.isEnumValue} : the opposite check.
102
+ */
23
103
  isNotEnumValue: <const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected) => child is Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
24
104
  };
25
- assertWrapOverrides: {
105
+ assertWrap: {
106
+ /**
107
+ * Asserts that a child value is an enum member. Returns the child value if the assertion
108
+ * passes.
109
+ *
110
+ * Type guards the child value.
111
+ *
112
+ * @example
113
+ *
114
+ * ```ts
115
+ * import {assertWrap} from '@augment-vir/assert';
116
+ *
117
+ * enum MyEnum {
118
+ * A = 'a',
119
+ * B = 'b',
120
+ * }
121
+ *
122
+ * assertWrap.isEnumValue('a', MyEnum); // returns `'a'`
123
+ * assertWrap.isEnumValue('A', MyEnum); // throws an error
124
+ * ```
125
+ *
126
+ * @returns The child value if it is an enum member.
127
+ * @throws {@link AssertionError} If the child is not an enum member.
128
+ * @see
129
+ * - {@link assertWrap.isNotEnumValue} : the opposite assertion.
130
+ */
26
131
  isEnumValue: <const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => NarrowToExpected<Actual, Expected[keyof Expected]>;
132
+ /**
133
+ * Asserts that a child value is _not_ an enum member. Returns the child value if the
134
+ * assertion passes.
135
+ *
136
+ * Type guards the child value.
137
+ *
138
+ * @example
139
+ *
140
+ * ```ts
141
+ * import {assertWrap} from '@augment-vir/assert';
142
+ *
143
+ * enum MyEnum {
144
+ * A = 'a',
145
+ * B = 'b',
146
+ * }
147
+ *
148
+ * assertWrap.isNotEnumValue('a', MyEnum); // throws an error
149
+ * assertWrap.isNotEnumValue('A', MyEnum); // returns `'A'`
150
+ * ```
151
+ *
152
+ * @returns The child value if it is not an enum member.
153
+ * @throws {@link AssertionError} If the child is an enum member.
154
+ * @see
155
+ * - {@link assertWrap.isEnumValue} : the opposite assertion.
156
+ */
27
157
  isNotEnumValue: <const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
28
158
  };
29
- checkWrapOverrides: {
159
+ checkWrap: {
160
+ /**
161
+ * Checks that a child value is an enum member. Returns the child value if the check passes,
162
+ * otherwise `undefined`.
163
+ *
164
+ * Type guards the child value.
165
+ *
166
+ * @example
167
+ *
168
+ * ```ts
169
+ * import {checkWrap} from '@augment-vir/assert';
170
+ *
171
+ * enum MyEnum {
172
+ * A = 'a',
173
+ * B = 'b',
174
+ * }
175
+ *
176
+ * checkWrap.isEnumValue('a', MyEnum); // returns `'a'`
177
+ * checkWrap.isEnumValue('A', MyEnum); // returns `undefined`
178
+ * ```
179
+ *
180
+ * @returns The child value if the check passes, otherwise `undefined`.
181
+ * @see
182
+ * - {@link checkWrap.isNotEnumValue} : the opposite check.
183
+ */
30
184
  isEnumValue: <const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected) => NarrowToExpected<Actual, Expected[keyof Expected]> | undefined;
185
+ /**
186
+ * Checks that a child value is _not_ an enum member. Returns the child value if the check
187
+ * passes, otherwise `undefined`.
188
+ *
189
+ * Type guards the child value.
190
+ *
191
+ * @example
192
+ *
193
+ * ```ts
194
+ * import {checkWrap} from '@augment-vir/assert';
195
+ *
196
+ * enum MyEnum {
197
+ * A = 'a',
198
+ * B = 'b',
199
+ * }
200
+ *
201
+ * checkWrap.isNotEnumValue('a', MyEnum); // returns `undefined`
202
+ * checkWrap.isNotEnumValue('A', MyEnum); // returns `'A'`
203
+ * ```
204
+ *
205
+ * @returns The child value if the check passes, otherwise `undefined`.
206
+ * @see
207
+ * - {@link checkWrap.isEnumValue} : the opposite check.
208
+ */
31
209
  isNotEnumValue: <const Actual, const Expected extends EnumBaseType>(child: Actual, checkEnum: Expected) => Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`> | undefined;
32
210
  };
33
- waitUntilOverrides: {
211
+ waitUntil: {
212
+ /**
213
+ * Repeatedly calls a callback until its output is an enum member. Once the callback output
214
+ * passes, it is returned. If the attempts time out, an error is thrown.
215
+ *
216
+ * Performs no type guarding.
217
+ *
218
+ * @example
219
+ *
220
+ * ```ts
221
+ * import {waitUntil} from '@augment-vir/assert';
222
+ *
223
+ * enum MyEnum {
224
+ * A = 'a',
225
+ * B = 'b',
226
+ * }
227
+ *
228
+ * await waitUntil.isEnumValue(MyEnum, () => 'a'); // returns `'a'`
229
+ * await waitUntil.isEnumValue(MyEnum, () => 'A'); // throws an error
230
+ * ```
231
+ *
232
+ * @returns The callback output once it passes.
233
+ * @throws {@link AssertionError} On timeout.
234
+ * @see
235
+ * - {@link waitUntil.isNotEnumValue} : the opposite assertion.
236
+ */
34
237
  isEnumValue: <const Actual, const Expected extends EnumBaseType>(checkEnum: Expected, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, Expected[keyof Expected]>>;
238
+ /**
239
+ * Repeatedly calls a callback until its output is _not_ an enum member. Once the callback
240
+ * output passes, it is returned. If the attempts time out, an error is thrown.
241
+ *
242
+ * Performs no type guarding.
243
+ *
244
+ * @example
245
+ *
246
+ * ```ts
247
+ * import {waitUntil} from '@augment-vir/assert';
248
+ *
249
+ * enum MyEnum {
250
+ * A = 'a',
251
+ * B = 'b',
252
+ * }
253
+ *
254
+ * await waitUntil.isNotEnumValue(MyEnum, () => 'a'); // throws an error
255
+ * await waitUntil.isNotEnumValue(MyEnum, () => 'A'); // returns `'A'`
256
+ * ```
257
+ *
258
+ * @returns The callback output once it passes.
259
+ * @throws {@link AssertionError} On timeout.
260
+ * @see
261
+ * - {@link waitUntil.isEnumValue} : the opposite assertion.
262
+ */
35
263
  isNotEnumValue: <const Actual, const Expected extends EnumBaseType>(checkEnum: Expected, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>>;
36
264
  };
37
265
  };
@@ -22,21 +22,213 @@ const assertions = {
22
22
  isNotEnumValue,
23
23
  };
24
24
  export const enumGuards = {
25
- assertions,
26
- checkOverrides: {
25
+ assert: assertions,
26
+ check: {
27
+ /**
28
+ * Checks that a child value is an enum member.
29
+ *
30
+ * Type guards the child value.
31
+ *
32
+ * @example
33
+ *
34
+ * ```ts
35
+ * import {check} from '@augment-vir/assert';
36
+ *
37
+ * enum MyEnum {
38
+ * A = 'a',
39
+ * B = 'b',
40
+ * }
41
+ *
42
+ * check.isEnumValue('a', MyEnum); // returns `true`
43
+ * check.isEnumValue('A', MyEnum); // returns `false`
44
+ * ```
45
+ *
46
+ * @see
47
+ * - {@link check.isNotEnumValue} : the opposite check.
48
+ */
27
49
  isEnumValue: autoGuard(),
50
+ /**
51
+ * Checks that a child value is _not_ an enum member.
52
+ *
53
+ * Type guards the child value.
54
+ *
55
+ * @example
56
+ *
57
+ * ```ts
58
+ * import {check} from '@augment-vir/assert';
59
+ *
60
+ * enum MyEnum {
61
+ * A = 'a',
62
+ * B = 'b',
63
+ * }
64
+ *
65
+ * check.isNotEnumValue('a', MyEnum); // returns `false`
66
+ * check.isNotEnumValue('A', MyEnum); // returns `true`
67
+ * ```
68
+ *
69
+ * @see
70
+ * - {@link check.isEnumValue} : the opposite check.
71
+ */
28
72
  isNotEnumValue: autoGuard(),
29
73
  },
30
- assertWrapOverrides: {
74
+ assertWrap: {
75
+ /**
76
+ * Asserts that a child value is an enum member. Returns the child value if the assertion
77
+ * passes.
78
+ *
79
+ * Type guards the child value.
80
+ *
81
+ * @example
82
+ *
83
+ * ```ts
84
+ * import {assertWrap} from '@augment-vir/assert';
85
+ *
86
+ * enum MyEnum {
87
+ * A = 'a',
88
+ * B = 'b',
89
+ * }
90
+ *
91
+ * assertWrap.isEnumValue('a', MyEnum); // returns `'a'`
92
+ * assertWrap.isEnumValue('A', MyEnum); // throws an error
93
+ * ```
94
+ *
95
+ * @returns The child value if it is an enum member.
96
+ * @throws {@link AssertionError} If the child is not an enum member.
97
+ * @see
98
+ * - {@link assertWrap.isNotEnumValue} : the opposite assertion.
99
+ */
31
100
  isEnumValue: autoGuard(),
101
+ /**
102
+ * Asserts that a child value is _not_ an enum member. Returns the child value if the
103
+ * assertion passes.
104
+ *
105
+ * Type guards the child value.
106
+ *
107
+ * @example
108
+ *
109
+ * ```ts
110
+ * import {assertWrap} from '@augment-vir/assert';
111
+ *
112
+ * enum MyEnum {
113
+ * A = 'a',
114
+ * B = 'b',
115
+ * }
116
+ *
117
+ * assertWrap.isNotEnumValue('a', MyEnum); // throws an error
118
+ * assertWrap.isNotEnumValue('A', MyEnum); // returns `'A'`
119
+ * ```
120
+ *
121
+ * @returns The child value if it is not an enum member.
122
+ * @throws {@link AssertionError} If the child is an enum member.
123
+ * @see
124
+ * - {@link assertWrap.isEnumValue} : the opposite assertion.
125
+ */
32
126
  isNotEnumValue: autoGuard(),
33
127
  },
34
- checkWrapOverrides: {
128
+ checkWrap: {
129
+ /**
130
+ * Checks that a child value is an enum member. Returns the child value if the check passes,
131
+ * otherwise `undefined`.
132
+ *
133
+ * Type guards the child value.
134
+ *
135
+ * @example
136
+ *
137
+ * ```ts
138
+ * import {checkWrap} from '@augment-vir/assert';
139
+ *
140
+ * enum MyEnum {
141
+ * A = 'a',
142
+ * B = 'b',
143
+ * }
144
+ *
145
+ * checkWrap.isEnumValue('a', MyEnum); // returns `'a'`
146
+ * checkWrap.isEnumValue('A', MyEnum); // returns `undefined`
147
+ * ```
148
+ *
149
+ * @returns The child value if the check passes, otherwise `undefined`.
150
+ * @see
151
+ * - {@link checkWrap.isNotEnumValue} : the opposite check.
152
+ */
35
153
  isEnumValue: autoGuard(),
154
+ /**
155
+ * Checks that a child value is _not_ an enum member. Returns the child value if the check
156
+ * passes, otherwise `undefined`.
157
+ *
158
+ * Type guards the child value.
159
+ *
160
+ * @example
161
+ *
162
+ * ```ts
163
+ * import {checkWrap} from '@augment-vir/assert';
164
+ *
165
+ * enum MyEnum {
166
+ * A = 'a',
167
+ * B = 'b',
168
+ * }
169
+ *
170
+ * checkWrap.isNotEnumValue('a', MyEnum); // returns `undefined`
171
+ * checkWrap.isNotEnumValue('A', MyEnum); // returns `'A'`
172
+ * ```
173
+ *
174
+ * @returns The child value if the check passes, otherwise `undefined`.
175
+ * @see
176
+ * - {@link checkWrap.isEnumValue} : the opposite check.
177
+ */
36
178
  isNotEnumValue: autoGuard(),
37
179
  },
38
- waitUntilOverrides: {
180
+ waitUntil: {
181
+ /**
182
+ * Repeatedly calls a callback until its output is an enum member. Once the callback output
183
+ * passes, it is returned. If the attempts time out, an error is thrown.
184
+ *
185
+ * Performs no type guarding.
186
+ *
187
+ * @example
188
+ *
189
+ * ```ts
190
+ * import {waitUntil} from '@augment-vir/assert';
191
+ *
192
+ * enum MyEnum {
193
+ * A = 'a',
194
+ * B = 'b',
195
+ * }
196
+ *
197
+ * await waitUntil.isEnumValue(MyEnum, () => 'a'); // returns `'a'`
198
+ * await waitUntil.isEnumValue(MyEnum, () => 'A'); // throws an error
199
+ * ```
200
+ *
201
+ * @returns The callback output once it passes.
202
+ * @throws {@link AssertionError} On timeout.
203
+ * @see
204
+ * - {@link waitUntil.isNotEnumValue} : the opposite assertion.
205
+ */
39
206
  isEnumValue: autoGuard(),
207
+ /**
208
+ * Repeatedly calls a callback until its output is _not_ an enum member. Once the callback
209
+ * output passes, it is returned. If the attempts time out, an error is thrown.
210
+ *
211
+ * Performs no type guarding.
212
+ *
213
+ * @example
214
+ *
215
+ * ```ts
216
+ * import {waitUntil} from '@augment-vir/assert';
217
+ *
218
+ * enum MyEnum {
219
+ * A = 'a',
220
+ * B = 'b',
221
+ * }
222
+ *
223
+ * await waitUntil.isNotEnumValue(MyEnum, () => 'a'); // throws an error
224
+ * await waitUntil.isNotEnumValue(MyEnum, () => 'A'); // returns `'A'`
225
+ * ```
226
+ *
227
+ * @returns The callback output once it passes.
228
+ * @throws {@link AssertionError} On timeout.
229
+ * @see
230
+ * - {@link waitUntil.isEnumValue} : the opposite assertion.
231
+ */
40
232
  isNotEnumValue: autoGuard(),
41
233
  },
42
234
  };