@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.
- package/dist/assertions/boolean.d.ts +20 -26
- package/dist/assertions/boolean.js +185 -41
- package/dist/assertions/boundary.d.ts +40 -256
- package/dist/assertions/boundary.js +265 -229
- package/dist/assertions/enum.d.ts +12 -13
- package/dist/assertions/enum.js +98 -20
- package/dist/assertions/equality/entry-equality.d.ts +11 -15
- package/dist/assertions/equality/entry-equality.js +210 -43
- package/dist/assertions/equality/json-equality.d.ts +11 -15
- package/dist/assertions/equality/json-equality.js +144 -43
- package/dist/assertions/equality/simple-equality.d.ts +39 -46
- package/dist/assertions/equality/simple-equality.js +316 -61
- package/dist/assertions/extendable-assertions.d.ts +0 -12
- package/dist/assertions/extendable-assertions.js +0 -12
- package/dist/assertions/http.d.ts +10 -14
- package/dist/assertions/http.js +96 -28
- package/dist/assertions/instance.d.ts +10 -18
- package/dist/assertions/instance.js +92 -26
- package/dist/assertions/keys.d.ts +59 -138
- package/dist/assertions/keys.js +279 -163
- package/dist/assertions/length.d.ts +30 -212
- package/dist/assertions/length.js +117 -175
- package/dist/assertions/nullish.d.ts +8 -20
- package/dist/assertions/nullish.js +85 -27
- package/dist/assertions/numeric.d.ts +67 -81
- package/dist/assertions/numeric.js +564 -133
- package/dist/assertions/output.d.ts +2 -3
- package/dist/assertions/output.js +1 -7
- package/dist/assertions/primitive.d.ts +33 -40
- package/dist/assertions/primitive.js +232 -66
- package/dist/assertions/promise.d.ts +20 -30
- package/dist/assertions/promise.js +244 -53
- package/dist/assertions/regexp.d.ts +12 -14
- package/dist/assertions/regexp.js +84 -21
- package/dist/assertions/runtime-type.d.ts +99 -207
- package/dist/assertions/runtime-type.js +805 -276
- package/dist/assertions/throws.d.ts +24 -25
- package/dist/assertions/throws.js +43 -5
- package/dist/assertions/uuid.d.ts +11 -16
- package/dist/assertions/uuid.js +91 -22
- package/dist/assertions/values.d.ts +81 -210
- package/dist/assertions/values.js +627 -234
- package/dist/augments/assertion-exports.d.ts +0 -1
- package/dist/augments/assertion-exports.js +1 -1
- package/dist/augments/guards/assert-wrap.d.ts +7 -4
- package/dist/augments/guards/assert-wrap.js +5 -4
- package/dist/augments/guards/check-wrap.d.ts +7 -5
- package/dist/augments/guards/check-wrap.js +5 -4
- package/dist/augments/guards/check.d.ts +5 -5
- package/dist/augments/guards/check.js +5 -4
- package/dist/augments/guards/wait-until.d.ts +8 -4
- package/dist/augments/guards/wait-until.js +7 -8
- package/dist/guard-types/guard-group.d.ts +5 -2
- package/dist/guard-types/wait-until-function.d.ts +2 -10
- package/dist/guard-types/wait-until-function.js +1 -9
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/guard-types/assert-wrap-function.d.ts +0 -12
- package/dist/guard-types/assert-wrap-function.js +0 -14
- package/dist/guard-types/check-function.d.ts +0 -14
- package/dist/guard-types/check-function.js +0 -22
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
- package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
- package/dist/guard-types/guard-override.d.ts +0 -4
- package/dist/guard-types/guard-override.js +0 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import { getObjectTypedKeys, } from '@augment-vir/core';
|
|
3
3
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
4
|
-
import {
|
|
4
|
+
import { createWaitUntil } from '../guard-types/wait-until-function.js';
|
|
5
5
|
function isLengthAtLeast(actual, length, failureMessage) {
|
|
6
6
|
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
7
7
|
? actual.length
|
|
@@ -44,7 +44,45 @@ function waitUntilIsLengthExactly(length, callback, options, failureMessage) {
|
|
|
44
44
|
}
|
|
45
45
|
/* node:coverage enable */
|
|
46
46
|
const assertions = {
|
|
47
|
+
/**
|
|
48
|
+
* Asserts that an array or string has at least the given length.
|
|
49
|
+
*
|
|
50
|
+
* Type guards an array into an {@link AtLeastTuple}. Performs no type guarding on a string.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* import {assert} from '@augment-vir/assert';
|
|
56
|
+
*
|
|
57
|
+
* assert.isLengthAtLeast(['a', 'b', 'c'], 2); // passes
|
|
58
|
+
* assert.isLengthAtLeast(['a', 'b', 'c'], 3); // passes
|
|
59
|
+
* assert.isLengthAtLeast(['a', 'b'], 3); // fails
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @throws {@link AssertionError} If the value is less than the given length.
|
|
63
|
+
* @see
|
|
64
|
+
* - {@link assert.isLengthExactly} : the more exact assertion.
|
|
65
|
+
*/
|
|
47
66
|
isLengthAtLeast,
|
|
67
|
+
/**
|
|
68
|
+
* Asserts that an array or string has exactly the given length.
|
|
69
|
+
*
|
|
70
|
+
* Type guards an array into a {@link Tuple}. Performs no type guarding on a string.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* import {assert} from '@augment-vir/assert';
|
|
76
|
+
*
|
|
77
|
+
* assert.isLengthExactly(['a', 'b', 'c'], 2); // fails
|
|
78
|
+
* assert.isLengthExactly(['a', 'b', 'c'], 3); // passes
|
|
79
|
+
* assert.isLengthExactly(['a', 'b'], 3); // fails
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @throws {@link AssertionError} If the value is not exactly the given length.
|
|
83
|
+
* @see
|
|
84
|
+
* - {@link assert.isLengthAtLeast} : the more flexible assertion.
|
|
85
|
+
*/
|
|
48
86
|
isLengthExactly,
|
|
49
87
|
};
|
|
50
88
|
export const lengthGuards = {
|
|
@@ -60,35 +98,20 @@ export const lengthGuards = {
|
|
|
60
98
|
* ```ts
|
|
61
99
|
* import {check} from '@augment-vir/assert';
|
|
62
100
|
*
|
|
63
|
-
* check.isLengthAtLeast(
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* 'b',
|
|
67
|
-
* 'c',
|
|
68
|
-
* ],
|
|
69
|
-
* 2,
|
|
70
|
-
* ); // returns `true`
|
|
71
|
-
* check.isLengthAtLeast(
|
|
72
|
-
* [
|
|
73
|
-
* 'a',
|
|
74
|
-
* 'b',
|
|
75
|
-
* 'c',
|
|
76
|
-
* ],
|
|
77
|
-
* 3,
|
|
78
|
-
* ); // returns `true`
|
|
79
|
-
* check.isLengthAtLeast(
|
|
80
|
-
* [
|
|
81
|
-
* 'a',
|
|
82
|
-
* 'b',
|
|
83
|
-
* ],
|
|
84
|
-
* 3,
|
|
85
|
-
* ); // returns `false`
|
|
101
|
+
* check.isLengthAtLeast(['a', 'b', 'c'], 2); // returns `true`
|
|
102
|
+
* check.isLengthAtLeast(['a', 'b', 'c'], 3); // returns `true`
|
|
103
|
+
* check.isLengthAtLeast(['a', 'b'], 3); // returns `false`
|
|
86
104
|
* ```
|
|
87
105
|
*
|
|
88
106
|
* @see
|
|
89
107
|
* - {@link check.isLengthExactly} : the more exact check.
|
|
90
108
|
*/
|
|
91
|
-
isLengthAtLeast:
|
|
109
|
+
isLengthAtLeast: ((actual, length) => {
|
|
110
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
111
|
+
? actual.length
|
|
112
|
+
: getObjectTypedKeys(actual).length;
|
|
113
|
+
return actualLength >= length;
|
|
114
|
+
}),
|
|
92
115
|
/**
|
|
93
116
|
* Checks that an array or string has exactly the given length.
|
|
94
117
|
*
|
|
@@ -99,35 +122,20 @@ export const lengthGuards = {
|
|
|
99
122
|
* ```ts
|
|
100
123
|
* import {check} from '@augment-vir/assert';
|
|
101
124
|
*
|
|
102
|
-
* check.isLengthExactly(
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* 'b',
|
|
106
|
-
* 'c',
|
|
107
|
-
* ],
|
|
108
|
-
* 2,
|
|
109
|
-
* ); // fails
|
|
110
|
-
* check.isLengthExactly(
|
|
111
|
-
* [
|
|
112
|
-
* 'a',
|
|
113
|
-
* 'b',
|
|
114
|
-
* 'c',
|
|
115
|
-
* ],
|
|
116
|
-
* 3,
|
|
117
|
-
* ); // passes
|
|
118
|
-
* check.isLengthExactly(
|
|
119
|
-
* [
|
|
120
|
-
* 'a',
|
|
121
|
-
* 'b',
|
|
122
|
-
* ],
|
|
123
|
-
* 3,
|
|
124
|
-
* ); // fails
|
|
125
|
+
* check.isLengthExactly(['a', 'b', 'c'], 2); // fails
|
|
126
|
+
* check.isLengthExactly(['a', 'b', 'c'], 3); // passes
|
|
127
|
+
* check.isLengthExactly(['a', 'b'], 3); // fails
|
|
125
128
|
* ```
|
|
126
129
|
*
|
|
127
130
|
* @see
|
|
128
131
|
* - {@link check.isLengthAtLeast} : the more flexible check.
|
|
129
132
|
*/
|
|
130
|
-
isLengthExactly:
|
|
133
|
+
isLengthExactly: ((actual, length) => {
|
|
134
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
135
|
+
? actual.length
|
|
136
|
+
: getObjectTypedKeys(actual).length;
|
|
137
|
+
return actualLength === length;
|
|
138
|
+
}),
|
|
131
139
|
},
|
|
132
140
|
assertWrap: {
|
|
133
141
|
/**
|
|
@@ -141,29 +149,9 @@ export const lengthGuards = {
|
|
|
141
149
|
* ```ts
|
|
142
150
|
* import {assertWrap} from '@augment-vir/assert';
|
|
143
151
|
*
|
|
144
|
-
* assertWrap.isLengthAtLeast(
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* 'b',
|
|
148
|
-
* 'c',
|
|
149
|
-
* ],
|
|
150
|
-
* 2,
|
|
151
|
-
* ); // returns `['a', 'b', 'c']`
|
|
152
|
-
* assertWrap.isLengthAtLeast(
|
|
153
|
-
* [
|
|
154
|
-
* 'a',
|
|
155
|
-
* 'b',
|
|
156
|
-
* 'c',
|
|
157
|
-
* ],
|
|
158
|
-
* 3,
|
|
159
|
-
* ); // returns `['a', 'b', 'c']`
|
|
160
|
-
* assertWrap.isLengthAtLeast(
|
|
161
|
-
* [
|
|
162
|
-
* 'a',
|
|
163
|
-
* 'b',
|
|
164
|
-
* ],
|
|
165
|
-
* 3,
|
|
166
|
-
* ); // throws an error
|
|
152
|
+
* assertWrap.isLengthAtLeast(['a', 'b', 'c'], 2); // returns `['a', 'b', 'c']`
|
|
153
|
+
* assertWrap.isLengthAtLeast(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
|
|
154
|
+
* assertWrap.isLengthAtLeast(['a', 'b'], 3); // throws an error
|
|
167
155
|
* ```
|
|
168
156
|
*
|
|
169
157
|
* @returns The value if it has at least the given length.
|
|
@@ -171,7 +159,15 @@ export const lengthGuards = {
|
|
|
171
159
|
* @see
|
|
172
160
|
* - {@link assertWrap.isLengthExactly} : the more exact assertion.
|
|
173
161
|
*/
|
|
174
|
-
isLengthAtLeast:
|
|
162
|
+
isLengthAtLeast: ((actual, length, failureMessage) => {
|
|
163
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
164
|
+
? actual.length
|
|
165
|
+
: getObjectTypedKeys(actual).length;
|
|
166
|
+
if (actualLength < length) {
|
|
167
|
+
throw new AssertionError(`Length '${actual.length}' is not at least '${length}'.`, failureMessage);
|
|
168
|
+
}
|
|
169
|
+
return actual;
|
|
170
|
+
}),
|
|
175
171
|
/**
|
|
176
172
|
* Asserts that an array or string has exactly the given length. Returns the value if the
|
|
177
173
|
* assertion passes.
|
|
@@ -183,29 +179,9 @@ export const lengthGuards = {
|
|
|
183
179
|
* ```ts
|
|
184
180
|
* import {assertWrap} from '@augment-vir/assert';
|
|
185
181
|
*
|
|
186
|
-
* assertWrap.isLengthExactly(
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* 'b',
|
|
190
|
-
* 'c',
|
|
191
|
-
* ],
|
|
192
|
-
* 2,
|
|
193
|
-
* ); // throws an error
|
|
194
|
-
* assertWrap.isLengthExactly(
|
|
195
|
-
* [
|
|
196
|
-
* 'a',
|
|
197
|
-
* 'b',
|
|
198
|
-
* 'c',
|
|
199
|
-
* ],
|
|
200
|
-
* 3,
|
|
201
|
-
* ); // returns `['a', 'b', 'c']`
|
|
202
|
-
* assertWrap.isLengthExactly(
|
|
203
|
-
* [
|
|
204
|
-
* 'a',
|
|
205
|
-
* 'b',
|
|
206
|
-
* ],
|
|
207
|
-
* 3,
|
|
208
|
-
* ); // throws an error
|
|
182
|
+
* assertWrap.isLengthExactly(['a', 'b', 'c'], 2); // throws an error
|
|
183
|
+
* assertWrap.isLengthExactly(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
|
|
184
|
+
* assertWrap.isLengthExactly(['a', 'b'], 3); // throws an error
|
|
209
185
|
* ```
|
|
210
186
|
*
|
|
211
187
|
* @returns The value if it has exactly the given length.
|
|
@@ -213,7 +189,15 @@ export const lengthGuards = {
|
|
|
213
189
|
* @see
|
|
214
190
|
* - {@link assertWrap.isLengthAtLeast} : the more flexible assertion.
|
|
215
191
|
*/
|
|
216
|
-
isLengthExactly:
|
|
192
|
+
isLengthExactly: ((actual, length, failureMessage) => {
|
|
193
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
194
|
+
? actual.length
|
|
195
|
+
: getObjectTypedKeys(actual).length;
|
|
196
|
+
if (actualLength !== length) {
|
|
197
|
+
throw new AssertionError(`Length '${actual.length}' is not exactly '${length}'.`, failureMessage);
|
|
198
|
+
}
|
|
199
|
+
return actual;
|
|
200
|
+
}),
|
|
217
201
|
},
|
|
218
202
|
checkWrap: {
|
|
219
203
|
/**
|
|
@@ -227,36 +211,26 @@ export const lengthGuards = {
|
|
|
227
211
|
* ```ts
|
|
228
212
|
* import {checkWrap} from '@augment-vir/assert';
|
|
229
213
|
*
|
|
230
|
-
* checkWrap.isLengthAtLeast(
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* 'b',
|
|
234
|
-
* 'c',
|
|
235
|
-
* ],
|
|
236
|
-
* 2,
|
|
237
|
-
* ); // returns `['a', 'b', 'c']`
|
|
238
|
-
* checkWrap.isLengthAtLeast(
|
|
239
|
-
* [
|
|
240
|
-
* 'a',
|
|
241
|
-
* 'b',
|
|
242
|
-
* 'c',
|
|
243
|
-
* ],
|
|
244
|
-
* 3,
|
|
245
|
-
* ); // returns `['a', 'b', 'c']`
|
|
246
|
-
* checkWrap.isLengthAtLeast(
|
|
247
|
-
* [
|
|
248
|
-
* 'a',
|
|
249
|
-
* 'b',
|
|
250
|
-
* ],
|
|
251
|
-
* 3,
|
|
252
|
-
* ); // returns `undefined`
|
|
214
|
+
* checkWrap.isLengthAtLeast(['a', 'b', 'c'], 2); // returns `['a', 'b', 'c']`
|
|
215
|
+
* checkWrap.isLengthAtLeast(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
|
|
216
|
+
* checkWrap.isLengthAtLeast(['a', 'b'], 3); // returns `undefined`
|
|
253
217
|
* ```
|
|
254
218
|
*
|
|
255
219
|
* @returns The value if the check passes, otherwise `undefined`.
|
|
256
220
|
* @see
|
|
257
221
|
* - {@link checkWrap.isLengthExactly} : the more exact check.
|
|
258
222
|
*/
|
|
259
|
-
isLengthAtLeast:
|
|
223
|
+
isLengthAtLeast: ((actual, length) => {
|
|
224
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
225
|
+
? actual.length
|
|
226
|
+
: getObjectTypedKeys(actual).length;
|
|
227
|
+
if (actualLength >= length) {
|
|
228
|
+
return actual;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
260
234
|
/**
|
|
261
235
|
* Checks that an array or string has exactly the given length. Returns the value if the
|
|
262
236
|
* check passes, otherwise `undefined`.
|
|
@@ -268,36 +242,26 @@ export const lengthGuards = {
|
|
|
268
242
|
* ```ts
|
|
269
243
|
* import {checkWrap} from '@augment-vir/assert';
|
|
270
244
|
*
|
|
271
|
-
* checkWrap.isLengthExactly(
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* 'b',
|
|
275
|
-
* 'c',
|
|
276
|
-
* ],
|
|
277
|
-
* 2,
|
|
278
|
-
* ); // returns `undefined`
|
|
279
|
-
* checkWrap.isLengthExactly(
|
|
280
|
-
* [
|
|
281
|
-
* 'a',
|
|
282
|
-
* 'b',
|
|
283
|
-
* 'c',
|
|
284
|
-
* ],
|
|
285
|
-
* 3,
|
|
286
|
-
* ); // returns `['a', 'b', 'c']`
|
|
287
|
-
* checkWrap.isLengthExactly(
|
|
288
|
-
* [
|
|
289
|
-
* 'a',
|
|
290
|
-
* 'b',
|
|
291
|
-
* ],
|
|
292
|
-
* 3,
|
|
293
|
-
* ); // returns `undefined`
|
|
245
|
+
* checkWrap.isLengthExactly(['a', 'b', 'c'], 2); // returns `undefined`
|
|
246
|
+
* checkWrap.isLengthExactly(['a', 'b', 'c'], 3); // returns `['a', 'b', 'c']`
|
|
247
|
+
* checkWrap.isLengthExactly(['a', 'b'], 3); // returns `undefined`
|
|
294
248
|
* ```
|
|
295
249
|
*
|
|
296
250
|
* @returns The value if the check passes, otherwise `undefined`.
|
|
297
251
|
* @see
|
|
298
252
|
* - {@link checkWrap.isLengthAtLeast} : the more flexible check.
|
|
299
253
|
*/
|
|
300
|
-
isLengthExactly:
|
|
254
|
+
isLengthExactly: ((actual, length) => {
|
|
255
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
256
|
+
? actual.length
|
|
257
|
+
: getObjectTypedKeys(actual).length;
|
|
258
|
+
if (actualLength === length) {
|
|
259
|
+
return actual;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
301
265
|
},
|
|
302
266
|
waitUntil: {
|
|
303
267
|
/**
|
|
@@ -312,20 +276,9 @@ export const lengthGuards = {
|
|
|
312
276
|
* ```ts
|
|
313
277
|
* import {waitUntil} from '@augment-vir/assert';
|
|
314
278
|
*
|
|
315
|
-
* await waitUntil.isLengthAtLeast(2, () => [
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* 'c',
|
|
319
|
-
* ]); // returns `['a', 'b', 'c']`
|
|
320
|
-
* await waitUntil.isLengthAtLeast(3, () => [
|
|
321
|
-
* 'a',
|
|
322
|
-
* 'b',
|
|
323
|
-
* 'c',
|
|
324
|
-
* ]); // returns `['a', 'b', 'c']`
|
|
325
|
-
* await waitUntil.isLengthAtLeast(3, () => [
|
|
326
|
-
* 'a',
|
|
327
|
-
* 'b',
|
|
328
|
-
* ]); // throws an error
|
|
279
|
+
* await waitUntil.isLengthAtLeast(2, () => ['a', 'b', 'c']); // returns `['a', 'b', 'c']`
|
|
280
|
+
* await waitUntil.isLengthAtLeast(3, () => ['a', 'b', 'c']); // returns `['a', 'b', 'c']`
|
|
281
|
+
* await waitUntil.isLengthAtLeast(3, () => ['a', 'b']); // throws an error
|
|
329
282
|
* ```
|
|
330
283
|
*
|
|
331
284
|
* @returns The callback output once it passes.
|
|
@@ -333,7 +286,7 @@ export const lengthGuards = {
|
|
|
333
286
|
* @see
|
|
334
287
|
* - {@link waitUntil.isLengthExactly} : the more exact assertion.
|
|
335
288
|
*/
|
|
336
|
-
isLengthAtLeast:
|
|
289
|
+
isLengthAtLeast: createWaitUntil(assertions.isLengthAtLeast),
|
|
337
290
|
/**
|
|
338
291
|
* Repeatedly calls a callback until its output is an array or string that has exactly the
|
|
339
292
|
* given length. Once the callback output passes, it is returned. If the attempts time out,
|
|
@@ -346,20 +299,9 @@ export const lengthGuards = {
|
|
|
346
299
|
* ```ts
|
|
347
300
|
* import {waitUntil} from '@augment-vir/assert';
|
|
348
301
|
*
|
|
349
|
-
* await waitUntil.isLengthAtLeast(2, () => [
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* 'c',
|
|
353
|
-
* ]); // throws an error
|
|
354
|
-
* await waitUntil.isLengthAtLeast(3, () => [
|
|
355
|
-
* 'a',
|
|
356
|
-
* 'b',
|
|
357
|
-
* 'c',
|
|
358
|
-
* ]); // returns `['a', 'b', 'c']`
|
|
359
|
-
* await waitUntil.isLengthAtLeast(3, () => [
|
|
360
|
-
* 'a',
|
|
361
|
-
* 'b',
|
|
362
|
-
* ]); // throws an error
|
|
302
|
+
* await waitUntil.isLengthAtLeast(2, () => ['a', 'b', 'c']); // throws an error
|
|
303
|
+
* await waitUntil.isLengthAtLeast(3, () => ['a', 'b', 'c']); // returns `['a', 'b', 'c']`
|
|
304
|
+
* await waitUntil.isLengthAtLeast(3, () => ['a', 'b']); // throws an error
|
|
363
305
|
* ```
|
|
364
306
|
*
|
|
365
307
|
* @returns The callback output once it passes.
|
|
@@ -367,6 +309,6 @@ export const lengthGuards = {
|
|
|
367
309
|
* @see
|
|
368
310
|
* - {@link waitUntil.isLengthAtLeast} : the more flexible assertion.
|
|
369
311
|
*/
|
|
370
|
-
isLengthExactly:
|
|
312
|
+
isLengthExactly: createWaitUntil(assertions.isLengthExactly),
|
|
371
313
|
},
|
|
372
314
|
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { type MaybePromise } from '@augment-vir/core';
|
|
2
|
-
import { autoGuardSymbol } from '../guard-types/guard-override.js';
|
|
3
2
|
import { type WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
4
|
-
declare function isDefined<const Actual>(
|
|
5
|
-
/** The value to check. */
|
|
6
|
-
input: Actual,
|
|
7
|
-
/** Message to include in error message if this assertion fails. */
|
|
8
|
-
failureMessage?: string | undefined): asserts input is Exclude<Actual, undefined | null>;
|
|
9
|
-
declare function isNullish(
|
|
10
|
-
/** The value to check. */
|
|
11
|
-
input: unknown,
|
|
12
|
-
/** Message to include in error message if this assertion fails. */
|
|
13
|
-
failureMessage?: string | undefined): asserts input is null | undefined;
|
|
14
3
|
export declare const nullishGuards: {
|
|
15
4
|
assert: {
|
|
16
5
|
/**
|
|
@@ -33,7 +22,7 @@ export declare const nullishGuards: {
|
|
|
33
22
|
* @see
|
|
34
23
|
* - {@link assert.isNullish} : the opposite assertion.
|
|
35
24
|
*/
|
|
36
|
-
isDefined:
|
|
25
|
+
isDefined<const Actual>(this: void, input: Actual, failureMessage?: string | undefined): asserts input is Exclude<Actual, undefined | null>;
|
|
37
26
|
/**
|
|
38
27
|
* Asserts that a value is nullish (`null` or `undefined`).
|
|
39
28
|
*
|
|
@@ -54,7 +43,7 @@ export declare const nullishGuards: {
|
|
|
54
43
|
* @see
|
|
55
44
|
* - {@link assert.isDefined} : the opposite assertion.
|
|
56
45
|
*/
|
|
57
|
-
isNullish:
|
|
46
|
+
isNullish(this: void, input: unknown, failureMessage?: string | undefined): asserts input is null | undefined;
|
|
58
47
|
};
|
|
59
48
|
check: {
|
|
60
49
|
/**
|
|
@@ -76,7 +65,7 @@ export declare const nullishGuards: {
|
|
|
76
65
|
* @see
|
|
77
66
|
* - {@link check.isNullish} : the opposite check.
|
|
78
67
|
*/
|
|
79
|
-
isDefined
|
|
68
|
+
isDefined<Actual>(this: void, input: Actual): input is Exclude<Actual, undefined | null>;
|
|
80
69
|
/**
|
|
81
70
|
* Checks that a value is nullish (`null` or `undefined`).
|
|
82
71
|
*
|
|
@@ -96,7 +85,7 @@ export declare const nullishGuards: {
|
|
|
96
85
|
* @see
|
|
97
86
|
* - {@link check.isDefined} : the opposite check.
|
|
98
87
|
*/
|
|
99
|
-
isNullish:
|
|
88
|
+
isNullish(this: void, input: unknown): input is null | undefined;
|
|
100
89
|
};
|
|
101
90
|
assertWrap: {
|
|
102
91
|
/**
|
|
@@ -121,7 +110,7 @@ export declare const nullishGuards: {
|
|
|
121
110
|
* @see
|
|
122
111
|
* - {@link assertWrap.isNullish} : the opposite assertion.
|
|
123
112
|
*/
|
|
124
|
-
isDefined
|
|
113
|
+
isDefined<Actual>(this: void, input: Actual, failureMessage?: string | undefined): Exclude<Actual, undefined | null>;
|
|
125
114
|
/**
|
|
126
115
|
* Asserts that a value is nullish (`null` or `undefined`). Returns the value if the
|
|
127
116
|
* assertion passes.
|
|
@@ -144,7 +133,7 @@ export declare const nullishGuards: {
|
|
|
144
133
|
* @see
|
|
145
134
|
* - {@link assertWrap.isDefined} : the opposite assertion.
|
|
146
135
|
*/
|
|
147
|
-
isNullish:
|
|
136
|
+
isNullish<Actual>(this: void, input: Actual, failureMessage?: string | undefined): Extract<Actual, undefined | null>;
|
|
148
137
|
};
|
|
149
138
|
/** Nullish checks don't make any sense on `checkWrap`. */
|
|
150
139
|
checkWrap: {
|
|
@@ -175,7 +164,7 @@ export declare const nullishGuards: {
|
|
|
175
164
|
* @see
|
|
176
165
|
* - {@link waitUntil.isNullish} : the opposite assertion.
|
|
177
166
|
*/
|
|
178
|
-
isDefined: <Actual>(callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, undefined | null>>;
|
|
167
|
+
isDefined: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, undefined | null>>;
|
|
179
168
|
/**
|
|
180
169
|
* Repeatedly calls a callback until its output is a value that is nullish (`null` or
|
|
181
170
|
* `undefined`). Once the callback output passes, it is returned. If the attempts time out,
|
|
@@ -199,7 +188,6 @@ export declare const nullishGuards: {
|
|
|
199
188
|
* @see
|
|
200
189
|
* - {@link waitUntil.isDefined} : the opposite assertion.
|
|
201
190
|
*/
|
|
202
|
-
isNullish:
|
|
191
|
+
isNullish: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Extract<Actual, undefined | null>>;
|
|
203
192
|
};
|
|
204
193
|
};
|
|
205
|
-
export {};
|
|
@@ -1,27 +1,65 @@
|
|
|
1
1
|
import { stringify } from '@augment-vir/core';
|
|
2
2
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
-
import {
|
|
4
|
-
function isDefined(
|
|
5
|
-
/** The value to check. */
|
|
6
|
-
input,
|
|
7
|
-
/** Message to include in error message if this assertion fails. */
|
|
8
|
-
failureMessage) {
|
|
9
|
-
if (input == undefined) {
|
|
10
|
-
throw new AssertionError(`'${stringify(input)}' is not defined.`, failureMessage);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function isNullish(
|
|
14
|
-
/** The value to check. */
|
|
15
|
-
input,
|
|
16
|
-
/** Message to include in error message if this assertion fails. */
|
|
17
|
-
failureMessage) {
|
|
18
|
-
if (input != undefined) {
|
|
19
|
-
throw new AssertionError(`'${stringify(input)}' is not a nullish.`, failureMessage);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
3
|
+
import { createWaitUntil } from '../guard-types/wait-until-function.js';
|
|
22
4
|
const assertions = {
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that a value is defined (not `null` and not `undefined`).
|
|
7
|
+
*
|
|
8
|
+
* Type guards the value.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {assert} from '@augment-vir/assert';
|
|
14
|
+
*
|
|
15
|
+
* assert.isDefined(0); // passes
|
|
16
|
+
* assert.isDefined(''); // passes
|
|
17
|
+
* assert.isDefined(null); // fails
|
|
18
|
+
* assert.isDefined(undefined); // fails
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @throws {@link AssertionError} If the assertion fails.
|
|
22
|
+
* @see
|
|
23
|
+
* - {@link assert.isNullish} : the opposite assertion.
|
|
24
|
+
*/
|
|
25
|
+
isDefined(
|
|
26
|
+
/** The value to check. */
|
|
27
|
+
input,
|
|
28
|
+
/** Message to include in error message if this assertion fails. */
|
|
29
|
+
failureMessage) {
|
|
30
|
+
if (input == undefined) {
|
|
31
|
+
throw new AssertionError(`'${stringify(input)}' is not defined.`, failureMessage);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Asserts that a value is nullish (`null` or `undefined`).
|
|
36
|
+
*
|
|
37
|
+
* Type guards the value.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import {assert} from '@augment-vir/assert';
|
|
43
|
+
*
|
|
44
|
+
* assert.isNullish(0); // fails
|
|
45
|
+
* assert.isNullish(''); // fails
|
|
46
|
+
* assert.isNullish(null); // passes
|
|
47
|
+
* assert.isNullish(undefined); // passes
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @throws {@link AssertionError} If the assertion fails.
|
|
51
|
+
* @see
|
|
52
|
+
* - {@link assert.isDefined} : the opposite assertion.
|
|
53
|
+
*/
|
|
54
|
+
isNullish(
|
|
55
|
+
/** The value to check. */
|
|
56
|
+
input,
|
|
57
|
+
/** Message to include in error message if this assertion fails. */
|
|
58
|
+
failureMessage) {
|
|
59
|
+
if (input != undefined) {
|
|
60
|
+
throw new AssertionError(`'${stringify(input)}' is not a nullish.`, failureMessage);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
25
63
|
};
|
|
26
64
|
export const nullishGuards = {
|
|
27
65
|
assert: assertions,
|
|
@@ -45,7 +83,9 @@ export const nullishGuards = {
|
|
|
45
83
|
* @see
|
|
46
84
|
* - {@link check.isNullish} : the opposite check.
|
|
47
85
|
*/
|
|
48
|
-
isDefined
|
|
86
|
+
isDefined(input) {
|
|
87
|
+
return input != undefined;
|
|
88
|
+
},
|
|
49
89
|
/**
|
|
50
90
|
* Checks that a value is nullish (`null` or `undefined`).
|
|
51
91
|
*
|
|
@@ -65,7 +105,11 @@ export const nullishGuards = {
|
|
|
65
105
|
* @see
|
|
66
106
|
* - {@link check.isDefined} : the opposite check.
|
|
67
107
|
*/
|
|
68
|
-
isNullish
|
|
108
|
+
isNullish(
|
|
109
|
+
/** The value to check. */
|
|
110
|
+
input) {
|
|
111
|
+
return input == undefined;
|
|
112
|
+
},
|
|
69
113
|
},
|
|
70
114
|
assertWrap: {
|
|
71
115
|
/**
|
|
@@ -90,7 +134,14 @@ export const nullishGuards = {
|
|
|
90
134
|
* @see
|
|
91
135
|
* - {@link assertWrap.isNullish} : the opposite assertion.
|
|
92
136
|
*/
|
|
93
|
-
isDefined
|
|
137
|
+
isDefined(input, failureMessage) {
|
|
138
|
+
if (input == undefined) {
|
|
139
|
+
throw new AssertionError(`'${stringify(input)}' is not defined.`, failureMessage);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return input;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
94
145
|
/**
|
|
95
146
|
* Asserts that a value is nullish (`null` or `undefined`). Returns the value if the
|
|
96
147
|
* assertion passes.
|
|
@@ -113,7 +164,14 @@ export const nullishGuards = {
|
|
|
113
164
|
* @see
|
|
114
165
|
* - {@link assertWrap.isDefined} : the opposite assertion.
|
|
115
166
|
*/
|
|
116
|
-
isNullish
|
|
167
|
+
isNullish(input, failureMessage) {
|
|
168
|
+
if (input == undefined) {
|
|
169
|
+
return input;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new AssertionError(`'${stringify(input)}' is not nullish.`, failureMessage);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
117
175
|
},
|
|
118
176
|
/** Nullish checks don't make any sense on `checkWrap`. */
|
|
119
177
|
checkWrap: {
|
|
@@ -144,7 +202,7 @@ export const nullishGuards = {
|
|
|
144
202
|
* @see
|
|
145
203
|
* - {@link waitUntil.isNullish} : the opposite assertion.
|
|
146
204
|
*/
|
|
147
|
-
isDefined:
|
|
205
|
+
isDefined: createWaitUntil(assertions.isDefined),
|
|
148
206
|
/**
|
|
149
207
|
* Repeatedly calls a callback until its output is a value that is nullish (`null` or
|
|
150
208
|
* `undefined`). Once the callback output passes, it is returned. If the attempts time out,
|
|
@@ -168,6 +226,6 @@ export const nullishGuards = {
|
|
|
168
226
|
* @see
|
|
169
227
|
* - {@link waitUntil.isDefined} : the opposite assertion.
|
|
170
228
|
*/
|
|
171
|
-
isNullish:
|
|
229
|
+
isNullish: createWaitUntil(assertions.isNullish),
|
|
172
230
|
},
|
|
173
231
|
};
|