@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
@@ -9,34 +9,215 @@ constructor: Constructor<Instance>,
9
9
  failureMessage?: string | undefined): asserts instance is Instance;
10
10
  declare function notInstanceOf<const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>, failureMessage?: string | undefined): asserts instance is Exclude<Actual, Instance>;
11
11
  export declare const instanceGuards: {
12
- assertions: {
12
+ assert: {
13
13
  /**
14
- * Check if a value is an instance of the given class constructor.
14
+ * Asserts that a value is an instance of the given class constructor.
15
15
  *
16
16
  * Type guards the value.
17
+ *
18
+ * @example
19
+ *
20
+ * ```ts
21
+ * import {assert} from '@augment-vir/assert';
22
+ *
23
+ * assert.instanceOf(/abc/, RegExp); // passes
24
+ * assert.instanceOf('abc', RegExp); // fails
25
+ * ```
26
+ *
27
+ * @throws {@link AssertionError} If the value is not an instance of the given class
28
+ * constructor.
29
+ * @see
30
+ * - {@link assert.notInstanceOf} : the opposite assertion.
17
31
  */
18
32
  instanceOf: typeof instanceOf;
19
33
  /**
20
- * Check if a value is _not_ an instance of the given class constructor.
34
+ * Asserts that a value is _not_ an instance of the given class constructor.
35
+ *
36
+ * Type guards the value.
37
+ *
38
+ * @example
39
+ *
40
+ * ```ts
41
+ * import {assert} from '@augment-vir/assert';
21
42
  *
22
- * Type guards the value when possible.
43
+ * assert.notInstanceOf(/abc/, RegExp); // fails
44
+ * assert.notInstanceOf('abc', RegExp); // passes
45
+ * ```
46
+ *
47
+ * @throws {@link AssertionError} If the value is an instance of the given class constructor.
48
+ * @see
49
+ * - {@link assert.instanceOf} : the opposite assertion.
23
50
  */
24
51
  notInstanceOf: typeof notInstanceOf;
25
52
  };
26
- checkOverrides: {
53
+ check: {
54
+ /**
55
+ * Checks that a value is an instance of the given class constructor.
56
+ *
57
+ * Type guards the value.
58
+ *
59
+ * @example
60
+ *
61
+ * ```ts
62
+ * import {check} from '@augment-vir/assert';
63
+ *
64
+ * check.instanceOf(/abc/, RegExp); // returns `true`
65
+ * check.instanceOf('abc', RegExp); // returns `false`
66
+ * ```
67
+ *
68
+ * @see
69
+ * - {@link check.notInstanceOf} : the opposite check.
70
+ */
27
71
  instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>) => instance is Instance;
72
+ /**
73
+ * Checks that a value is _not_ an instance of the given class constructor.
74
+ *
75
+ * Type guards the value.
76
+ *
77
+ * @example
78
+ *
79
+ * ```ts
80
+ * import {check} from '@augment-vir/assert';
81
+ *
82
+ * check.notInstanceOf(/abc/, RegExp); // returns `false`
83
+ * check.notInstanceOf('abc', RegExp); // returns `true`
84
+ * ```
85
+ *
86
+ * @see
87
+ * - {@link check.instanceOf} : the opposite check.
88
+ */
28
89
  notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>) => instance is Exclude<Actual, Instance>;
29
90
  };
30
- assertWrapOverrides: {
91
+ assertWrap: {
92
+ /**
93
+ * Asserts that a value is an instance of the given class constructor. Returns the value if
94
+ * the assertion passes.
95
+ *
96
+ * Type guards the value.
97
+ *
98
+ * @example
99
+ *
100
+ * ```ts
101
+ * import {assertWrap} from '@augment-vir/assert';
102
+ *
103
+ * assertWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
104
+ * assertWrap.instanceOf('abc', RegExp); // throws an error
105
+ * ```
106
+ *
107
+ * @throws {@link AssertionError} If the value is not an instance of the given class
108
+ * constructor.
109
+ * @see
110
+ * - {@link assertWrap.notInstanceOf} : the opposite assertion.
111
+ */
31
112
  instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>, failureMessage?: string | undefined) => Instance;
113
+ /**
114
+ * Asserts that a value is _not_ an instance of the given class constructor. Returns the
115
+ * value if the assertion passes.
116
+ *
117
+ * Type guards the value.
118
+ *
119
+ * @example
120
+ *
121
+ * ```ts
122
+ * import {assertWrap} from '@augment-vir/assert';
123
+ *
124
+ * assertWrap.notInstanceOf(/abc/, RegExp); // throws an error
125
+ * assertWrap.notInstanceOf('abc', RegExp); // returns `'abc'`
126
+ * ```
127
+ *
128
+ * @throws {@link AssertionError} If the value is an instance of the given class
129
+ * constructor.
130
+ * @see
131
+ * - {@link assertWrap.instanceOf} : the opposite assertion.
132
+ */
32
133
  notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>, failureMessage?: string | undefined) => Exclude<Actual, Instance>;
33
134
  };
34
- checkWrapOverrides: {
135
+ checkWrap: {
136
+ /**
137
+ * Checks that a value is an instance of the given class constructor. Returns the value if
138
+ * the check passes, otherwise `undefined`.
139
+ *
140
+ * Type guards the value.
141
+ *
142
+ * @example
143
+ *
144
+ * ```ts
145
+ * import {checkWrap} from '@augment-vir/assert';
146
+ *
147
+ * checkWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
148
+ * checkWrap.instanceOf('abc', RegExp); // returns `undefined`
149
+ * ```
150
+ *
151
+ * @returns The value if the check passes, otherwise `undefined`.
152
+ * @see
153
+ * - {@link checkWrap.notInstanceOf} : the opposite check.
154
+ */
35
155
  instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>) => Instance | undefined;
156
+ /**
157
+ * Checks that a value is _not_ an instance of the given class constructor. Returns the
158
+ * value if the check passes, otherwise `undefined`.
159
+ *
160
+ * Type guards the value.
161
+ *
162
+ * @example
163
+ *
164
+ * ```ts
165
+ * import {checkWrap} from '@augment-vir/assert';
166
+ *
167
+ * checkWrap.notInstanceOf(/abc/, RegExp); // returns `undefined`
168
+ * checkWrap.notInstanceOf('abc', RegExp); // returns `'abc'`
169
+ * ```
170
+ *
171
+ * @returns The value if the check passes, otherwise `undefined`.
172
+ * @see
173
+ * - {@link checkWrap.instanceOf} : the opposite check.
174
+ */
36
175
  notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>) => Exclude<Actual, Instance> | undefined;
37
176
  };
38
- waitUntilOverrides: {
177
+ waitUntil: {
178
+ /**
179
+ * Repeatedly calls a callback until its output is an instance of the given class
180
+ * constructor. Once the callback output passes, it is returned. If the attempts time out,
181
+ * an error is thrown.
182
+ *
183
+ * Type guards the value.
184
+ *
185
+ * @example
186
+ *
187
+ * ```ts
188
+ * import {waitUntil} from '@augment-vir/assert';
189
+ *
190
+ * await waitUntil.instanceOf(RegExp, () => /abc/); // returns `/abc/`
191
+ * await waitUntil.instanceOf(RegExp, () => 'abc'); // throws an error
192
+ * ```
193
+ *
194
+ * @returns The callback output once it passes.
195
+ * @throws {@link AssertionError} On timeout.
196
+ * @see
197
+ * - {@link waitUntil.notInstanceOf} : the opposite assertion.
198
+ */
39
199
  instanceOf: <const Instance>(constructor: Constructor<Instance>, callback: () => MaybePromise<unknown>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Instance>;
200
+ /**
201
+ * Repeatedly calls a callback until its output is not an instance of the given class
202
+ * constructor. Once the callback output passes, it is returned. If the attempts time out,
203
+ * an error is thrown.
204
+ *
205
+ * Type guards the value.
206
+ *
207
+ * @example
208
+ *
209
+ * ```ts
210
+ * import {waitUntil} from '@augment-vir/assert';
211
+ *
212
+ * await waitUntil.instanceOf(RegExp, () => /abc/); // throws an error
213
+ * await waitUntil.instanceOf(RegExp, () => 'abc'); // returns `'abc'`
214
+ * ```
215
+ *
216
+ * @returns The callback output once it passes.
217
+ * @throws {@link AssertionError} On timeout.
218
+ * @see
219
+ * - {@link waitUntil.instanceOf} : the opposite assertion.
220
+ */
40
221
  notInstanceOf: <const Actual, const Instance>(constructor: Constructor<Instance>, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, Instance>>;
41
222
  };
42
223
  };
@@ -21,21 +21,175 @@ const assertions = {
21
21
  notInstanceOf,
22
22
  };
23
23
  export const instanceGuards = {
24
- assertions,
25
- checkOverrides: {
24
+ assert: assertions,
25
+ check: {
26
+ /**
27
+ * Checks that a value is an instance of the given class constructor.
28
+ *
29
+ * Type guards the value.
30
+ *
31
+ * @example
32
+ *
33
+ * ```ts
34
+ * import {check} from '@augment-vir/assert';
35
+ *
36
+ * check.instanceOf(/abc/, RegExp); // returns `true`
37
+ * check.instanceOf('abc', RegExp); // returns `false`
38
+ * ```
39
+ *
40
+ * @see
41
+ * - {@link check.notInstanceOf} : the opposite check.
42
+ */
26
43
  instanceOf: autoGuard(),
44
+ /**
45
+ * Checks that a value is _not_ an instance of the given class constructor.
46
+ *
47
+ * Type guards the value.
48
+ *
49
+ * @example
50
+ *
51
+ * ```ts
52
+ * import {check} from '@augment-vir/assert';
53
+ *
54
+ * check.notInstanceOf(/abc/, RegExp); // returns `false`
55
+ * check.notInstanceOf('abc', RegExp); // returns `true`
56
+ * ```
57
+ *
58
+ * @see
59
+ * - {@link check.instanceOf} : the opposite check.
60
+ */
27
61
  notInstanceOf: autoGuard(),
28
62
  },
29
- assertWrapOverrides: {
63
+ assertWrap: {
64
+ /**
65
+ * Asserts that a value is an instance of the given class constructor. Returns the value if
66
+ * the assertion passes.
67
+ *
68
+ * Type guards the value.
69
+ *
70
+ * @example
71
+ *
72
+ * ```ts
73
+ * import {assertWrap} from '@augment-vir/assert';
74
+ *
75
+ * assertWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
76
+ * assertWrap.instanceOf('abc', RegExp); // throws an error
77
+ * ```
78
+ *
79
+ * @throws {@link AssertionError} If the value is not an instance of the given class
80
+ * constructor.
81
+ * @see
82
+ * - {@link assertWrap.notInstanceOf} : the opposite assertion.
83
+ */
30
84
  instanceOf: autoGuard(),
85
+ /**
86
+ * Asserts that a value is _not_ an instance of the given class constructor. Returns the
87
+ * value if the assertion passes.
88
+ *
89
+ * Type guards the value.
90
+ *
91
+ * @example
92
+ *
93
+ * ```ts
94
+ * import {assertWrap} from '@augment-vir/assert';
95
+ *
96
+ * assertWrap.notInstanceOf(/abc/, RegExp); // throws an error
97
+ * assertWrap.notInstanceOf('abc', RegExp); // returns `'abc'`
98
+ * ```
99
+ *
100
+ * @throws {@link AssertionError} If the value is an instance of the given class
101
+ * constructor.
102
+ * @see
103
+ * - {@link assertWrap.instanceOf} : the opposite assertion.
104
+ */
31
105
  notInstanceOf: autoGuard(),
32
106
  },
33
- checkWrapOverrides: {
107
+ checkWrap: {
108
+ /**
109
+ * Checks that a value is an instance of the given class constructor. Returns the value if
110
+ * the check passes, otherwise `undefined`.
111
+ *
112
+ * Type guards the value.
113
+ *
114
+ * @example
115
+ *
116
+ * ```ts
117
+ * import {checkWrap} from '@augment-vir/assert';
118
+ *
119
+ * checkWrap.instanceOf(/abc/, RegExp); // returns `/abc/`
120
+ * checkWrap.instanceOf('abc', RegExp); // returns `undefined`
121
+ * ```
122
+ *
123
+ * @returns The value if the check passes, otherwise `undefined`.
124
+ * @see
125
+ * - {@link checkWrap.notInstanceOf} : the opposite check.
126
+ */
34
127
  instanceOf: autoGuard(),
128
+ /**
129
+ * Checks that a value is _not_ an instance of the given class constructor. Returns the
130
+ * value if the check passes, otherwise `undefined`.
131
+ *
132
+ * Type guards the value.
133
+ *
134
+ * @example
135
+ *
136
+ * ```ts
137
+ * import {checkWrap} from '@augment-vir/assert';
138
+ *
139
+ * checkWrap.notInstanceOf(/abc/, RegExp); // returns `undefined`
140
+ * checkWrap.notInstanceOf('abc', RegExp); // returns `'abc'`
141
+ * ```
142
+ *
143
+ * @returns The value if the check passes, otherwise `undefined`.
144
+ * @see
145
+ * - {@link checkWrap.instanceOf} : the opposite check.
146
+ */
35
147
  notInstanceOf: autoGuard(),
36
148
  },
37
- waitUntilOverrides: {
149
+ waitUntil: {
150
+ /**
151
+ * Repeatedly calls a callback until its output is an instance of the given class
152
+ * constructor. Once the callback output passes, it is returned. If the attempts time out,
153
+ * an error is thrown.
154
+ *
155
+ * Type guards the value.
156
+ *
157
+ * @example
158
+ *
159
+ * ```ts
160
+ * import {waitUntil} from '@augment-vir/assert';
161
+ *
162
+ * await waitUntil.instanceOf(RegExp, () => /abc/); // returns `/abc/`
163
+ * await waitUntil.instanceOf(RegExp, () => 'abc'); // throws an error
164
+ * ```
165
+ *
166
+ * @returns The callback output once it passes.
167
+ * @throws {@link AssertionError} On timeout.
168
+ * @see
169
+ * - {@link waitUntil.notInstanceOf} : the opposite assertion.
170
+ */
38
171
  instanceOf: autoGuard(),
172
+ /**
173
+ * Repeatedly calls a callback until its output is not an instance of the given class
174
+ * constructor. Once the callback output passes, it is returned. If the attempts time out,
175
+ * an error is thrown.
176
+ *
177
+ * Type guards the value.
178
+ *
179
+ * @example
180
+ *
181
+ * ```ts
182
+ * import {waitUntil} from '@augment-vir/assert';
183
+ *
184
+ * await waitUntil.instanceOf(RegExp, () => /abc/); // throws an error
185
+ * await waitUntil.instanceOf(RegExp, () => 'abc'); // returns `'abc'`
186
+ * ```
187
+ *
188
+ * @returns The callback output once it passes.
189
+ * @throws {@link AssertionError} On timeout.
190
+ * @see
191
+ * - {@link waitUntil.instanceOf} : the opposite assertion.
192
+ */
39
193
  notInstanceOf: autoGuard(),
40
194
  },
41
195
  };