@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.
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 +17 -4
@@ -7,6 +7,7 @@ import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
7
7
  * default.
8
8
  *
9
9
  * @category Assert : Util
10
+ * @category Package : @augment-vir/assert
10
11
  * @example
11
12
  *
12
13
  * ```ts
@@ -32,7 +33,7 @@ import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
32
33
  * ```
33
34
  *
34
35
  * @param FunctionToCall The function type that your custom asserter will be run on.
35
- * @package @augment-vir/assert
36
+ * @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
36
37
  */
37
38
  export type CustomOutputAsserter<FunctionToCall extends AnyFunction> = (actual: Awaited<ReturnType<FunctionToCall>>, expected: Awaited<ReturnType<FunctionToCall>>, failureMessage?: string | undefined) => void;
38
39
  type OutputReturn<FunctionToCall extends AnyFunction, Return> = Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? IsAny<ReturnType<FunctionToCall>> extends true ? Return : Promise<Return> : Return;
@@ -57,26 +58,125 @@ export type OutputWaitUntilWithAsserter = <const FunctionToCall extends AnyFunct
57
58
  export declare function waitUntilOutput<const FunctionToCall extends AnyFunction>(functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<Awaited<ReturnType<NoInfer<FunctionToCall>>>>;
58
59
  export declare function waitUntilOutput<const FunctionToCall extends AnyFunction>(asserter: CustomOutputAsserter<NoInfer<FunctionToCall>>, functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<Awaited<ReturnType<NoInfer<FunctionToCall>>>>;
59
60
  export declare const outputGuards: {
60
- assertions: {
61
+ assert: {
61
62
  /**
62
- * Checks that the output of the given function deeply equals expectations. A custom asserter
63
+ * Asserts that the output of the given function deeply equals expectations. A custom asserter
63
64
  * can optionally be provided as the first argument to change the expectation checking from
64
65
  * "deeply equals" to whatever you want.
65
66
  *
66
67
  * Performs no type guarding.
68
+ *
69
+ * ```ts
70
+ * import {assert} from '@augment-vir/assert';
71
+ *
72
+ * assert.output((input: number) => String(input), [5], '5'); // passes
73
+ * assert.output((input: number) => String(input), [10], '5'); // fails
74
+ *
75
+ * assert.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // fails
76
+ * assert.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // passes
77
+ * ```
78
+ *
79
+ * @throws {@link AssertionError} If the assertion fails.
67
80
  */
68
81
  output: typeof assertOutput;
69
82
  };
70
- checkOverrides: {
83
+ check: {
84
+ /**
85
+ * Checks that the output of the given function deeply equals expectations. A custom
86
+ * asserter can optionally be provided as the first argument to change the expectation
87
+ * checking from the default "deeply equals" to whatever you want.
88
+ *
89
+ * Performs no type guarding.
90
+ *
91
+ * ```ts
92
+ * import {check} from '@augment-vir/assert';
93
+ *
94
+ * check.output((input: number) => String(input), [5], '5'); // returns `true`
95
+ * check.output((input: number) => String(input), [10], '5'); // returns `false`
96
+ *
97
+ * check.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // returns `false`
98
+ * check.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `true`
99
+ * ```
100
+ */
71
101
  output: typeof checkOutput;
72
102
  };
73
- assertWrapOverrides: {
103
+ assertWrap: {
104
+ /**
105
+ * Asserts that the output of the given function deeply equals expectations. A custom
106
+ * asserter can optionally be provided as the first argument to change the expectation
107
+ * checking from the default "deeply equals" to whatever you want. Returns the output if the
108
+ * assertion passes.
109
+ *
110
+ * Performs no type guarding.
111
+ *
112
+ * ```ts
113
+ * import {assertWrap} from '@augment-vir/assert';
114
+ *
115
+ * assertWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
116
+ * assertWrap.output((input: number) => String(input), [10], '5'); // throws an error
117
+ *
118
+ * assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // throws an error
119
+ * assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`
120
+ * ```
121
+ *
122
+ * @returns The output if the assertion passes.
123
+ * @throws {@link AssertionError} If the assertion fails.
124
+ */
74
125
  output: typeof assertWrapOutput;
75
126
  };
76
- checkWrapOverrides: {
127
+ checkWrap: {
128
+ /**
129
+ * Asserts that the output of the given function deeply equals expectations. A custom
130
+ * asserter can optionally be provided as the first argument to change the expectation
131
+ * checking from the default "deeply equals" to whatever you want. Returns the output if the
132
+ * check passes, otherwise `undefined`.
133
+ *
134
+ * Performs no type guarding.
135
+ *
136
+ * ```ts
137
+ * import {checkWrap} from '@augment-vir/assert';
138
+ *
139
+ * checkWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
140
+ * checkWrap.output((input: number) => String(input), [10], '5'); // returns `undefined`
141
+ *
142
+ * checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // returns `undefined`
143
+ * checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`
144
+ * ```
145
+ *
146
+ * @returns The output if the assertion passes, otherwise `undefined`.
147
+ */
77
148
  output: typeof checkWrapOutput;
78
149
  };
79
- waitUntilOverrides: {
150
+ waitUntil: {
151
+ /**
152
+ * Repeatedly calls a callback until its output deeply equals expectations. A custom
153
+ * asserter can optionally be provided as the first argument to change the expectation
154
+ * checking from the default "deeply equals" to whatever you want.
155
+ *
156
+ * Performs no type guarding.
157
+ *
158
+ * ```ts
159
+ * import {waitUntil} from '@augment-vir/assert';
160
+ *
161
+ * await waitUntil.output((input: number) => String(input), [5], '5'); // returns `'5'`
162
+ * await waitUntil.output((input: number) => String(input), [10], '5'); // throws an error
163
+ *
164
+ * await waitUntil.output(
165
+ * assert.isLengthAtLeast,
166
+ * (input: number) => String(input),
167
+ * [5],
168
+ * 2,
169
+ * ); // throws an error
170
+ * await waitUntil.output(
171
+ * assert.isLengthAtLeast,
172
+ * (input: number) => String(input),
173
+ * [10],
174
+ * 2,
175
+ * ); // returns `10`
176
+ * ```
177
+ *
178
+ * @throws {@link AssertionError} If the assertion fails.
179
+ */
80
180
  output: typeof waitUntilOutput;
81
181
  };
82
182
  };
@@ -157,17 +157,104 @@ const assertions = {
157
157
  output: assertOutput,
158
158
  };
159
159
  export const outputGuards = {
160
- assertions,
161
- checkOverrides: {
160
+ assert: assertions,
161
+ check: {
162
+ /**
163
+ * Checks that the output of the given function deeply equals expectations. A custom
164
+ * asserter can optionally be provided as the first argument to change the expectation
165
+ * checking from the default "deeply equals" to whatever you want.
166
+ *
167
+ * Performs no type guarding.
168
+ *
169
+ * ```ts
170
+ * import {check} from '@augment-vir/assert';
171
+ *
172
+ * check.output((input: number) => String(input), [5], '5'); // returns `true`
173
+ * check.output((input: number) => String(input), [10], '5'); // returns `false`
174
+ *
175
+ * check.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // returns `false`
176
+ * check.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `true`
177
+ * ```
178
+ */
162
179
  output: checkOutput,
163
180
  },
164
- assertWrapOverrides: {
181
+ assertWrap: {
182
+ /**
183
+ * Asserts that the output of the given function deeply equals expectations. A custom
184
+ * asserter can optionally be provided as the first argument to change the expectation
185
+ * checking from the default "deeply equals" to whatever you want. Returns the output if the
186
+ * assertion passes.
187
+ *
188
+ * Performs no type guarding.
189
+ *
190
+ * ```ts
191
+ * import {assertWrap} from '@augment-vir/assert';
192
+ *
193
+ * assertWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
194
+ * assertWrap.output((input: number) => String(input), [10], '5'); // throws an error
195
+ *
196
+ * assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // throws an error
197
+ * assertWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`
198
+ * ```
199
+ *
200
+ * @returns The output if the assertion passes.
201
+ * @throws {@link AssertionError} If the assertion fails.
202
+ */
165
203
  output: assertWrapOutput,
166
204
  },
167
- checkWrapOverrides: {
205
+ checkWrap: {
206
+ /**
207
+ * Asserts that the output of the given function deeply equals expectations. A custom
208
+ * asserter can optionally be provided as the first argument to change the expectation
209
+ * checking from the default "deeply equals" to whatever you want. Returns the output if the
210
+ * check passes, otherwise `undefined`.
211
+ *
212
+ * Performs no type guarding.
213
+ *
214
+ * ```ts
215
+ * import {checkWrap} from '@augment-vir/assert';
216
+ *
217
+ * checkWrap.output((input: number) => String(input), [5], '5'); // returns `'5'`
218
+ * checkWrap.output((input: number) => String(input), [10], '5'); // returns `undefined`
219
+ *
220
+ * checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [5], 2); // returns `undefined`
221
+ * checkWrap.output(assert.isLengthAtLeast, (input: number) => String(input), [10], 2); // returns `10`
222
+ * ```
223
+ *
224
+ * @returns The output if the assertion passes, otherwise `undefined`.
225
+ */
168
226
  output: checkWrapOutput,
169
227
  },
170
- waitUntilOverrides: {
228
+ waitUntil: {
229
+ /**
230
+ * Repeatedly calls a callback until its output deeply equals expectations. A custom
231
+ * asserter can optionally be provided as the first argument to change the expectation
232
+ * checking from the default "deeply equals" to whatever you want.
233
+ *
234
+ * Performs no type guarding.
235
+ *
236
+ * ```ts
237
+ * import {waitUntil} from '@augment-vir/assert';
238
+ *
239
+ * await waitUntil.output((input: number) => String(input), [5], '5'); // returns `'5'`
240
+ * await waitUntil.output((input: number) => String(input), [10], '5'); // throws an error
241
+ *
242
+ * await waitUntil.output(
243
+ * assert.isLengthAtLeast,
244
+ * (input: number) => String(input),
245
+ * [5],
246
+ * 2,
247
+ * ); // throws an error
248
+ * await waitUntil.output(
249
+ * assert.isLengthAtLeast,
250
+ * (input: number) => String(input),
251
+ * [10],
252
+ * 2,
253
+ * ); // returns `10`
254
+ * ```
255
+ *
256
+ * @throws {@link AssertionError} If the assertion fails.
257
+ */
171
258
  output: waitUntilOutput,
172
259
  },
173
260
  };