@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,90 +1,467 @@
|
|
|
1
1
|
import { stringify, } from '@augment-vir/core';
|
|
2
2
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
-
import {
|
|
4
|
-
function isNotArray(actual, failureMessage) {
|
|
5
|
-
assertNotRuntimeType(actual, 'array', failureMessage);
|
|
6
|
-
}
|
|
7
|
-
function isNotBigInt(actual, failureMessage) {
|
|
8
|
-
assertNotRuntimeType(actual, 'bigint', failureMessage);
|
|
9
|
-
}
|
|
10
|
-
function isNotBoolean(actual, failureMessage) {
|
|
11
|
-
assertNotRuntimeType(actual, 'boolean', failureMessage);
|
|
12
|
-
}
|
|
13
|
-
function isNotFunction(actual, failureMessage) {
|
|
14
|
-
assertNotRuntimeType(actual, 'function', failureMessage);
|
|
15
|
-
}
|
|
16
|
-
function isNotNumber(actual, failureMessage) {
|
|
17
|
-
assertNotRuntimeType(actual, 'number', failureMessage);
|
|
18
|
-
}
|
|
19
|
-
function isNotObject(actual, failureMessage) {
|
|
20
|
-
assertNotRuntimeType(actual, 'object', failureMessage);
|
|
21
|
-
}
|
|
22
|
-
function isNotString(actual, failureMessage) {
|
|
23
|
-
assertNotRuntimeType(actual, 'string', failureMessage);
|
|
24
|
-
}
|
|
25
|
-
function isNotSymbol(actual, failureMessage) {
|
|
26
|
-
assertNotRuntimeType(actual, 'symbol', failureMessage);
|
|
27
|
-
}
|
|
28
|
-
function isNotUndefined(actual, failureMessage) {
|
|
29
|
-
assertNotRuntimeType(actual, 'undefined', failureMessage);
|
|
30
|
-
}
|
|
31
|
-
function isNotNull(actual, failureMessage) {
|
|
32
|
-
assertNotRuntimeType(actual, 'null', failureMessage);
|
|
33
|
-
}
|
|
34
|
-
function isArray(actual, failureMessage) {
|
|
35
|
-
assertRuntimeType(actual, 'array', failureMessage);
|
|
36
|
-
}
|
|
37
|
-
function isBigInt(actual, failureMessage) {
|
|
38
|
-
assertRuntimeType(actual, 'bigint', failureMessage);
|
|
39
|
-
}
|
|
40
|
-
function isBoolean(actual, failureMessage) {
|
|
41
|
-
assertRuntimeType(actual, 'boolean', failureMessage);
|
|
42
|
-
}
|
|
43
|
-
function isFunction(actual, failureMessage) {
|
|
44
|
-
assertRuntimeType(actual, 'function', failureMessage);
|
|
45
|
-
}
|
|
46
|
-
export function isNumber(actual, failureMessage) {
|
|
47
|
-
assertRuntimeType(actual, 'number', failureMessage);
|
|
48
|
-
if (isNaN(actual)) {
|
|
49
|
-
throw new AssertionError('Value is NaN.', failureMessage);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function isObject(actual, failureMessage) {
|
|
53
|
-
assertRuntimeType(actual, 'object', failureMessage);
|
|
54
|
-
}
|
|
55
|
-
function isString(actual, failureMessage) {
|
|
56
|
-
assertRuntimeType(actual, 'string', failureMessage);
|
|
57
|
-
}
|
|
58
|
-
function isSymbol(actual, failureMessage) {
|
|
59
|
-
assertRuntimeType(actual, 'symbol', failureMessage);
|
|
60
|
-
}
|
|
61
|
-
function isUndefined(actual, failureMessage) {
|
|
62
|
-
assertRuntimeType(actual, 'undefined', failureMessage);
|
|
63
|
-
}
|
|
64
|
-
function isNull(actual, failureMessage) {
|
|
65
|
-
assertRuntimeType(actual, 'null', failureMessage);
|
|
66
|
-
}
|
|
3
|
+
import { createWaitUntil } from '../guard-types/wait-until-function.js';
|
|
67
4
|
const assertions = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that a value is an array.
|
|
7
|
+
*
|
|
8
|
+
* Type guards the value.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {assert} from '@augment-vir/assert';
|
|
14
|
+
*
|
|
15
|
+
* assert.isArray([]); // passes
|
|
16
|
+
* assert.isArray({length: 4}); // fails
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
20
|
+
* @see
|
|
21
|
+
* - {@link assert.isNotArray} : the opposite assertion.
|
|
22
|
+
*/
|
|
23
|
+
isArray(actual, failureMessage) {
|
|
24
|
+
if (!Array.isArray(actual)) {
|
|
25
|
+
throw new AssertionError(`'${stringify(actual)}' is not an array.`, failureMessage);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Asserts that a value is a BigInt.
|
|
30
|
+
*
|
|
31
|
+
* Type guards the value.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* import {assert} from '@augment-vir/assert';
|
|
37
|
+
*
|
|
38
|
+
* assert.isBigInt(123n); // passes
|
|
39
|
+
* assert.isBigInt(123); // fails
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
43
|
+
* @see
|
|
44
|
+
* - {@link assert.isNotBigInt} : the opposite assertion.
|
|
45
|
+
*/
|
|
46
|
+
isBigInt(actual, failureMessage) {
|
|
47
|
+
if (typeof actual !== 'bigint') {
|
|
48
|
+
throw new AssertionError(`'${stringify(actual)}' is not a bigint.`, failureMessage);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Asserts that a value is a boolean.
|
|
53
|
+
*
|
|
54
|
+
* Type guards the value.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* import {assert} from '@augment-vir/assert';
|
|
60
|
+
*
|
|
61
|
+
* assert.isBoolean(true); // passes
|
|
62
|
+
* assert.isBoolean('true'); // fails
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
66
|
+
* @see
|
|
67
|
+
* - {@link assert.isNotBoolean} : the opposite assertion.
|
|
68
|
+
*/
|
|
69
|
+
isBoolean(actual, failureMessage) {
|
|
70
|
+
if (typeof actual !== 'boolean') {
|
|
71
|
+
throw new AssertionError(`'${stringify(actual)}' is not a boolean.`, failureMessage);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Asserts that a value is a function.
|
|
76
|
+
*
|
|
77
|
+
* Type guards the value.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* import {assert} from '@augment-vir/assert';
|
|
83
|
+
*
|
|
84
|
+
* assert.isFunction(() => {}); // passes
|
|
85
|
+
* assert.isFunction({}); // fails
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
89
|
+
* @see
|
|
90
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
91
|
+
*/
|
|
92
|
+
isFunction(actual, failureMessage) {
|
|
93
|
+
if (typeof actual !== 'function') {
|
|
94
|
+
throw new AssertionError(`'${stringify(actual)}' is not a function.`, failureMessage);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Asserts that a value is exactly `null`.
|
|
99
|
+
*
|
|
100
|
+
* Type guards the value.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import {assert} from '@augment-vir/assert';
|
|
106
|
+
*
|
|
107
|
+
* assert.isNull(null); // passes
|
|
108
|
+
* assert.isNull(undefined); // fails
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
112
|
+
* @see
|
|
113
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
114
|
+
*/
|
|
115
|
+
isNull(actual, failureMessage) {
|
|
116
|
+
if (actual !== null) {
|
|
117
|
+
throw new AssertionError(`'${stringify(actual)}' is not nul.`, failureMessage);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Asserts that a value is a number. This excludes `NaN`.
|
|
122
|
+
*
|
|
123
|
+
* Type guards the value.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* import {assert} from '@augment-vir/assert';
|
|
129
|
+
*
|
|
130
|
+
* assert.isNumber(123); // passes
|
|
131
|
+
* assert.isNumber(123n); // fails
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
135
|
+
* @see
|
|
136
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
137
|
+
*/
|
|
138
|
+
isNumber(actual, failureMessage) {
|
|
139
|
+
if (typeof actual !== 'number' || isNaN(actual)) {
|
|
140
|
+
throw new AssertionError(`'${stringify(actual)}' is not a number.`, failureMessage);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
/**
|
|
144
|
+
* Asserts that a value is an object. This excludes arrays.
|
|
145
|
+
*
|
|
146
|
+
* Type guards the value.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* import {assert} from '@augment-vir/assert';
|
|
152
|
+
*
|
|
153
|
+
* assert.isObject({}); // passes
|
|
154
|
+
* assert.isObject([]); // fails
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
158
|
+
* @see
|
|
159
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
160
|
+
*/
|
|
161
|
+
isObject(actual, failureMessage) {
|
|
162
|
+
if (Array.isArray(actual) || typeof actual !== 'object' || !actual) {
|
|
163
|
+
throw new AssertionError(`'${stringify(actual)}' is not a non-null object.`, failureMessage);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Asserts that a value is a string.
|
|
168
|
+
*
|
|
169
|
+
* Type guards the value.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* import {assert} from '@augment-vir/assert';
|
|
175
|
+
*
|
|
176
|
+
* assert.isString(''); // passes
|
|
177
|
+
* assert.isString(5); // fails
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
181
|
+
* @see
|
|
182
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
183
|
+
*/
|
|
184
|
+
isString(actual, failureMessage) {
|
|
185
|
+
if (typeof actual !== 'string') {
|
|
186
|
+
throw new AssertionError(`'${stringify(actual)}' is not a string.`, failureMessage);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* Asserts that a value is a symbol.
|
|
191
|
+
*
|
|
192
|
+
* Type guards the value.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
*
|
|
196
|
+
* ```ts
|
|
197
|
+
* import {assert} from '@augment-vir/assert';
|
|
198
|
+
*
|
|
199
|
+
* assert.isSymbol(Symbol('my-symbol')); // passes
|
|
200
|
+
* assert.isSymbol('my-symbol'); // fails
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
204
|
+
* @see
|
|
205
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
206
|
+
*/
|
|
207
|
+
isSymbol(actual, failureMessage) {
|
|
208
|
+
if (typeof actual !== 'symbol') {
|
|
209
|
+
throw new AssertionError(`'${stringify(actual)}' is not a symbol.`, failureMessage);
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Asserts that a value is exactly `undefined`.
|
|
214
|
+
*
|
|
215
|
+
* Type guards the value.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* import {assert} from '@augment-vir/assert';
|
|
221
|
+
*
|
|
222
|
+
* assert.isUndefined(undefined); // passes
|
|
223
|
+
* assert.isUndefined(null); // fails
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
227
|
+
* @see
|
|
228
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
229
|
+
*/
|
|
230
|
+
isUndefined(actual, failureMessage) {
|
|
231
|
+
if (typeof actual !== 'undefined') {
|
|
232
|
+
throw new AssertionError(`'${stringify(actual)}' is not a undefined.`, failureMessage);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
/**
|
|
236
|
+
* Asserts that a value is _not_ an array.
|
|
237
|
+
*
|
|
238
|
+
* Type guards the value.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
*
|
|
242
|
+
* ```ts
|
|
243
|
+
* import {assert} from '@augment-vir/assert';
|
|
244
|
+
*
|
|
245
|
+
* assert.isNotArray([]); // fails
|
|
246
|
+
* assert.isNotArray({length: 4}); // passes
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
250
|
+
* @see
|
|
251
|
+
* - {@link assert.isArray} : the opposite assertion.
|
|
252
|
+
*/
|
|
253
|
+
isNotArray(actual, failureMessage) {
|
|
254
|
+
if (Array.isArray(actual)) {
|
|
255
|
+
throw new AssertionError(`'${stringify(actual)}' is an array.`, failureMessage);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
/**
|
|
259
|
+
* Asserts that a value is _not_ a BigInt.
|
|
260
|
+
*
|
|
261
|
+
* Type guards the value.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* import {assert} from '@augment-vir/assert';
|
|
267
|
+
*
|
|
268
|
+
* assert.isNotBigInt(123n); // fails
|
|
269
|
+
* assert.isNotBigInt(123); // passes
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
273
|
+
* @see
|
|
274
|
+
* - {@link assert.isBigInt} : the opposite assertion.
|
|
275
|
+
*/
|
|
276
|
+
isNotBigInt(actual, failureMessage) {
|
|
277
|
+
if (typeof actual === 'bigint') {
|
|
278
|
+
throw new AssertionError(`'${stringify(actual)}' is a bigint.`, failureMessage);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
/**
|
|
282
|
+
* Asserts that a value is _not_ a boolean.
|
|
283
|
+
*
|
|
284
|
+
* Type guards the value.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
*
|
|
288
|
+
* ```ts
|
|
289
|
+
* import {assert} from '@augment-vir/assert';
|
|
290
|
+
*
|
|
291
|
+
* assert.isNotBoolean(true); // fails
|
|
292
|
+
* assert.isNotBoolean('true'); // passes
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
296
|
+
* @see
|
|
297
|
+
* - {@link assert.isBoolean} : the opposite assertion.
|
|
298
|
+
*/
|
|
299
|
+
isNotBoolean(actual, failureMessage) {
|
|
300
|
+
if (typeof actual === 'boolean') {
|
|
301
|
+
throw new AssertionError(`'${stringify(actual)}' is a boolean.`, failureMessage);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
/**
|
|
305
|
+
* Asserts that a value is _not_ a function.
|
|
306
|
+
*
|
|
307
|
+
* Type guards the value.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* import {assert} from '@augment-vir/assert';
|
|
313
|
+
*
|
|
314
|
+
* assert.isNotFunction(() => {}); // fails
|
|
315
|
+
* assert.isNotFunction({}); // passes
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
319
|
+
* @see
|
|
320
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
321
|
+
*/
|
|
322
|
+
isNotFunction(actual, failureMessage) {
|
|
323
|
+
if (typeof actual === 'function') {
|
|
324
|
+
throw new AssertionError(`'${stringify(actual)}' is a function.`, failureMessage);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* Asserts that a value is _not_ exactly `null`.
|
|
329
|
+
*
|
|
330
|
+
* Type guards the value.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
*
|
|
334
|
+
* ```ts
|
|
335
|
+
* import {assert} from '@augment-vir/assert';
|
|
336
|
+
*
|
|
337
|
+
* assert.isNotNull(null); // fails
|
|
338
|
+
* assert.isNotNull(undefined); // passes
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* @throws {@link AssertionError} If the assertion failed. @see
|
|
342
|
+
* @see
|
|
343
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
344
|
+
*/
|
|
345
|
+
isNotNull(actual, failureMessage) {
|
|
346
|
+
if (actual === null) {
|
|
347
|
+
throw new AssertionError(`'${stringify(actual)}' is a null.`, failureMessage);
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
/**
|
|
351
|
+
* Asserts that a value is _not_ a number. This includes `NaN`.
|
|
352
|
+
*
|
|
353
|
+
* Type guards the value.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
*
|
|
357
|
+
* ```ts
|
|
358
|
+
* import {assert} from '@augment-vir/assert';
|
|
359
|
+
*
|
|
360
|
+
* assert.isNotNumber(123); // fails
|
|
361
|
+
* assert.isNotNumber(123n); // passes
|
|
362
|
+
* ```
|
|
363
|
+
*
|
|
364
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
365
|
+
* @see
|
|
366
|
+
* - {@link assert.isNotFunction} : the opposite assertion.
|
|
367
|
+
*/
|
|
368
|
+
isNotNumber(actual, failureMessage) {
|
|
369
|
+
if (typeof actual === 'number') {
|
|
370
|
+
throw new AssertionError(`'${stringify(actual)}' is a number.`, failureMessage);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
/**
|
|
374
|
+
* Asserts that a value is _not_ an object. This includes arrays.
|
|
375
|
+
*
|
|
376
|
+
* Type guards the value.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
*
|
|
380
|
+
* ```ts
|
|
381
|
+
* import {assert} from '@augment-vir/assert';
|
|
382
|
+
*
|
|
383
|
+
* assert.isNotObject({}); // fails
|
|
384
|
+
* assert.isNotObject([]); // passes
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
388
|
+
* @see
|
|
389
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
390
|
+
*/
|
|
391
|
+
isNotObject(actual, failureMessage) {
|
|
392
|
+
if (!Array.isArray(actual) && typeof actual === 'object' && !!actual) {
|
|
393
|
+
throw new AssertionError(`'${stringify(actual)}' is a non-null object.`, failureMessage);
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
/**
|
|
397
|
+
* Asserts that a value is _not_ a string.
|
|
398
|
+
*
|
|
399
|
+
* Type guards the value.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
*
|
|
403
|
+
* ```ts
|
|
404
|
+
* import {assert} from '@augment-vir/assert';
|
|
405
|
+
*
|
|
406
|
+
* assert.isNotString(''); // fails
|
|
407
|
+
* assert.isNotString(5); // passes
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
411
|
+
* @see
|
|
412
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
413
|
+
*/
|
|
414
|
+
isNotString(actual, failureMessage) {
|
|
415
|
+
if (typeof actual === 'string') {
|
|
416
|
+
throw new AssertionError(`'${stringify(actual)}' is a string.`, failureMessage);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
/**
|
|
420
|
+
* Asserts that a value is _not_ a symbol.
|
|
421
|
+
*
|
|
422
|
+
* Type guards the value.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
*
|
|
426
|
+
* ```ts
|
|
427
|
+
* import {assert} from '@augment-vir/assert';
|
|
428
|
+
*
|
|
429
|
+
* assert.isNotSymbol(Symbol('my-symbol')); // fails
|
|
430
|
+
* assert.isNotSymbol('my-symbol'); // passes
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
434
|
+
* @see
|
|
435
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
436
|
+
*/
|
|
437
|
+
isNotSymbol(actual, failureMessage) {
|
|
438
|
+
if (typeof actual === 'symbol') {
|
|
439
|
+
throw new AssertionError(`'${stringify(actual)}' is a symbol.`, failureMessage);
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
/**
|
|
443
|
+
* Asserts that a value is _not_ exactly `undefined`.
|
|
444
|
+
*
|
|
445
|
+
* Type guards the value.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
*
|
|
449
|
+
* ```ts
|
|
450
|
+
* import {assert} from '@augment-vir/assert';
|
|
451
|
+
*
|
|
452
|
+
* assert.isNotUndefined(undefined); // fails
|
|
453
|
+
* assert.isNotUndefined(null); // passes
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
457
|
+
* @see
|
|
458
|
+
* - {@link assert.isFunction} : the opposite assertion.
|
|
459
|
+
*/
|
|
460
|
+
isNotUndefined(actual, failureMessage) {
|
|
461
|
+
if (typeof actual === 'undefined') {
|
|
462
|
+
throw new AssertionError(`'${stringify(actual)}' is a undefined.`, failureMessage);
|
|
463
|
+
}
|
|
464
|
+
},
|
|
88
465
|
};
|
|
89
466
|
export const runtimeTypeGuards = {
|
|
90
467
|
assert: assertions,
|
|
@@ -106,7 +483,9 @@ export const runtimeTypeGuards = {
|
|
|
106
483
|
* @see
|
|
107
484
|
* - {@link check.isNotArray} : the opposite check.
|
|
108
485
|
*/
|
|
109
|
-
isArray
|
|
486
|
+
isArray(actual) {
|
|
487
|
+
return Array.isArray(actual);
|
|
488
|
+
},
|
|
110
489
|
/**
|
|
111
490
|
* Checks that a value is a BigInt.
|
|
112
491
|
*
|
|
@@ -124,7 +503,9 @@ export const runtimeTypeGuards = {
|
|
|
124
503
|
* @see
|
|
125
504
|
* - {@link check.isNotBigInt} : the opposite check.
|
|
126
505
|
*/
|
|
127
|
-
isBigInt
|
|
506
|
+
isBigInt(actual) {
|
|
507
|
+
return typeof actual === 'bigint';
|
|
508
|
+
},
|
|
128
509
|
/**
|
|
129
510
|
* Checks that a value is a boolean.
|
|
130
511
|
*
|
|
@@ -142,7 +523,9 @@ export const runtimeTypeGuards = {
|
|
|
142
523
|
* @see
|
|
143
524
|
* - {@link check.isNotBoolean} : the opposite check.
|
|
144
525
|
*/
|
|
145
|
-
isBoolean
|
|
526
|
+
isBoolean(actual) {
|
|
527
|
+
return typeof actual === 'boolean';
|
|
528
|
+
},
|
|
146
529
|
/**
|
|
147
530
|
* Checks that a value is a function.
|
|
148
531
|
*
|
|
@@ -160,7 +543,9 @@ export const runtimeTypeGuards = {
|
|
|
160
543
|
* @see
|
|
161
544
|
* - {@link check.isNotFunction} : the opposite check.
|
|
162
545
|
*/
|
|
163
|
-
isFunction
|
|
546
|
+
isFunction(actual) {
|
|
547
|
+
return typeof actual === 'function';
|
|
548
|
+
},
|
|
164
549
|
/**
|
|
165
550
|
* Checks that a value is exactly `null`.
|
|
166
551
|
*
|
|
@@ -178,7 +563,9 @@ export const runtimeTypeGuards = {
|
|
|
178
563
|
* @see
|
|
179
564
|
* - {@link check.isNotFunction} : the opposite check.
|
|
180
565
|
*/
|
|
181
|
-
isNull
|
|
566
|
+
isNull(actual) {
|
|
567
|
+
return actual === null;
|
|
568
|
+
},
|
|
182
569
|
/**
|
|
183
570
|
* Checks that a value is a number. This excludes `NaN`.
|
|
184
571
|
*
|
|
@@ -196,7 +583,9 @@ export const runtimeTypeGuards = {
|
|
|
196
583
|
* @see
|
|
197
584
|
* - {@link check.isNotFunction} : the opposite check.
|
|
198
585
|
*/
|
|
199
|
-
isNumber
|
|
586
|
+
isNumber(actual) {
|
|
587
|
+
return typeof actual === 'number';
|
|
588
|
+
},
|
|
200
589
|
/**
|
|
201
590
|
* Checks that a value is an object. This excludes arrays.
|
|
202
591
|
*
|
|
@@ -214,7 +603,9 @@ export const runtimeTypeGuards = {
|
|
|
214
603
|
* @see
|
|
215
604
|
* - {@link check.isNotFunction} : the opposite check.
|
|
216
605
|
*/
|
|
217
|
-
isObject
|
|
606
|
+
isObject(actual) {
|
|
607
|
+
return !Array.isArray(actual) && typeof actual === 'object' && !!actual;
|
|
608
|
+
},
|
|
218
609
|
/**
|
|
219
610
|
* Checks that a value is a string.
|
|
220
611
|
*
|
|
@@ -232,7 +623,9 @@ export const runtimeTypeGuards = {
|
|
|
232
623
|
* @see
|
|
233
624
|
* - {@link check.isNotFunction} : the opposite check.
|
|
234
625
|
*/
|
|
235
|
-
isString
|
|
626
|
+
isString(actual) {
|
|
627
|
+
return typeof actual === 'string';
|
|
628
|
+
},
|
|
236
629
|
/**
|
|
237
630
|
* Checks that a value is a symbol.
|
|
238
631
|
*
|
|
@@ -250,7 +643,9 @@ export const runtimeTypeGuards = {
|
|
|
250
643
|
* @see
|
|
251
644
|
* - {@link check.isNotFunction} : the opposite check.
|
|
252
645
|
*/
|
|
253
|
-
isSymbol
|
|
646
|
+
isSymbol(actual) {
|
|
647
|
+
return typeof actual === 'symbol';
|
|
648
|
+
},
|
|
254
649
|
/**
|
|
255
650
|
* Checks that a value is exactly `undefined`.
|
|
256
651
|
*
|
|
@@ -268,7 +663,9 @@ export const runtimeTypeGuards = {
|
|
|
268
663
|
* @see
|
|
269
664
|
* - {@link check.isNotFunction} : the opposite check.
|
|
270
665
|
*/
|
|
271
|
-
isUndefined
|
|
666
|
+
isUndefined(actual) {
|
|
667
|
+
return actual === undefined;
|
|
668
|
+
},
|
|
272
669
|
/**
|
|
273
670
|
* Checks that a value is _not_ an array.
|
|
274
671
|
*
|
|
@@ -286,7 +683,9 @@ export const runtimeTypeGuards = {
|
|
|
286
683
|
* @see
|
|
287
684
|
* - {@link check.isArray} : the opposite check.
|
|
288
685
|
*/
|
|
289
|
-
isNotArray
|
|
686
|
+
isNotArray(actual) {
|
|
687
|
+
return !Array.isArray(actual);
|
|
688
|
+
},
|
|
290
689
|
/**
|
|
291
690
|
* Checks that a value is _not_ a BigInt.
|
|
292
691
|
*
|
|
@@ -304,7 +703,9 @@ export const runtimeTypeGuards = {
|
|
|
304
703
|
* @see
|
|
305
704
|
* - {@link check.isBigInt} : the opposite check.
|
|
306
705
|
*/
|
|
307
|
-
isNotBigInt
|
|
706
|
+
isNotBigInt(actual) {
|
|
707
|
+
return typeof actual !== 'bigint';
|
|
708
|
+
},
|
|
308
709
|
/**
|
|
309
710
|
* Checks that a value is _not_ a boolean.
|
|
310
711
|
*
|
|
@@ -322,7 +723,9 @@ export const runtimeTypeGuards = {
|
|
|
322
723
|
* @see
|
|
323
724
|
* - {@link check.isBoolean} : the opposite check.
|
|
324
725
|
*/
|
|
325
|
-
isNotBoolean
|
|
726
|
+
isNotBoolean(actual) {
|
|
727
|
+
return typeof actual !== 'boolean';
|
|
728
|
+
},
|
|
326
729
|
/**
|
|
327
730
|
* Checks that a value is _not_ a function.
|
|
328
731
|
*
|
|
@@ -340,7 +743,9 @@ export const runtimeTypeGuards = {
|
|
|
340
743
|
* @see
|
|
341
744
|
* - {@link check.isFunction} : the opposite check.
|
|
342
745
|
*/
|
|
343
|
-
isNotFunction
|
|
746
|
+
isNotFunction(actual) {
|
|
747
|
+
return typeof actual !== 'function';
|
|
748
|
+
},
|
|
344
749
|
/**
|
|
345
750
|
* Checks that a value is _not_ exactly `null`.
|
|
346
751
|
*
|
|
@@ -358,7 +763,9 @@ export const runtimeTypeGuards = {
|
|
|
358
763
|
* @see
|
|
359
764
|
* - {@link check.isFunction} : the opposite check.
|
|
360
765
|
*/
|
|
361
|
-
isNotNull
|
|
766
|
+
isNotNull(actual) {
|
|
767
|
+
return actual !== null;
|
|
768
|
+
},
|
|
362
769
|
/**
|
|
363
770
|
* Checks that a value is _not_ a number. This includes `NaN`.
|
|
364
771
|
*
|
|
@@ -376,7 +783,9 @@ export const runtimeTypeGuards = {
|
|
|
376
783
|
* @see
|
|
377
784
|
* - {@link check.isNotFunction} : the opposite check.
|
|
378
785
|
*/
|
|
379
|
-
isNotNumber
|
|
786
|
+
isNotNumber(actual) {
|
|
787
|
+
return typeof actual !== 'number';
|
|
788
|
+
},
|
|
380
789
|
/**
|
|
381
790
|
* Checks that a value is _not_ an object. This includes arrays.
|
|
382
791
|
*
|
|
@@ -394,7 +803,9 @@ export const runtimeTypeGuards = {
|
|
|
394
803
|
* @see
|
|
395
804
|
* - {@link check.isFunction} : the opposite check.
|
|
396
805
|
*/
|
|
397
|
-
isNotObject
|
|
806
|
+
isNotObject(actual) {
|
|
807
|
+
return Array.isArray(actual) || typeof actual !== 'object' || !actual;
|
|
808
|
+
},
|
|
398
809
|
/**
|
|
399
810
|
* Checks that a value is _not_ a string.
|
|
400
811
|
*
|
|
@@ -412,7 +823,9 @@ export const runtimeTypeGuards = {
|
|
|
412
823
|
* @see
|
|
413
824
|
* - {@link check.isFunction} : the opposite check.
|
|
414
825
|
*/
|
|
415
|
-
isNotString
|
|
826
|
+
isNotString(actual) {
|
|
827
|
+
return typeof actual !== 'string';
|
|
828
|
+
},
|
|
416
829
|
/**
|
|
417
830
|
* Checks that a value is _not_ a symbol.
|
|
418
831
|
*
|
|
@@ -430,7 +843,9 @@ export const runtimeTypeGuards = {
|
|
|
430
843
|
* @see
|
|
431
844
|
* - {@link check.isFunction} : the opposite check.
|
|
432
845
|
*/
|
|
433
|
-
isNotSymbol
|
|
846
|
+
isNotSymbol(actual) {
|
|
847
|
+
return typeof actual !== 'symbol';
|
|
848
|
+
},
|
|
434
849
|
/**
|
|
435
850
|
* Checks that a value is _not_ exactly `undefined`.
|
|
436
851
|
*
|
|
@@ -448,7 +863,9 @@ export const runtimeTypeGuards = {
|
|
|
448
863
|
* @see
|
|
449
864
|
* - {@link check.isFunction} : the opposite check.
|
|
450
865
|
*/
|
|
451
|
-
isNotUndefined
|
|
866
|
+
isNotUndefined(actual) {
|
|
867
|
+
return typeof actual !== 'undefined';
|
|
868
|
+
},
|
|
452
869
|
},
|
|
453
870
|
assertWrap: {
|
|
454
871
|
/**
|
|
@@ -470,7 +887,12 @@ export const runtimeTypeGuards = {
|
|
|
470
887
|
* @see
|
|
471
888
|
* - {@link assertWrap.isNotArray} : the opposite assertion.
|
|
472
889
|
*/
|
|
473
|
-
isArray
|
|
890
|
+
isArray(actual, failureMessage) {
|
|
891
|
+
if (!Array.isArray(actual)) {
|
|
892
|
+
throw new AssertionError(`'${stringify(actual)}' is not an array.`, failureMessage);
|
|
893
|
+
}
|
|
894
|
+
return actual;
|
|
895
|
+
},
|
|
474
896
|
/**
|
|
475
897
|
* Asserts that a value is a BigInt. Returns the value if the assertion passes.
|
|
476
898
|
*
|
|
@@ -490,7 +912,12 @@ export const runtimeTypeGuards = {
|
|
|
490
912
|
* @see
|
|
491
913
|
* - {@link assertWrap.isNotBigInt} : the opposite assertion.
|
|
492
914
|
*/
|
|
493
|
-
isBigInt
|
|
915
|
+
isBigInt(actual, failureMessage) {
|
|
916
|
+
if (typeof actual !== 'bigint') {
|
|
917
|
+
throw new AssertionError(`'${stringify(actual)}' is not a bigint.`, failureMessage);
|
|
918
|
+
}
|
|
919
|
+
return actual;
|
|
920
|
+
},
|
|
494
921
|
/**
|
|
495
922
|
* Asserts that a value is a boolean. Returns the value if the assertion passes.
|
|
496
923
|
*
|
|
@@ -510,7 +937,12 @@ export const runtimeTypeGuards = {
|
|
|
510
937
|
* @see
|
|
511
938
|
* - {@link assertWrap.isNotBoolean} : the opposite assertion.
|
|
512
939
|
*/
|
|
513
|
-
isBoolean
|
|
940
|
+
isBoolean(actual, failureMessage) {
|
|
941
|
+
if (typeof actual !== 'boolean') {
|
|
942
|
+
throw new AssertionError(`'${stringify(actual)}' is not a boolean.`, failureMessage);
|
|
943
|
+
}
|
|
944
|
+
return actual;
|
|
945
|
+
},
|
|
514
946
|
/**
|
|
515
947
|
* Asserts that a value is a function. Returns the value if the assertion passes.
|
|
516
948
|
*
|
|
@@ -530,7 +962,12 @@ export const runtimeTypeGuards = {
|
|
|
530
962
|
* @see
|
|
531
963
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
532
964
|
*/
|
|
533
|
-
isFunction
|
|
965
|
+
isFunction(actual, failureMessage) {
|
|
966
|
+
if (typeof actual !== 'function') {
|
|
967
|
+
throw new AssertionError(`'${stringify(actual)}' is not a function.`, failureMessage);
|
|
968
|
+
}
|
|
969
|
+
return actual;
|
|
970
|
+
},
|
|
534
971
|
/**
|
|
535
972
|
* Asserts that a value is exactly `null. Returns the value if the assertion passes.
|
|
536
973
|
*
|
|
@@ -550,7 +987,12 @@ export const runtimeTypeGuards = {
|
|
|
550
987
|
* @see
|
|
551
988
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
552
989
|
*/
|
|
553
|
-
isNull
|
|
990
|
+
isNull(actual, failureMessage) {
|
|
991
|
+
if (actual !== null) {
|
|
992
|
+
throw new AssertionError(`'${stringify(actual)}' is not nul.`, failureMessage);
|
|
993
|
+
}
|
|
994
|
+
return actual;
|
|
995
|
+
},
|
|
554
996
|
/**
|
|
555
997
|
* Asserts that a value is a number. This excludes `NaN. Returns the value if the assertion
|
|
556
998
|
* passes.
|
|
@@ -571,7 +1013,12 @@ export const runtimeTypeGuards = {
|
|
|
571
1013
|
* @see
|
|
572
1014
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
573
1015
|
*/
|
|
574
|
-
isNumber
|
|
1016
|
+
isNumber(actual, failureMessage) {
|
|
1017
|
+
if (typeof actual !== 'number' || isNaN(actual)) {
|
|
1018
|
+
throw new AssertionError(`'${stringify(actual)}' is not a number.`, failureMessage);
|
|
1019
|
+
}
|
|
1020
|
+
return actual;
|
|
1021
|
+
},
|
|
575
1022
|
/**
|
|
576
1023
|
* Asserts that a value is an object. This excludes arrays. Returns the value if the
|
|
577
1024
|
* assertion passes.
|
|
@@ -592,7 +1039,12 @@ export const runtimeTypeGuards = {
|
|
|
592
1039
|
* @see
|
|
593
1040
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
594
1041
|
*/
|
|
595
|
-
isObject
|
|
1042
|
+
isObject(actual, failureMessage) {
|
|
1043
|
+
if (Array.isArray(actual) || typeof actual !== 'object' || !actual) {
|
|
1044
|
+
throw new AssertionError(`'${stringify(actual)}' is not a non-null object.`, failureMessage);
|
|
1045
|
+
}
|
|
1046
|
+
return actual;
|
|
1047
|
+
},
|
|
596
1048
|
/**
|
|
597
1049
|
* Asserts that a value is a string. Returns the value if the assertion passes.
|
|
598
1050
|
*
|
|
@@ -612,7 +1064,12 @@ export const runtimeTypeGuards = {
|
|
|
612
1064
|
* @see
|
|
613
1065
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
614
1066
|
*/
|
|
615
|
-
isString
|
|
1067
|
+
isString(actual, failureMessage) {
|
|
1068
|
+
if (typeof actual !== 'string') {
|
|
1069
|
+
throw new AssertionError(`'${stringify(actual)}' is not a string.`, failureMessage);
|
|
1070
|
+
}
|
|
1071
|
+
return actual;
|
|
1072
|
+
},
|
|
616
1073
|
/**
|
|
617
1074
|
* Trying to assign a unique symbol to another variable kills the `unique` part of the
|
|
618
1075
|
* symbol. this seems to be a bug with TypeScript itself.
|
|
@@ -641,7 +1098,12 @@ export const runtimeTypeGuards = {
|
|
|
641
1098
|
* @see
|
|
642
1099
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
643
1100
|
*/
|
|
644
|
-
isSymbol
|
|
1101
|
+
isSymbol(actual, failureMessage) {
|
|
1102
|
+
if (typeof actual !== 'symbol') {
|
|
1103
|
+
throw new AssertionError(`'${stringify(actual)}' is not a symbol.`, failureMessage);
|
|
1104
|
+
}
|
|
1105
|
+
return actual;
|
|
1106
|
+
},
|
|
645
1107
|
/**
|
|
646
1108
|
* Asserts that a value is exactly `undefined. Returns the value if the assertion passes.
|
|
647
1109
|
*
|
|
@@ -661,7 +1123,12 @@ export const runtimeTypeGuards = {
|
|
|
661
1123
|
* @see
|
|
662
1124
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
663
1125
|
*/
|
|
664
|
-
isUndefined
|
|
1126
|
+
isUndefined(actual, failureMessage) {
|
|
1127
|
+
if (typeof actual !== 'undefined') {
|
|
1128
|
+
throw new AssertionError(`'${stringify(actual)}' is not a undefined.`, failureMessage);
|
|
1129
|
+
}
|
|
1130
|
+
return actual;
|
|
1131
|
+
},
|
|
665
1132
|
/**
|
|
666
1133
|
* Asserts that a value is _not_ an array. Returns the value if the assertion passes.
|
|
667
1134
|
*
|
|
@@ -681,7 +1148,12 @@ export const runtimeTypeGuards = {
|
|
|
681
1148
|
* @see
|
|
682
1149
|
* - {@link assertWrap.isArray} : the opposite assertion.
|
|
683
1150
|
*/
|
|
684
|
-
isNotArray
|
|
1151
|
+
isNotArray(actual, failureMessage) {
|
|
1152
|
+
if (Array.isArray(actual)) {
|
|
1153
|
+
throw new AssertionError(`'${stringify(actual)}' is an array.`, failureMessage);
|
|
1154
|
+
}
|
|
1155
|
+
return actual;
|
|
1156
|
+
},
|
|
685
1157
|
/**
|
|
686
1158
|
* Asserts that a value is _not_ a BigInt. Returns the value if the assertion passes.
|
|
687
1159
|
*
|
|
@@ -701,7 +1173,12 @@ export const runtimeTypeGuards = {
|
|
|
701
1173
|
* @see
|
|
702
1174
|
* - {@link assertWrap.isBigInt} : the opposite assertion.
|
|
703
1175
|
*/
|
|
704
|
-
isNotBigInt
|
|
1176
|
+
isNotBigInt(actual, failureMessage) {
|
|
1177
|
+
if (typeof actual === 'bigint') {
|
|
1178
|
+
throw new AssertionError(`'${stringify(actual)}' is a bigint.`, failureMessage);
|
|
1179
|
+
}
|
|
1180
|
+
return actual;
|
|
1181
|
+
},
|
|
705
1182
|
/**
|
|
706
1183
|
* Asserts that a value is _not_ a boolean. Returns the value if the assertion passes.
|
|
707
1184
|
*
|
|
@@ -721,7 +1198,12 @@ export const runtimeTypeGuards = {
|
|
|
721
1198
|
* @see
|
|
722
1199
|
* - {@link assertWrap.isBoolean} : the opposite assertion.
|
|
723
1200
|
*/
|
|
724
|
-
isNotBoolean
|
|
1201
|
+
isNotBoolean(actual, failureMessage) {
|
|
1202
|
+
if (typeof actual === 'boolean') {
|
|
1203
|
+
throw new AssertionError(`'${stringify(actual)}' is a boolean.`, failureMessage);
|
|
1204
|
+
}
|
|
1205
|
+
return actual;
|
|
1206
|
+
},
|
|
725
1207
|
/**
|
|
726
1208
|
* Asserts that a value is _not_ a function. Returns the value if the assertion passes.
|
|
727
1209
|
*
|
|
@@ -741,7 +1223,12 @@ export const runtimeTypeGuards = {
|
|
|
741
1223
|
* @see
|
|
742
1224
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
743
1225
|
*/
|
|
744
|
-
isNotFunction
|
|
1226
|
+
isNotFunction(actual, failureMessage) {
|
|
1227
|
+
if (typeof actual === 'function') {
|
|
1228
|
+
throw new AssertionError(`'${stringify(actual)}' is a function.`, failureMessage);
|
|
1229
|
+
}
|
|
1230
|
+
return actual;
|
|
1231
|
+
},
|
|
745
1232
|
/**
|
|
746
1233
|
* Asserts that a value is _not_ exactly `null. Returns the value if the assertion passes.
|
|
747
1234
|
*
|
|
@@ -761,7 +1248,12 @@ export const runtimeTypeGuards = {
|
|
|
761
1248
|
* @see
|
|
762
1249
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
763
1250
|
*/
|
|
764
|
-
isNotNull
|
|
1251
|
+
isNotNull(actual, failureMessage) {
|
|
1252
|
+
if (actual === null) {
|
|
1253
|
+
throw new AssertionError(`'${stringify(actual)}' is a null.`, failureMessage);
|
|
1254
|
+
}
|
|
1255
|
+
return actual;
|
|
1256
|
+
},
|
|
765
1257
|
/**
|
|
766
1258
|
* Asserts that a value is _not_ a number. This includes `NaN. Returns the value if the
|
|
767
1259
|
* assertion passes.
|
|
@@ -782,7 +1274,12 @@ export const runtimeTypeGuards = {
|
|
|
782
1274
|
* @see
|
|
783
1275
|
* - {@link assertWrap.isNotFunction} : the opposite assertion.
|
|
784
1276
|
*/
|
|
785
|
-
isNotNumber
|
|
1277
|
+
isNotNumber(actual, failureMessage) {
|
|
1278
|
+
if (typeof actual === 'number') {
|
|
1279
|
+
throw new AssertionError(`'${stringify(actual)}' is a number.`, failureMessage);
|
|
1280
|
+
}
|
|
1281
|
+
return actual;
|
|
1282
|
+
},
|
|
786
1283
|
/**
|
|
787
1284
|
* Asserts that a value is _not_ an object. This includes arrays. Returns the value if the
|
|
788
1285
|
* assertion passes.
|
|
@@ -803,7 +1300,12 @@ export const runtimeTypeGuards = {
|
|
|
803
1300
|
* @see
|
|
804
1301
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
805
1302
|
*/
|
|
806
|
-
isNotObject
|
|
1303
|
+
isNotObject(actual, failureMessage) {
|
|
1304
|
+
if (!Array.isArray(actual) && typeof actual === 'object' && !!actual) {
|
|
1305
|
+
throw new AssertionError(`'${stringify(actual)}' is a non-null object.`, failureMessage);
|
|
1306
|
+
}
|
|
1307
|
+
return actual;
|
|
1308
|
+
},
|
|
807
1309
|
/**
|
|
808
1310
|
* Asserts that a value is _not_ a string. Returns the value if the assertion passes.
|
|
809
1311
|
*
|
|
@@ -823,7 +1325,12 @@ export const runtimeTypeGuards = {
|
|
|
823
1325
|
* @see
|
|
824
1326
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
825
1327
|
*/
|
|
826
|
-
isNotString
|
|
1328
|
+
isNotString(actual, failureMessage) {
|
|
1329
|
+
if (typeof actual === 'string') {
|
|
1330
|
+
throw new AssertionError(`'${stringify(actual)}' is a string.`, failureMessage);
|
|
1331
|
+
}
|
|
1332
|
+
return actual;
|
|
1333
|
+
},
|
|
827
1334
|
/**
|
|
828
1335
|
* Asserts that a value is _not_ a symbol. Returns the value if the assertion passes.
|
|
829
1336
|
*
|
|
@@ -843,7 +1350,12 @@ export const runtimeTypeGuards = {
|
|
|
843
1350
|
* @see
|
|
844
1351
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
845
1352
|
*/
|
|
846
|
-
isNotSymbol
|
|
1353
|
+
isNotSymbol(actual, failureMessage) {
|
|
1354
|
+
if (typeof actual === 'symbol') {
|
|
1355
|
+
throw new AssertionError(`'${stringify(actual)}' is a symbol.`, failureMessage);
|
|
1356
|
+
}
|
|
1357
|
+
return actual;
|
|
1358
|
+
},
|
|
847
1359
|
/**
|
|
848
1360
|
* Asserts that a value is _not_ exactly `undefined. Returns the value if the assertion
|
|
849
1361
|
* passes.
|
|
@@ -864,7 +1376,12 @@ export const runtimeTypeGuards = {
|
|
|
864
1376
|
* @see
|
|
865
1377
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
866
1378
|
*/
|
|
867
|
-
isNotUndefined
|
|
1379
|
+
isNotUndefined(actual, failureMessage) {
|
|
1380
|
+
if (typeof actual === 'undefined') {
|
|
1381
|
+
throw new AssertionError(`'${stringify(actual)}' is a undefined.`, failureMessage);
|
|
1382
|
+
}
|
|
1383
|
+
return actual;
|
|
1384
|
+
},
|
|
868
1385
|
},
|
|
869
1386
|
checkWrap: {
|
|
870
1387
|
/**
|
|
@@ -886,7 +1403,14 @@ export const runtimeTypeGuards = {
|
|
|
886
1403
|
* @see
|
|
887
1404
|
* - {@link checkWrap.isNotArray} : the opposite check.
|
|
888
1405
|
*/
|
|
889
|
-
isArray
|
|
1406
|
+
isArray(actual) {
|
|
1407
|
+
if (Array.isArray(actual)) {
|
|
1408
|
+
return actual;
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
return undefined;
|
|
1412
|
+
}
|
|
1413
|
+
},
|
|
890
1414
|
/**
|
|
891
1415
|
* Checks that a value is a BigInt. Returns the value if the check passes, otherwise
|
|
892
1416
|
* `undefined`.
|
|
@@ -906,7 +1430,14 @@ export const runtimeTypeGuards = {
|
|
|
906
1430
|
* @see
|
|
907
1431
|
* - {@link checkWrap.isNotBigInt} : the opposite check.
|
|
908
1432
|
*/
|
|
909
|
-
isBigInt
|
|
1433
|
+
isBigInt(actual) {
|
|
1434
|
+
if (typeof actual === 'bigint') {
|
|
1435
|
+
return actual;
|
|
1436
|
+
}
|
|
1437
|
+
else {
|
|
1438
|
+
return undefined;
|
|
1439
|
+
}
|
|
1440
|
+
},
|
|
910
1441
|
/**
|
|
911
1442
|
* Checks that a value is a boolean. Returns the value if the check passes, otherwise
|
|
912
1443
|
* `undefined`.
|
|
@@ -926,7 +1457,14 @@ export const runtimeTypeGuards = {
|
|
|
926
1457
|
* @see
|
|
927
1458
|
* - {@link checkWrap.isNotBoolean} : the opposite check.
|
|
928
1459
|
*/
|
|
929
|
-
isBoolean
|
|
1460
|
+
isBoolean(actual) {
|
|
1461
|
+
if (typeof actual === 'boolean') {
|
|
1462
|
+
return actual;
|
|
1463
|
+
}
|
|
1464
|
+
else {
|
|
1465
|
+
return undefined;
|
|
1466
|
+
}
|
|
1467
|
+
},
|
|
930
1468
|
/**
|
|
931
1469
|
* Checks that a value is a function. Returns the value if the check passes, otherwise
|
|
932
1470
|
* `undefined`.
|
|
@@ -946,7 +1484,14 @@ export const runtimeTypeGuards = {
|
|
|
946
1484
|
* @see
|
|
947
1485
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
948
1486
|
*/
|
|
949
|
-
isFunction
|
|
1487
|
+
isFunction(actual) {
|
|
1488
|
+
if (typeof actual === 'function') {
|
|
1489
|
+
return actual;
|
|
1490
|
+
}
|
|
1491
|
+
else {
|
|
1492
|
+
return undefined;
|
|
1493
|
+
}
|
|
1494
|
+
},
|
|
950
1495
|
/**
|
|
951
1496
|
* Checks that a value is exactly `null. Returns the value if the check passes, otherwise
|
|
952
1497
|
* `undefined`.
|
|
@@ -966,7 +1511,14 @@ export const runtimeTypeGuards = {
|
|
|
966
1511
|
* @see
|
|
967
1512
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
968
1513
|
*/
|
|
969
|
-
isNull
|
|
1514
|
+
isNull(actual) {
|
|
1515
|
+
if (actual === null) {
|
|
1516
|
+
return actual;
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
return undefined;
|
|
1520
|
+
}
|
|
1521
|
+
},
|
|
970
1522
|
/**
|
|
971
1523
|
* Checks that a value is a number. This excludes `NaN. Returns the value if the check
|
|
972
1524
|
* passes, otherwise `undefined`.
|
|
@@ -986,7 +1538,14 @@ export const runtimeTypeGuards = {
|
|
|
986
1538
|
* @see
|
|
987
1539
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
988
1540
|
*/
|
|
989
|
-
isNumber
|
|
1541
|
+
isNumber(actual) {
|
|
1542
|
+
if (typeof actual === 'number') {
|
|
1543
|
+
return actual;
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
return undefined;
|
|
1547
|
+
}
|
|
1548
|
+
},
|
|
990
1549
|
/**
|
|
991
1550
|
* Checks that a value is an object. This excludes arrays. Returns the value if the check
|
|
992
1551
|
* passes, otherwise `undefined`.
|
|
@@ -1006,7 +1565,14 @@ export const runtimeTypeGuards = {
|
|
|
1006
1565
|
* @see
|
|
1007
1566
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1008
1567
|
*/
|
|
1009
|
-
isObject
|
|
1568
|
+
isObject(actual) {
|
|
1569
|
+
if (!Array.isArray(actual) && typeof actual === 'object' && !!actual) {
|
|
1570
|
+
return actual;
|
|
1571
|
+
}
|
|
1572
|
+
else {
|
|
1573
|
+
return undefined;
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1010
1576
|
/**
|
|
1011
1577
|
* Checks that a value is a string. Returns the value if the check passes, otherwise
|
|
1012
1578
|
* `undefined`.
|
|
@@ -1026,7 +1592,14 @@ export const runtimeTypeGuards = {
|
|
|
1026
1592
|
* @see
|
|
1027
1593
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1028
1594
|
*/
|
|
1029
|
-
isString
|
|
1595
|
+
isString(actual) {
|
|
1596
|
+
if (typeof actual === 'string') {
|
|
1597
|
+
return actual;
|
|
1598
|
+
}
|
|
1599
|
+
else {
|
|
1600
|
+
return undefined;
|
|
1601
|
+
}
|
|
1602
|
+
},
|
|
1030
1603
|
/**
|
|
1031
1604
|
* Checks that a value is a symbol. Returns the value if the check passes, otherwise
|
|
1032
1605
|
* `undefined`.
|
|
@@ -1046,32 +1619,14 @@ export const runtimeTypeGuards = {
|
|
|
1046
1619
|
* @see
|
|
1047
1620
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1048
1621
|
*/
|
|
1049
|
-
isSymbol
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
* otherwise `undefined`.
|
|
1058
|
-
*
|
|
1059
|
-
* Type guards the value.
|
|
1060
|
-
*
|
|
1061
|
-
* @example
|
|
1062
|
-
*
|
|
1063
|
-
* ```ts
|
|
1064
|
-
* import {checkWrap} from '@augment-vir/assert';
|
|
1065
|
-
*
|
|
1066
|
-
* checkWrap.isUndefined(undefined); // returns `undefined`
|
|
1067
|
-
* checkWrap.isUndefined(null); // returns `undefined`
|
|
1068
|
-
* ```
|
|
1069
|
-
*
|
|
1070
|
-
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1071
|
-
* @see
|
|
1072
|
-
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1073
|
-
*/
|
|
1074
|
-
isUndefined: undefined,
|
|
1622
|
+
isSymbol(actual) {
|
|
1623
|
+
if (typeof actual === 'symbol') {
|
|
1624
|
+
return actual;
|
|
1625
|
+
}
|
|
1626
|
+
else {
|
|
1627
|
+
return undefined;
|
|
1628
|
+
}
|
|
1629
|
+
},
|
|
1075
1630
|
/**
|
|
1076
1631
|
* Checks that a value is _not_ an array. Returns the value if the check passes, otherwise
|
|
1077
1632
|
* `undefined`.
|
|
@@ -1091,7 +1646,14 @@ export const runtimeTypeGuards = {
|
|
|
1091
1646
|
* @see
|
|
1092
1647
|
* - {@link checkWrap.isArray} : the opposite check.
|
|
1093
1648
|
*/
|
|
1094
|
-
isNotArray
|
|
1649
|
+
isNotArray(actual) {
|
|
1650
|
+
if (Array.isArray(actual)) {
|
|
1651
|
+
return undefined;
|
|
1652
|
+
}
|
|
1653
|
+
else {
|
|
1654
|
+
return actual;
|
|
1655
|
+
}
|
|
1656
|
+
},
|
|
1095
1657
|
/**
|
|
1096
1658
|
* Checks that a value is _not_ a BigInt. Returns the value if the check passes, otherwise
|
|
1097
1659
|
* `undefined`.
|
|
@@ -1111,7 +1673,14 @@ export const runtimeTypeGuards = {
|
|
|
1111
1673
|
* @see
|
|
1112
1674
|
* - {@link checkWrap.isBigInt} : the opposite check.
|
|
1113
1675
|
*/
|
|
1114
|
-
isNotBigInt
|
|
1676
|
+
isNotBigInt(actual) {
|
|
1677
|
+
if (typeof actual === 'bigint') {
|
|
1678
|
+
return undefined;
|
|
1679
|
+
}
|
|
1680
|
+
else {
|
|
1681
|
+
return actual;
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
1115
1684
|
/**
|
|
1116
1685
|
* Checks that a value is _not_ a boolean. Returns the value if the check passes, otherwise
|
|
1117
1686
|
* `undefined`.
|
|
@@ -1131,7 +1700,14 @@ export const runtimeTypeGuards = {
|
|
|
1131
1700
|
* @see
|
|
1132
1701
|
* - {@link checkWrap.isBoolean} : the opposite check.
|
|
1133
1702
|
*/
|
|
1134
|
-
isNotBoolean
|
|
1703
|
+
isNotBoolean(actual) {
|
|
1704
|
+
if (typeof actual === 'boolean') {
|
|
1705
|
+
return undefined;
|
|
1706
|
+
}
|
|
1707
|
+
else {
|
|
1708
|
+
return actual;
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1135
1711
|
/**
|
|
1136
1712
|
* Checks that a value is _not_ a function. Returns the value if the check passes, otherwise
|
|
1137
1713
|
* `undefined`.
|
|
@@ -1151,7 +1727,14 @@ export const runtimeTypeGuards = {
|
|
|
1151
1727
|
* @see
|
|
1152
1728
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1153
1729
|
*/
|
|
1154
|
-
isNotFunction
|
|
1730
|
+
isNotFunction(actual) {
|
|
1731
|
+
if (typeof actual === 'function') {
|
|
1732
|
+
return undefined;
|
|
1733
|
+
}
|
|
1734
|
+
else {
|
|
1735
|
+
return actual;
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1155
1738
|
/**
|
|
1156
1739
|
* Checks that a value is _not_ exactly `null. Returns the value if the check passes,
|
|
1157
1740
|
* otherwise `undefined`.
|
|
@@ -1171,7 +1754,14 @@ export const runtimeTypeGuards = {
|
|
|
1171
1754
|
* @see
|
|
1172
1755
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1173
1756
|
*/
|
|
1174
|
-
isNotNull
|
|
1757
|
+
isNotNull(actual) {
|
|
1758
|
+
if (actual === null) {
|
|
1759
|
+
return undefined;
|
|
1760
|
+
}
|
|
1761
|
+
else {
|
|
1762
|
+
return actual;
|
|
1763
|
+
}
|
|
1764
|
+
},
|
|
1175
1765
|
/**
|
|
1176
1766
|
* Checks that a value is _not_ a number. This includes `NaN. Returns the value if the check
|
|
1177
1767
|
* passes, otherwise `undefined`.
|
|
@@ -1191,7 +1781,14 @@ export const runtimeTypeGuards = {
|
|
|
1191
1781
|
* @see
|
|
1192
1782
|
* - {@link checkWrap.isNotFunction} : the opposite check.
|
|
1193
1783
|
*/
|
|
1194
|
-
isNotNumber
|
|
1784
|
+
isNotNumber(actual) {
|
|
1785
|
+
if (typeof actual === 'number') {
|
|
1786
|
+
return undefined;
|
|
1787
|
+
}
|
|
1788
|
+
else {
|
|
1789
|
+
return actual;
|
|
1790
|
+
}
|
|
1791
|
+
},
|
|
1195
1792
|
/**
|
|
1196
1793
|
* Checks that a value is _not_ an object. This includes arrays. Returns the value if the
|
|
1197
1794
|
* check passes, otherwise `undefined`.
|
|
@@ -1211,7 +1808,14 @@ export const runtimeTypeGuards = {
|
|
|
1211
1808
|
* @see
|
|
1212
1809
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1213
1810
|
*/
|
|
1214
|
-
isNotObject
|
|
1811
|
+
isNotObject(actual) {
|
|
1812
|
+
if (Array.isArray(actual) || typeof actual !== 'object' || !actual) {
|
|
1813
|
+
return actual;
|
|
1814
|
+
}
|
|
1815
|
+
else {
|
|
1816
|
+
return undefined;
|
|
1817
|
+
}
|
|
1818
|
+
},
|
|
1215
1819
|
/**
|
|
1216
1820
|
* Checks that a value is _not_ a string. Returns the value if the check passes, otherwise
|
|
1217
1821
|
* `undefined`.
|
|
@@ -1231,7 +1835,14 @@ export const runtimeTypeGuards = {
|
|
|
1231
1835
|
* @see
|
|
1232
1836
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1233
1837
|
*/
|
|
1234
|
-
isNotString
|
|
1838
|
+
isNotString(actual) {
|
|
1839
|
+
if (typeof actual === 'string') {
|
|
1840
|
+
return undefined;
|
|
1841
|
+
}
|
|
1842
|
+
else {
|
|
1843
|
+
return actual;
|
|
1844
|
+
}
|
|
1845
|
+
},
|
|
1235
1846
|
/**
|
|
1236
1847
|
* Checks that a value is _not_ a symbol. Returns the value if the check passes, otherwise
|
|
1237
1848
|
* `undefined`.
|
|
@@ -1251,12 +1862,14 @@ export const runtimeTypeGuards = {
|
|
|
1251
1862
|
* @see
|
|
1252
1863
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1253
1864
|
*/
|
|
1254
|
-
isNotSymbol
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1865
|
+
isNotSymbol(actual) {
|
|
1866
|
+
if (typeof actual === 'symbol') {
|
|
1867
|
+
return undefined;
|
|
1868
|
+
}
|
|
1869
|
+
else {
|
|
1870
|
+
return actual;
|
|
1871
|
+
}
|
|
1872
|
+
},
|
|
1260
1873
|
},
|
|
1261
1874
|
waitUntil: {
|
|
1262
1875
|
/**
|
|
@@ -1280,7 +1893,7 @@ export const runtimeTypeGuards = {
|
|
|
1280
1893
|
* @see
|
|
1281
1894
|
* - {@link waitUntil.isNotArray} : the opposite assertion.
|
|
1282
1895
|
*/
|
|
1283
|
-
isArray:
|
|
1896
|
+
isArray: createWaitUntil(assertions.isArray),
|
|
1284
1897
|
/**
|
|
1285
1898
|
* Repeatedly calls a callback until its output is a BigInt. Once the callback output
|
|
1286
1899
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1300,7 +1913,7 @@ export const runtimeTypeGuards = {
|
|
|
1300
1913
|
* @see
|
|
1301
1914
|
* - {@link waitUntil.isNotBigInt} : the opposite assertion.
|
|
1302
1915
|
*/
|
|
1303
|
-
isBigInt:
|
|
1916
|
+
isBigInt: createWaitUntil(assertions.isBigInt),
|
|
1304
1917
|
/**
|
|
1305
1918
|
* Repeatedly calls a callback until its output is a boolean. Once the callback output
|
|
1306
1919
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1320,7 +1933,7 @@ export const runtimeTypeGuards = {
|
|
|
1320
1933
|
* @see
|
|
1321
1934
|
* - {@link waitUntil.isNotBoolean} : the opposite assertion.
|
|
1322
1935
|
*/
|
|
1323
|
-
isBoolean:
|
|
1936
|
+
isBoolean: createWaitUntil(assertions.isBoolean),
|
|
1324
1937
|
/**
|
|
1325
1938
|
* Repeatedly calls a callback until its output is a function. Once the callback output
|
|
1326
1939
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1344,7 +1957,7 @@ export const runtimeTypeGuards = {
|
|
|
1344
1957
|
* @see
|
|
1345
1958
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1346
1959
|
*/
|
|
1347
|
-
isFunction:
|
|
1960
|
+
isFunction: createWaitUntil(assertions.isFunction),
|
|
1348
1961
|
/**
|
|
1349
1962
|
* Repeatedly calls a callback until its output is exactly `null`. Once the callback output
|
|
1350
1963
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1364,7 +1977,7 @@ export const runtimeTypeGuards = {
|
|
|
1364
1977
|
* @see
|
|
1365
1978
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1366
1979
|
*/
|
|
1367
|
-
isNull:
|
|
1980
|
+
isNull: createWaitUntil(assertions.isNull),
|
|
1368
1981
|
/**
|
|
1369
1982
|
* Repeatedly calls a callback until its output is a number. This excludes `NaN`. Once the
|
|
1370
1983
|
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1384,7 +1997,7 @@ export const runtimeTypeGuards = {
|
|
|
1384
1997
|
* @see
|
|
1385
1998
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1386
1999
|
*/
|
|
1387
|
-
isNumber:
|
|
2000
|
+
isNumber: createWaitUntil(assertions.isNumber),
|
|
1388
2001
|
/**
|
|
1389
2002
|
* Repeatedly calls a callback until its output is an object. This excludes arrays. Once the
|
|
1390
2003
|
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1406,7 +2019,7 @@ export const runtimeTypeGuards = {
|
|
|
1406
2019
|
* @see
|
|
1407
2020
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1408
2021
|
*/
|
|
1409
|
-
isObject:
|
|
2022
|
+
isObject: createWaitUntil(assertions.isObject),
|
|
1410
2023
|
/**
|
|
1411
2024
|
* Repeatedly calls a callback until its output is a string. Once the callback output
|
|
1412
2025
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1426,7 +2039,7 @@ export const runtimeTypeGuards = {
|
|
|
1426
2039
|
* @see
|
|
1427
2040
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1428
2041
|
*/
|
|
1429
|
-
isString:
|
|
2042
|
+
isString: createWaitUntil(assertions.isString),
|
|
1430
2043
|
/**
|
|
1431
2044
|
* Repeatedly calls a callback until its output is a symbol. Once the callback output
|
|
1432
2045
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1446,7 +2059,7 @@ export const runtimeTypeGuards = {
|
|
|
1446
2059
|
* @see
|
|
1447
2060
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1448
2061
|
*/
|
|
1449
|
-
isSymbol:
|
|
2062
|
+
isSymbol: createWaitUntil(assertions.isSymbol),
|
|
1450
2063
|
/**
|
|
1451
2064
|
* Repeatedly calls a callback until its output is exactly `undefined`. Once the callback
|
|
1452
2065
|
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1466,7 +2079,7 @@ export const runtimeTypeGuards = {
|
|
|
1466
2079
|
* @see
|
|
1467
2080
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1468
2081
|
*/
|
|
1469
|
-
isUndefined:
|
|
2082
|
+
isUndefined: createWaitUntil(assertions.isUndefined),
|
|
1470
2083
|
/**
|
|
1471
2084
|
* Repeatedly calls a callback until its output is _not_ an array. Once the callback output
|
|
1472
2085
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1488,7 +2101,7 @@ export const runtimeTypeGuards = {
|
|
|
1488
2101
|
* @see
|
|
1489
2102
|
* - {@link waitUntil.isArray} : the opposite assertion.
|
|
1490
2103
|
*/
|
|
1491
|
-
isNotArray:
|
|
2104
|
+
isNotArray: createWaitUntil(assertions.isNotArray),
|
|
1492
2105
|
/**
|
|
1493
2106
|
* Repeatedly calls a callback until its output is _not_ a BigInt. Once the callback output
|
|
1494
2107
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1508,7 +2121,7 @@ export const runtimeTypeGuards = {
|
|
|
1508
2121
|
* @see
|
|
1509
2122
|
* - {@link waitUntil.isBigInt} : the opposite assertion.
|
|
1510
2123
|
*/
|
|
1511
|
-
isNotBigInt:
|
|
2124
|
+
isNotBigInt: createWaitUntil(assertions.isNotBigInt),
|
|
1512
2125
|
/**
|
|
1513
2126
|
* Repeatedly calls a callback until its output is _not_ a boolean. Once the callback output
|
|
1514
2127
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1528,7 +2141,7 @@ export const runtimeTypeGuards = {
|
|
|
1528
2141
|
* @see
|
|
1529
2142
|
* - {@link waitUntil.isBoolean} : the opposite assertion.
|
|
1530
2143
|
*/
|
|
1531
|
-
isNotBoolean:
|
|
2144
|
+
isNotBoolean: createWaitUntil(assertions.isNotBoolean),
|
|
1532
2145
|
/**
|
|
1533
2146
|
* Repeatedly calls a callback until its output is _not_ a function. Once the callback
|
|
1534
2147
|
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1552,7 +2165,7 @@ export const runtimeTypeGuards = {
|
|
|
1552
2165
|
* @see
|
|
1553
2166
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1554
2167
|
*/
|
|
1555
|
-
isNotFunction:
|
|
2168
|
+
isNotFunction: createWaitUntil(assertions.isNotFunction),
|
|
1556
2169
|
/**
|
|
1557
2170
|
* Repeatedly calls a callback until its output is _not_ exactly `null`. Once the callback
|
|
1558
2171
|
* output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1572,7 +2185,7 @@ export const runtimeTypeGuards = {
|
|
|
1572
2185
|
* @see
|
|
1573
2186
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1574
2187
|
*/
|
|
1575
|
-
isNotNull:
|
|
2188
|
+
isNotNull: createWaitUntil(assertions.isNotNull),
|
|
1576
2189
|
/**
|
|
1577
2190
|
* Repeatedly calls a callback until its output is _not_ a number. This includes `NaN`. Once
|
|
1578
2191
|
* the callback output passes, it is returned. If the attempts time out, an error is
|
|
@@ -1593,7 +2206,7 @@ export const runtimeTypeGuards = {
|
|
|
1593
2206
|
* @see
|
|
1594
2207
|
* - {@link waitUntil.isNotFunction} : the opposite assertion.
|
|
1595
2208
|
*/
|
|
1596
|
-
isNotNumber:
|
|
2209
|
+
isNotNumber: createWaitUntil(assertions.isNotNumber),
|
|
1597
2210
|
/**
|
|
1598
2211
|
* Repeatedly calls a callback until its output is _not_ an object. This includes arrays.
|
|
1599
2212
|
* Once the callback output passes, it is returned. If the attempts time out, an error is
|
|
@@ -1616,7 +2229,7 @@ export const runtimeTypeGuards = {
|
|
|
1616
2229
|
* @see
|
|
1617
2230
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1618
2231
|
*/
|
|
1619
|
-
isNotObject:
|
|
2232
|
+
isNotObject: createWaitUntil(assertions.isNotObject),
|
|
1620
2233
|
/**
|
|
1621
2234
|
* Repeatedly calls a callback until its output is _not_ a string. Once the callback output
|
|
1622
2235
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1636,7 +2249,7 @@ export const runtimeTypeGuards = {
|
|
|
1636
2249
|
* @see
|
|
1637
2250
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1638
2251
|
*/
|
|
1639
|
-
isNotString:
|
|
2252
|
+
isNotString: createWaitUntil(assertions.isNotString),
|
|
1640
2253
|
/**
|
|
1641
2254
|
* Repeatedly calls a callback until its output is _not_ a symbol. Once the callback output
|
|
1642
2255
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1656,7 +2269,7 @@ export const runtimeTypeGuards = {
|
|
|
1656
2269
|
* @see
|
|
1657
2270
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1658
2271
|
*/
|
|
1659
|
-
isNotSymbol:
|
|
2272
|
+
isNotSymbol: createWaitUntil(assertions.isNotSymbol),
|
|
1660
2273
|
/**
|
|
1661
2274
|
* Repeatedly calls a callback until its output is _not_ exactly `undefined`. Once the
|
|
1662
2275
|
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1676,90 +2289,6 @@ export const runtimeTypeGuards = {
|
|
|
1676
2289
|
* @see
|
|
1677
2290
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1678
2291
|
*/
|
|
1679
|
-
isNotUndefined:
|
|
2292
|
+
isNotUndefined: createWaitUntil(assertions.isNotUndefined),
|
|
1680
2293
|
},
|
|
1681
2294
|
};
|
|
1682
|
-
/**
|
|
1683
|
-
* An enum representing the possible values returned by {@link getRuntimeType}. These values are
|
|
1684
|
-
* similar to the output of the built-in
|
|
1685
|
-
* [`typeof`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof) operator
|
|
1686
|
-
* except that this includes new types `array` and `null`, that `typeof` does not have, which are
|
|
1687
|
-
* both distinct from `object`.
|
|
1688
|
-
*
|
|
1689
|
-
* @category Assert : Util
|
|
1690
|
-
* @category Package : @augment-vir/assert
|
|
1691
|
-
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
1692
|
-
*/
|
|
1693
|
-
export var RuntimeType;
|
|
1694
|
-
(function (RuntimeType) {
|
|
1695
|
-
RuntimeType["String"] = "string";
|
|
1696
|
-
RuntimeType["Number"] = "number";
|
|
1697
|
-
RuntimeType["Bigint"] = "bigint";
|
|
1698
|
-
RuntimeType["Boolean"] = "boolean";
|
|
1699
|
-
RuntimeType["Symbol"] = "symbol";
|
|
1700
|
-
RuntimeType["Undefined"] = "undefined";
|
|
1701
|
-
RuntimeType["Object"] = "object";
|
|
1702
|
-
RuntimeType["Function"] = "function";
|
|
1703
|
-
/**
|
|
1704
|
-
* This is not included in {@link RuntimeType.Object}. (Compared to
|
|
1705
|
-
* [`typeof`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof)
|
|
1706
|
-
* which _does_ include `null` in the `'object'` type.)
|
|
1707
|
-
*/
|
|
1708
|
-
RuntimeType["Array"] = "array";
|
|
1709
|
-
/**
|
|
1710
|
-
* This is not included in {@link RuntimeType.Object}. (Compared to
|
|
1711
|
-
* [`typeof`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof)
|
|
1712
|
-
* which _does_ include `null` in the `'object'` type.)
|
|
1713
|
-
*/
|
|
1714
|
-
RuntimeType["Null"] = "null";
|
|
1715
|
-
})(RuntimeType || (RuntimeType = {}));
|
|
1716
|
-
/**
|
|
1717
|
-
* Determines the {@link RuntimeType} of a variable. This is similar to the built-in
|
|
1718
|
-
* [`typeof`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof) operator
|
|
1719
|
-
* except in the following ways:
|
|
1720
|
-
*
|
|
1721
|
-
* - This returns an enum value ({@link RuntimeType}) rather than just a string (though the enum values
|
|
1722
|
-
* are strings anyway).
|
|
1723
|
-
* - This includes new types `array` and `null`, that `typeof` does not have, which are both distinct
|
|
1724
|
-
* from `object`.
|
|
1725
|
-
*
|
|
1726
|
-
* @category Assert : Util
|
|
1727
|
-
* @category Package : @augment-vir/assert
|
|
1728
|
-
* @example
|
|
1729
|
-
*
|
|
1730
|
-
* ```ts
|
|
1731
|
-
* import {getRuntimeType} from '@augment-vir/assert';
|
|
1732
|
-
*
|
|
1733
|
-
* getRuntimeType(['a']); // RuntimeType.Array
|
|
1734
|
-
* getRuntimeType({a: 'a'}); // RuntimeType.Object
|
|
1735
|
-
* ```
|
|
1736
|
-
*
|
|
1737
|
-
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
1738
|
-
*/
|
|
1739
|
-
export function getRuntimeType(actual) {
|
|
1740
|
-
if (actual === null) {
|
|
1741
|
-
return RuntimeType.Null;
|
|
1742
|
-
}
|
|
1743
|
-
else if (Array.isArray(actual)) {
|
|
1744
|
-
return RuntimeType.Array;
|
|
1745
|
-
}
|
|
1746
|
-
else {
|
|
1747
|
-
return typeof actual;
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
/**
|
|
1751
|
-
* Asserts that the given actual matches the given test type. Note that an name for the actual must
|
|
1752
|
-
* be provided for error messaging purposes.
|
|
1753
|
-
*/
|
|
1754
|
-
function assertRuntimeType(actual, testType, failureMessage) {
|
|
1755
|
-
const actualType = getRuntimeType(actual);
|
|
1756
|
-
if (actualType !== testType) {
|
|
1757
|
-
throw new AssertionError(`'${stringify(actual)}' is '${actualType}', not '${testType}'.`, failureMessage);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
function assertNotRuntimeType(actual, testType, failureMessage) {
|
|
1761
|
-
const actualType = getRuntimeType(actual);
|
|
1762
|
-
if (actualType === testType) {
|
|
1763
|
-
throw new AssertionError(`'${stringify(actual)}' is '${actualType}'.`, failureMessage);
|
|
1764
|
-
}
|
|
1765
|
-
}
|