@augment-vir/assert 31.47.0 → 31.49.0
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/runtime-type.d.ts +274 -34
- package/dist/assertions/runtime-type.js +371 -34
- package/package.json +3 -3
|
@@ -95,7 +95,7 @@ export declare const runtimeTypeGuards: {
|
|
|
95
95
|
*
|
|
96
96
|
* @throws {@link AssertionError} If the assertion failed.
|
|
97
97
|
* @see
|
|
98
|
-
* - {@link assert.
|
|
98
|
+
* - {@link assert.isNotNull} : the opposite assertion.
|
|
99
99
|
*/
|
|
100
100
|
isNull(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is null;
|
|
101
101
|
/**
|
|
@@ -114,7 +114,7 @@ export declare const runtimeTypeGuards: {
|
|
|
114
114
|
*
|
|
115
115
|
* @throws {@link AssertionError} If the assertion failed.
|
|
116
116
|
* @see
|
|
117
|
-
* - {@link assert.
|
|
117
|
+
* - {@link assert.isNotNumber} : the opposite assertion.
|
|
118
118
|
*/
|
|
119
119
|
isNumber(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is number;
|
|
120
120
|
/**
|
|
@@ -133,9 +133,33 @@ export declare const runtimeTypeGuards: {
|
|
|
133
133
|
*
|
|
134
134
|
* @throws {@link AssertionError} If the assertion failed.
|
|
135
135
|
* @see
|
|
136
|
-
* - {@link assert.
|
|
136
|
+
* - {@link assert.isNotObject} : the opposite assertion.
|
|
137
137
|
*/
|
|
138
138
|
isObject(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is UnknownObject;
|
|
139
|
+
/**
|
|
140
|
+
* Asserts that a value is a plain object. This excludes arrays and class instances.
|
|
141
|
+
*
|
|
142
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
143
|
+
* that's impossible).
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* import {assert} from '@augment-vir/assert';
|
|
149
|
+
*
|
|
150
|
+
* assert.isPlainObject({}); // passes
|
|
151
|
+
* assert.isPlainObject({value: 'key'}); // passes
|
|
152
|
+
* assert.isPlainObject(null); // fails
|
|
153
|
+
* assert.isPlainObject(new RegExp()); // fails
|
|
154
|
+
* assert.isPlainObject(new Date()); // fails
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
158
|
+
* @see
|
|
159
|
+
* - {@link assert.isNotPlainObject} : the opposite assertion.
|
|
160
|
+
* - {@link assert.isObject} : a more generic object assertion.
|
|
161
|
+
*/
|
|
162
|
+
isPlainObject(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is UnknownObject;
|
|
139
163
|
/**
|
|
140
164
|
* Asserts that a value is a string.
|
|
141
165
|
*
|
|
@@ -152,7 +176,7 @@ export declare const runtimeTypeGuards: {
|
|
|
152
176
|
*
|
|
153
177
|
* @throws {@link AssertionError} If the assertion failed.
|
|
154
178
|
* @see
|
|
155
|
-
* - {@link assert.
|
|
179
|
+
* - {@link assert.isNotString} : the opposite assertion.
|
|
156
180
|
*/
|
|
157
181
|
isString(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is string;
|
|
158
182
|
/**
|
|
@@ -171,7 +195,7 @@ export declare const runtimeTypeGuards: {
|
|
|
171
195
|
*
|
|
172
196
|
* @throws {@link AssertionError} If the assertion failed.
|
|
173
197
|
* @see
|
|
174
|
-
* - {@link assert.
|
|
198
|
+
* - {@link assert.isNotSymbol} : the opposite assertion.
|
|
175
199
|
*/
|
|
176
200
|
isSymbol(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is symbol;
|
|
177
201
|
/**
|
|
@@ -190,7 +214,7 @@ export declare const runtimeTypeGuards: {
|
|
|
190
214
|
*
|
|
191
215
|
* @throws {@link AssertionError} If the assertion failed.
|
|
192
216
|
* @see
|
|
193
|
-
* - {@link assert.
|
|
217
|
+
* - {@link assert.isNotUndefined} : the opposite assertion.
|
|
194
218
|
*/
|
|
195
219
|
isUndefined(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is undefined;
|
|
196
220
|
/**
|
|
@@ -304,7 +328,7 @@ export declare const runtimeTypeGuards: {
|
|
|
304
328
|
*
|
|
305
329
|
* @throws {@link AssertionError} If the assertion failed.
|
|
306
330
|
* @see
|
|
307
|
-
* - {@link assert.
|
|
331
|
+
* - {@link assert.isNumber} : the opposite assertion.
|
|
308
332
|
*/
|
|
309
333
|
isNotNumber<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): asserts actual is Exclude<Actual, number>;
|
|
310
334
|
/**
|
|
@@ -326,6 +350,27 @@ export declare const runtimeTypeGuards: {
|
|
|
326
350
|
* - {@link assert.isFunction} : the opposite assertion.
|
|
327
351
|
*/
|
|
328
352
|
isNotObject<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): asserts actual is Exclude<Actual, UnknownObject>;
|
|
353
|
+
/**
|
|
354
|
+
* Asserts that a value is not a plain object. This includes arrays and class instances.
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
*
|
|
358
|
+
* ```ts
|
|
359
|
+
* import {assert} from '@augment-vir/assert';
|
|
360
|
+
*
|
|
361
|
+
* assert.isNotPlainObject({}); // fails
|
|
362
|
+
* assert.isNotPlainObject({value: 'key'}); // fails
|
|
363
|
+
* assert.isNotPlainObject(null); // passes
|
|
364
|
+
* assert.isNotPlainObject(new RegExp()); // passes
|
|
365
|
+
* assert.isNotPlainObject(new Date()); // passes
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
369
|
+
* @see
|
|
370
|
+
* - {@link assert.isPlainObject} : the opposite assertion.
|
|
371
|
+
* - {@link assert.isNotObject} : a more generic non-object assertion.
|
|
372
|
+
*/
|
|
373
|
+
isNotPlainObject(this: void, actual: unknown, failureMessage?: string | undefined): void;
|
|
329
374
|
/**
|
|
330
375
|
* Asserts that a value is _not_ a string.
|
|
331
376
|
*
|
|
@@ -472,7 +517,7 @@ export declare const runtimeTypeGuards: {
|
|
|
472
517
|
* ```
|
|
473
518
|
*
|
|
474
519
|
* @see
|
|
475
|
-
* - {@link check.
|
|
520
|
+
* - {@link check.isNotNull} : the opposite check.
|
|
476
521
|
*/
|
|
477
522
|
isNull<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, null>;
|
|
478
523
|
/**
|
|
@@ -490,7 +535,7 @@ export declare const runtimeTypeGuards: {
|
|
|
490
535
|
* ```
|
|
491
536
|
*
|
|
492
537
|
* @see
|
|
493
|
-
* - {@link check.
|
|
538
|
+
* - {@link check.isNotNumber} : the opposite check.
|
|
494
539
|
*/
|
|
495
540
|
isNumber<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, number>;
|
|
496
541
|
/**
|
|
@@ -508,9 +553,32 @@ export declare const runtimeTypeGuards: {
|
|
|
508
553
|
* ```
|
|
509
554
|
*
|
|
510
555
|
* @see
|
|
511
|
-
* - {@link check.
|
|
556
|
+
* - {@link check.isNotObject} : the opposite check.
|
|
512
557
|
*/
|
|
513
558
|
isObject<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, UnknownObject>;
|
|
559
|
+
/**
|
|
560
|
+
* Checks that a value is a plain object. This excludes arrays and class instances.
|
|
561
|
+
*
|
|
562
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
563
|
+
* that's impossible).
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
*
|
|
567
|
+
* ```ts
|
|
568
|
+
* import {check} from '@augment-vir/assert';
|
|
569
|
+
*
|
|
570
|
+
* check.isPlainObject({}); // returns `true`
|
|
571
|
+
* check.isPlainObject({value: 'key'}); // returns `true`
|
|
572
|
+
* check.isPlainObject(null); // returns `false`
|
|
573
|
+
* check.isPlainObject(new RegExp()); // returns `false`
|
|
574
|
+
* check.isPlainObject(new Date()); // returns `false`
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @see
|
|
578
|
+
* - {@link check.isNotPlainObject} : the opposite check.
|
|
579
|
+
* - {@link check.isObject} : a more generic object check.
|
|
580
|
+
*/
|
|
581
|
+
isPlainObject<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, UnknownObject>;
|
|
514
582
|
/**
|
|
515
583
|
* Checks that a value is a string.
|
|
516
584
|
*
|
|
@@ -526,7 +594,7 @@ export declare const runtimeTypeGuards: {
|
|
|
526
594
|
* ```
|
|
527
595
|
*
|
|
528
596
|
* @see
|
|
529
|
-
* - {@link check.
|
|
597
|
+
* - {@link check.isNotString} : the opposite check.
|
|
530
598
|
*/
|
|
531
599
|
isString<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, string>;
|
|
532
600
|
/**
|
|
@@ -544,7 +612,7 @@ export declare const runtimeTypeGuards: {
|
|
|
544
612
|
* ```
|
|
545
613
|
*
|
|
546
614
|
* @see
|
|
547
|
-
* - {@link check.
|
|
615
|
+
* - {@link check.isNotSymbol} : the opposite check.
|
|
548
616
|
*/
|
|
549
617
|
isSymbol<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, symbol>;
|
|
550
618
|
/**
|
|
@@ -562,7 +630,7 @@ export declare const runtimeTypeGuards: {
|
|
|
562
630
|
* ```
|
|
563
631
|
*
|
|
564
632
|
* @see
|
|
565
|
-
* - {@link check.
|
|
633
|
+
* - {@link check.isNotUndefined} : the opposite check.
|
|
566
634
|
*/
|
|
567
635
|
isUndefined<Actual>(this: void, actual: Actual): actual is NarrowToActual<Actual, undefined>;
|
|
568
636
|
/**
|
|
@@ -670,7 +738,7 @@ export declare const runtimeTypeGuards: {
|
|
|
670
738
|
* ```
|
|
671
739
|
*
|
|
672
740
|
* @see
|
|
673
|
-
* - {@link check.
|
|
741
|
+
* - {@link check.isNumber} : the opposite check.
|
|
674
742
|
*/
|
|
675
743
|
isNotNumber<Actual>(this: void, actual: Actual): actual is Exclude<Actual, number>;
|
|
676
744
|
/**
|
|
@@ -691,6 +759,26 @@ export declare const runtimeTypeGuards: {
|
|
|
691
759
|
* - {@link check.isFunction} : the opposite check.
|
|
692
760
|
*/
|
|
693
761
|
isNotObject<Actual>(this: void, actual: Actual): actual is Exclude<Actual, UnknownObject>;
|
|
762
|
+
/**
|
|
763
|
+
* Checks that a value is not a plain object. This includes arrays and class instances.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
*
|
|
767
|
+
* ```ts
|
|
768
|
+
* import {assert} from '@augment-vir/assert';
|
|
769
|
+
*
|
|
770
|
+
* check.isNotPlainObject({}); // returns `false`
|
|
771
|
+
* check.isNotPlainObject({value: 'key'}); // returns `false`
|
|
772
|
+
* check.isNotPlainObject(null); // returns `true`
|
|
773
|
+
* check.isNotPlainObject(new RegExp()); // returns `true`
|
|
774
|
+
* check.isNotPlainObject(new Date()); // returns `true`
|
|
775
|
+
* ```
|
|
776
|
+
*
|
|
777
|
+
* @see
|
|
778
|
+
* - {@link check.isPlainObject} : the opposite check.
|
|
779
|
+
* - {@link check.isNotObject} : a more generic non-object check.
|
|
780
|
+
*/
|
|
781
|
+
isNotPlainObject(this: void, actual: unknown): boolean;
|
|
694
782
|
/**
|
|
695
783
|
* Checks that a value is _not_ a string.
|
|
696
784
|
*
|
|
@@ -844,7 +932,7 @@ export declare const runtimeTypeGuards: {
|
|
|
844
932
|
* @returns The value if the assertion passes.
|
|
845
933
|
* @throws {@link AssertionError} If the assertion failed.
|
|
846
934
|
* @see
|
|
847
|
-
* - {@link assertWrap.
|
|
935
|
+
* - {@link assertWrap.isNotNull} : the opposite assertion.
|
|
848
936
|
*/
|
|
849
937
|
isNull<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, null>;
|
|
850
938
|
/**
|
|
@@ -865,7 +953,7 @@ export declare const runtimeTypeGuards: {
|
|
|
865
953
|
* @returns The value if the assertion passes.
|
|
866
954
|
* @throws {@link AssertionError} If the assertion failed.
|
|
867
955
|
* @see
|
|
868
|
-
* - {@link assertWrap.
|
|
956
|
+
* - {@link assertWrap.isNotNumber} : the opposite assertion.
|
|
869
957
|
*/
|
|
870
958
|
isNumber<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, number>;
|
|
871
959
|
/**
|
|
@@ -886,9 +974,34 @@ export declare const runtimeTypeGuards: {
|
|
|
886
974
|
* @returns The value if the assertion passes.
|
|
887
975
|
* @throws {@link AssertionError} If the assertion failed.
|
|
888
976
|
* @see
|
|
889
|
-
* - {@link assertWrap.
|
|
977
|
+
* - {@link assertWrap.isNotObject} : the opposite assertion.
|
|
890
978
|
*/
|
|
891
979
|
isObject<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, UnknownObject>;
|
|
980
|
+
/**
|
|
981
|
+
* Asserts that a value is a plain object. This excludes arrays and class instances. Returns
|
|
982
|
+
* the value if the assertion passes.
|
|
983
|
+
*
|
|
984
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
985
|
+
* that's impossible).
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
*
|
|
989
|
+
* ```ts
|
|
990
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
991
|
+
*
|
|
992
|
+
* assertWrap.isPlainObject({}); // returns `{}`
|
|
993
|
+
* assertWrap.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
994
|
+
* assertWrap.isPlainObject(null); // throws an error
|
|
995
|
+
* assertWrap.isPlainObject(new RegExp()); // throws an error
|
|
996
|
+
* assertWrap.isPlainObject(new Date()); // throws an error
|
|
997
|
+
* ```
|
|
998
|
+
*
|
|
999
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1000
|
+
* @see
|
|
1001
|
+
* - {@link assertWrap.isNotPlainObject} : the opposite assertion.
|
|
1002
|
+
* - {@link assertWrap.isObject} : a more generic object assertion.
|
|
1003
|
+
*/
|
|
1004
|
+
isPlainObject<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, UnknownObject>;
|
|
892
1005
|
/**
|
|
893
1006
|
* Asserts that a value is a string. Returns the value if the assertion passes.
|
|
894
1007
|
*
|
|
@@ -906,7 +1019,7 @@ export declare const runtimeTypeGuards: {
|
|
|
906
1019
|
* @returns The value if the assertion passes.
|
|
907
1020
|
* @throws {@link AssertionError} If the assertion failed.
|
|
908
1021
|
* @see
|
|
909
|
-
* - {@link assertWrap.
|
|
1022
|
+
* - {@link assertWrap.isNotString} : the opposite assertion.
|
|
910
1023
|
*/
|
|
911
1024
|
isString<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, string>;
|
|
912
1025
|
/**
|
|
@@ -935,7 +1048,7 @@ export declare const runtimeTypeGuards: {
|
|
|
935
1048
|
* @returns The value if the assertion passes.
|
|
936
1049
|
* @throws {@link AssertionError} If the assertion failed.
|
|
937
1050
|
* @see
|
|
938
|
-
* - {@link assertWrap.
|
|
1051
|
+
* - {@link assertWrap.isNotSymbol} : the opposite assertion.
|
|
939
1052
|
*/
|
|
940
1053
|
isSymbol<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, symbol>;
|
|
941
1054
|
/**
|
|
@@ -955,7 +1068,7 @@ export declare const runtimeTypeGuards: {
|
|
|
955
1068
|
* @returns The value if the assertion passes.
|
|
956
1069
|
* @throws {@link AssertionError} If the assertion failed.
|
|
957
1070
|
* @see
|
|
958
|
-
* - {@link assertWrap.
|
|
1071
|
+
* - {@link assertWrap.isNotUndefined} : the opposite assertion.
|
|
959
1072
|
*/
|
|
960
1073
|
isUndefined<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, undefined>;
|
|
961
1074
|
/**
|
|
@@ -1076,7 +1189,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1076
1189
|
* @returns The value if the assertion passes.
|
|
1077
1190
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1078
1191
|
* @see
|
|
1079
|
-
* - {@link assertWrap.
|
|
1192
|
+
* - {@link assertWrap.isNumber} : the opposite assertion.
|
|
1080
1193
|
*/
|
|
1081
1194
|
isNotNumber<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): Exclude<Actual, number>;
|
|
1082
1195
|
/**
|
|
@@ -1100,6 +1213,31 @@ export declare const runtimeTypeGuards: {
|
|
|
1100
1213
|
* - {@link assertWrap.isFunction} : the opposite assertion.
|
|
1101
1214
|
*/
|
|
1102
1215
|
isNotObject<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): Exclude<Actual, UnknownObject>;
|
|
1216
|
+
/**
|
|
1217
|
+
* Asserts that a value is a not plain object. This includes arrays and class instances.
|
|
1218
|
+
* Returns the value if the assertion passes.
|
|
1219
|
+
*
|
|
1220
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1221
|
+
* that's impossible).
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
*
|
|
1225
|
+
* ```ts
|
|
1226
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
1227
|
+
*
|
|
1228
|
+
* assertWrap.isNotPlainObject({}); // throws an error
|
|
1229
|
+
* assertWrap.isNotPlainObject({value: 'key'}); // throws an error
|
|
1230
|
+
* assertWrap.isNotPlainObject(null); // returns `null`
|
|
1231
|
+
* assertWrap.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
1232
|
+
* assertWrap.isNotPlainObject(new Date()); // returns the Date instance
|
|
1233
|
+
* ```
|
|
1234
|
+
*
|
|
1235
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1236
|
+
* @see
|
|
1237
|
+
* - {@link assertWrap.isPlainObject} : the opposite assertion.
|
|
1238
|
+
* - {@link assertWrap.isObject} : a more generic non-object assertion.
|
|
1239
|
+
*/
|
|
1240
|
+
isNotPlainObject(this: void, actual: unknown, failureMessage?: string | undefined): unknown;
|
|
1103
1241
|
/**
|
|
1104
1242
|
* Asserts that a value is _not_ a string. Returns the value if the assertion passes.
|
|
1105
1243
|
*
|
|
@@ -1260,7 +1398,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1260
1398
|
*
|
|
1261
1399
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1262
1400
|
* @see
|
|
1263
|
-
* - {@link checkWrap.
|
|
1401
|
+
* - {@link checkWrap.isNotNull} : the opposite check.
|
|
1264
1402
|
*/
|
|
1265
1403
|
isNull<Actual>(this: void, actual: Actual): NarrowToActual<Actual, null> | undefined;
|
|
1266
1404
|
/**
|
|
@@ -1280,7 +1418,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1280
1418
|
*
|
|
1281
1419
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1282
1420
|
* @see
|
|
1283
|
-
* - {@link checkWrap.
|
|
1421
|
+
* - {@link checkWrap.isNotNumber} : the opposite check.
|
|
1284
1422
|
*/
|
|
1285
1423
|
isNumber<Actual>(this: void, actual: Actual): NarrowToActual<Actual, number> | undefined;
|
|
1286
1424
|
/**
|
|
@@ -1300,9 +1438,34 @@ export declare const runtimeTypeGuards: {
|
|
|
1300
1438
|
*
|
|
1301
1439
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1302
1440
|
* @see
|
|
1303
|
-
* - {@link checkWrap.
|
|
1441
|
+
* - {@link checkWrap.isNotObject} : the opposite check.
|
|
1304
1442
|
*/
|
|
1305
1443
|
isObject<Actual>(this: void, actual: Actual): NarrowToActual<Actual, UnknownObject> | undefined;
|
|
1444
|
+
/**
|
|
1445
|
+
* Checks that a value is a plain object. This excludes arrays and class instances. Returns
|
|
1446
|
+
* the value if the check passes, otherwise `undefined`.
|
|
1447
|
+
*
|
|
1448
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1449
|
+
* that's impossible).
|
|
1450
|
+
*
|
|
1451
|
+
* @example
|
|
1452
|
+
*
|
|
1453
|
+
* ```ts
|
|
1454
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1455
|
+
*
|
|
1456
|
+
* checkWrap.isPlainObject({}); // returns `{}`
|
|
1457
|
+
* checkWrap.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
1458
|
+
* checkWrap.isPlainObject(null); // returns `undefined`
|
|
1459
|
+
* checkWrap.isPlainObject(new RegExp()); // returns `undefined`
|
|
1460
|
+
* checkWrap.isPlainObject(new Date()); // returns `undefined`
|
|
1461
|
+
* ```
|
|
1462
|
+
*
|
|
1463
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1464
|
+
* @see
|
|
1465
|
+
* - {@link checkWrap.isNotPlainObject} : the opposite check.
|
|
1466
|
+
* - {@link checkWrap.isObject} : a more generic object check.
|
|
1467
|
+
*/
|
|
1468
|
+
isPlainObject<Actual>(this: void, actual: Actual): NarrowToActual<Actual, UnknownObject> | undefined;
|
|
1306
1469
|
/**
|
|
1307
1470
|
* Checks that a value is a string. Returns the value if the check passes, otherwise
|
|
1308
1471
|
* `undefined`.
|
|
@@ -1320,7 +1483,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1320
1483
|
*
|
|
1321
1484
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1322
1485
|
* @see
|
|
1323
|
-
* - {@link checkWrap.
|
|
1486
|
+
* - {@link checkWrap.isNotString} : the opposite check.
|
|
1324
1487
|
*/
|
|
1325
1488
|
isString<Actual>(this: void, actual: Actual): NarrowToActual<Actual, string> | undefined;
|
|
1326
1489
|
/**
|
|
@@ -1340,7 +1503,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1340
1503
|
*
|
|
1341
1504
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1342
1505
|
* @see
|
|
1343
|
-
* - {@link checkWrap.
|
|
1506
|
+
* - {@link checkWrap.isNotSymbol} : the opposite check.
|
|
1344
1507
|
*/
|
|
1345
1508
|
isSymbol<Actual>(this: void, actual: Actual): NarrowToActual<Actual, symbol> | undefined;
|
|
1346
1509
|
/**
|
|
@@ -1460,7 +1623,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1460
1623
|
*
|
|
1461
1624
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1462
1625
|
* @see
|
|
1463
|
-
* - {@link checkWrap.
|
|
1626
|
+
* - {@link checkWrap.isNumber} : the opposite check.
|
|
1464
1627
|
*/
|
|
1465
1628
|
isNotNumber<Actual>(this: void, actual: Actual): Exclude<Actual, number> | undefined;
|
|
1466
1629
|
/**
|
|
@@ -1483,6 +1646,31 @@ export declare const runtimeTypeGuards: {
|
|
|
1483
1646
|
* - {@link checkWrap.isFunction} : the opposite check.
|
|
1484
1647
|
*/
|
|
1485
1648
|
isNotObject<Actual>(this: void, actual: Actual): Exclude<Actual, UnknownObject> | undefined;
|
|
1649
|
+
/**
|
|
1650
|
+
* Checks that a value is not a plain object. This includes arrays and class instances.
|
|
1651
|
+
* Returns the value if the check passes, otherwise `undefined`.
|
|
1652
|
+
*
|
|
1653
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1654
|
+
* that's impossible).
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
*
|
|
1658
|
+
* ```ts
|
|
1659
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1660
|
+
*
|
|
1661
|
+
* checkWrap.isNotPlainObject({}); // returns `undefined`
|
|
1662
|
+
* checkWrap.isNotPlainObject({value: 'key'}); // returns `undefined`
|
|
1663
|
+
* checkWrap.isNotPlainObject(null); // returns `null`
|
|
1664
|
+
* checkWrap.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
1665
|
+
* checkWrap.isNotPlainObject(new Date()); // returns the Date instance
|
|
1666
|
+
* ```
|
|
1667
|
+
*
|
|
1668
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1669
|
+
* @see
|
|
1670
|
+
* - {@link checkWrap.isPlainObject} : the opposite check.
|
|
1671
|
+
* - {@link checkWrap.isNotObject} : a more generic non-object check.
|
|
1672
|
+
*/
|
|
1673
|
+
isNotPlainObject(this: void, actual: unknown): unknown;
|
|
1486
1674
|
/**
|
|
1487
1675
|
* Checks that a value is _not_ a string. Returns the value if the check passes, otherwise
|
|
1488
1676
|
* `undefined`.
|
|
@@ -1628,7 +1816,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1628
1816
|
*
|
|
1629
1817
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1630
1818
|
* @see
|
|
1631
|
-
* - {@link waitUntil.
|
|
1819
|
+
* - {@link waitUntil.isNotNull} : the opposite assertion.
|
|
1632
1820
|
*/
|
|
1633
1821
|
isNull: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, null>>;
|
|
1634
1822
|
/**
|
|
@@ -1648,7 +1836,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1648
1836
|
*
|
|
1649
1837
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1650
1838
|
* @see
|
|
1651
|
-
* - {@link waitUntil.
|
|
1839
|
+
* - {@link waitUntil.isNotNumber} : the opposite assertion.
|
|
1652
1840
|
*/
|
|
1653
1841
|
isNumber: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, number>>;
|
|
1654
1842
|
/**
|
|
@@ -1670,9 +1858,35 @@ export declare const runtimeTypeGuards: {
|
|
|
1670
1858
|
*
|
|
1671
1859
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1672
1860
|
* @see
|
|
1673
|
-
* - {@link waitUntil.
|
|
1861
|
+
* - {@link waitUntil.isNotObject} : the opposite assertion.
|
|
1674
1862
|
*/
|
|
1675
1863
|
isObject: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, UnknownObject>>;
|
|
1864
|
+
/**
|
|
1865
|
+
* Repeatedly calls a callback until its output is a plain object. This excludes arrays and
|
|
1866
|
+
* class instances. Once the callback output passes, it is returned. If the attempts time
|
|
1867
|
+
* out, an error is thrown.
|
|
1868
|
+
*
|
|
1869
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1870
|
+
* that's impossible).
|
|
1871
|
+
*
|
|
1872
|
+
* @example
|
|
1873
|
+
*
|
|
1874
|
+
* ```ts
|
|
1875
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
1876
|
+
*
|
|
1877
|
+
* waitUntil.isPlainObject({}); // returns `{}`
|
|
1878
|
+
* waitUntil.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
1879
|
+
* waitUntil.isPlainObject(null); // throws an error
|
|
1880
|
+
* waitUntil.isPlainObject(new RegExp()); // throws an error
|
|
1881
|
+
* waitUntil.isPlainObject(new Date()); // throws an error
|
|
1882
|
+
* ```
|
|
1883
|
+
*
|
|
1884
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1885
|
+
* @see
|
|
1886
|
+
* - {@link waitUntil.isNotPlainObject} : the opposite assertion.
|
|
1887
|
+
* - {@link waitUntil.isObject} : a more generic object assertion.
|
|
1888
|
+
*/
|
|
1889
|
+
isPlainObject: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, UnknownObject>>;
|
|
1676
1890
|
/**
|
|
1677
1891
|
* Repeatedly calls a callback until its output is a string. Once the callback output
|
|
1678
1892
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -1690,7 +1904,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1690
1904
|
*
|
|
1691
1905
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1692
1906
|
* @see
|
|
1693
|
-
* - {@link waitUntil.
|
|
1907
|
+
* - {@link waitUntil.isNotString} : the opposite assertion.
|
|
1694
1908
|
*/
|
|
1695
1909
|
isString: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, string>>;
|
|
1696
1910
|
/**
|
|
@@ -1710,7 +1924,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1710
1924
|
*
|
|
1711
1925
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1712
1926
|
* @see
|
|
1713
|
-
* - {@link waitUntil.
|
|
1927
|
+
* - {@link waitUntil.isNotSymbol} : the opposite assertion.
|
|
1714
1928
|
*/
|
|
1715
1929
|
isSymbol: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, symbol>>;
|
|
1716
1930
|
/**
|
|
@@ -1730,7 +1944,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1730
1944
|
*
|
|
1731
1945
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1732
1946
|
* @see
|
|
1733
|
-
* - {@link waitUntil.
|
|
1947
|
+
* - {@link waitUntil.isNotUndefined} : the opposite assertion.
|
|
1734
1948
|
*/
|
|
1735
1949
|
isUndefined: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, undefined>>;
|
|
1736
1950
|
/**
|
|
@@ -1857,7 +2071,7 @@ export declare const runtimeTypeGuards: {
|
|
|
1857
2071
|
*
|
|
1858
2072
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1859
2073
|
* @see
|
|
1860
|
-
* - {@link waitUntil.
|
|
2074
|
+
* - {@link waitUntil.isNumber} : the opposite assertion.
|
|
1861
2075
|
*/
|
|
1862
2076
|
isNotNumber: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, number>>;
|
|
1863
2077
|
/**
|
|
@@ -1883,6 +2097,32 @@ export declare const runtimeTypeGuards: {
|
|
|
1883
2097
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
1884
2098
|
*/
|
|
1885
2099
|
isNotObject: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, UnknownObject>>;
|
|
2100
|
+
/**
|
|
2101
|
+
* Repeatedly calls a callback until its output is not a plain object. This includes arrays
|
|
2102
|
+
* and class instances. Once the callback output passes, it is returned. If the attempts
|
|
2103
|
+
* time out, an error is thrown.
|
|
2104
|
+
*
|
|
2105
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
2106
|
+
* that's impossible).
|
|
2107
|
+
*
|
|
2108
|
+
* @example
|
|
2109
|
+
*
|
|
2110
|
+
* ```ts
|
|
2111
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
2112
|
+
*
|
|
2113
|
+
* waitUntil.isNotPlainObject({}); // throws an error
|
|
2114
|
+
* waitUntil.isNotPlainObject({value: 'key'}); // throws an error
|
|
2115
|
+
* waitUntil.isNotPlainObject(null); // returns `null`
|
|
2116
|
+
* waitUntil.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
2117
|
+
* waitUntil.isNotPlainObject(new Date()); // returns the Date instance
|
|
2118
|
+
* ```
|
|
2119
|
+
*
|
|
2120
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
2121
|
+
* @see
|
|
2122
|
+
* - {@link waitUntil.isPlainObject} : the opposite assertion.
|
|
2123
|
+
* - {@link waitUntil.isNotObject} : a more generic non-object assertion.
|
|
2124
|
+
*/
|
|
2125
|
+
isNotPlainObject: <Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, UnknownObject>>;
|
|
1886
2126
|
/**
|
|
1887
2127
|
* Repeatedly calls a callback until its output is _not_ a string. Once the callback output
|
|
1888
2128
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -110,7 +110,7 @@ const assertions = {
|
|
|
110
110
|
*
|
|
111
111
|
* @throws {@link AssertionError} If the assertion failed.
|
|
112
112
|
* @see
|
|
113
|
-
* - {@link assert.
|
|
113
|
+
* - {@link assert.isNotNull} : the opposite assertion.
|
|
114
114
|
*/
|
|
115
115
|
isNull(actual, failureMessage) {
|
|
116
116
|
if (actual !== null) {
|
|
@@ -133,7 +133,7 @@ const assertions = {
|
|
|
133
133
|
*
|
|
134
134
|
* @throws {@link AssertionError} If the assertion failed.
|
|
135
135
|
* @see
|
|
136
|
-
* - {@link assert.
|
|
136
|
+
* - {@link assert.isNotNumber} : the opposite assertion.
|
|
137
137
|
*/
|
|
138
138
|
isNumber(actual, failureMessage) {
|
|
139
139
|
if (typeof actual !== 'number' || isNaN(actual)) {
|
|
@@ -156,13 +156,48 @@ const assertions = {
|
|
|
156
156
|
*
|
|
157
157
|
* @throws {@link AssertionError} If the assertion failed.
|
|
158
158
|
* @see
|
|
159
|
-
* - {@link assert.
|
|
159
|
+
* - {@link assert.isNotObject} : the opposite assertion.
|
|
160
160
|
*/
|
|
161
161
|
isObject(actual, failureMessage) {
|
|
162
162
|
if (Array.isArray(actual) || typeof actual !== 'object' || !actual) {
|
|
163
163
|
throw new AssertionError(`'${stringify(actual)}' is not a non-null object.`, failureMessage);
|
|
164
164
|
}
|
|
165
165
|
},
|
|
166
|
+
/**
|
|
167
|
+
* Asserts that a value is a plain object. This excludes arrays and class instances.
|
|
168
|
+
*
|
|
169
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
170
|
+
* that's impossible).
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* import {assert} from '@augment-vir/assert';
|
|
176
|
+
*
|
|
177
|
+
* assert.isPlainObject({}); // passes
|
|
178
|
+
* assert.isPlainObject({value: 'key'}); // passes
|
|
179
|
+
* assert.isPlainObject(null); // fails
|
|
180
|
+
* assert.isPlainObject(new RegExp()); // fails
|
|
181
|
+
* assert.isPlainObject(new Date()); // fails
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
185
|
+
* @see
|
|
186
|
+
* - {@link assert.isNotPlainObject} : the opposite assertion.
|
|
187
|
+
* - {@link assert.isObject} : a more generic object assertion.
|
|
188
|
+
*/
|
|
189
|
+
isPlainObject(actual, failureMessage) {
|
|
190
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
191
|
+
if (typeof actual !== 'object' ||
|
|
192
|
+
actual == undefined ||
|
|
193
|
+
!((prototype == undefined ||
|
|
194
|
+
prototype === Object.prototype ||
|
|
195
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
196
|
+
!(Symbol.toStringTag in actual) &&
|
|
197
|
+
!(Symbol.iterator in actual))) {
|
|
198
|
+
throw new AssertionError(`'${stringify(actual)}' is not a plain object.`, failureMessage);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
166
201
|
/**
|
|
167
202
|
* Asserts that a value is a string.
|
|
168
203
|
*
|
|
@@ -179,7 +214,7 @@ const assertions = {
|
|
|
179
214
|
*
|
|
180
215
|
* @throws {@link AssertionError} If the assertion failed.
|
|
181
216
|
* @see
|
|
182
|
-
* - {@link assert.
|
|
217
|
+
* - {@link assert.isNotString} : the opposite assertion.
|
|
183
218
|
*/
|
|
184
219
|
isString(actual, failureMessage) {
|
|
185
220
|
if (typeof actual !== 'string') {
|
|
@@ -202,7 +237,7 @@ const assertions = {
|
|
|
202
237
|
*
|
|
203
238
|
* @throws {@link AssertionError} If the assertion failed.
|
|
204
239
|
* @see
|
|
205
|
-
* - {@link assert.
|
|
240
|
+
* - {@link assert.isNotSymbol} : the opposite assertion.
|
|
206
241
|
*/
|
|
207
242
|
isSymbol(actual, failureMessage) {
|
|
208
243
|
if (typeof actual !== 'symbol') {
|
|
@@ -225,7 +260,7 @@ const assertions = {
|
|
|
225
260
|
*
|
|
226
261
|
* @throws {@link AssertionError} If the assertion failed.
|
|
227
262
|
* @see
|
|
228
|
-
* - {@link assert.
|
|
263
|
+
* - {@link assert.isNotUndefined} : the opposite assertion.
|
|
229
264
|
*/
|
|
230
265
|
isUndefined(actual, failureMessage) {
|
|
231
266
|
if (typeof actual !== 'undefined') {
|
|
@@ -363,7 +398,7 @@ const assertions = {
|
|
|
363
398
|
*
|
|
364
399
|
* @throws {@link AssertionError} If the assertion failed.
|
|
365
400
|
* @see
|
|
366
|
-
* - {@link assert.
|
|
401
|
+
* - {@link assert.isNumber} : the opposite assertion.
|
|
367
402
|
*/
|
|
368
403
|
isNotNumber(actual, failureMessage) {
|
|
369
404
|
if (typeof actual === 'number') {
|
|
@@ -393,6 +428,39 @@ const assertions = {
|
|
|
393
428
|
throw new AssertionError(`'${stringify(actual)}' is a non-null object.`, failureMessage);
|
|
394
429
|
}
|
|
395
430
|
},
|
|
431
|
+
/**
|
|
432
|
+
* Asserts that a value is not a plain object. This includes arrays and class instances.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* import {assert} from '@augment-vir/assert';
|
|
438
|
+
*
|
|
439
|
+
* assert.isNotPlainObject({}); // fails
|
|
440
|
+
* assert.isNotPlainObject({value: 'key'}); // fails
|
|
441
|
+
* assert.isNotPlainObject(null); // passes
|
|
442
|
+
* assert.isNotPlainObject(new RegExp()); // passes
|
|
443
|
+
* assert.isNotPlainObject(new Date()); // passes
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
447
|
+
* @see
|
|
448
|
+
* - {@link assert.isPlainObject} : the opposite assertion.
|
|
449
|
+
* - {@link assert.isNotObject} : a more generic non-object assertion.
|
|
450
|
+
*/
|
|
451
|
+
isNotPlainObject(actual, failureMessage) {
|
|
452
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
453
|
+
if (typeof actual !== 'object' ||
|
|
454
|
+
actual == undefined ||
|
|
455
|
+
!((prototype == undefined ||
|
|
456
|
+
prototype === Object.prototype ||
|
|
457
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
458
|
+
!(Symbol.toStringTag in actual) &&
|
|
459
|
+
!(Symbol.iterator in actual))) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
throw new AssertionError(`'${stringify(actual)}' is a plain object.`, failureMessage);
|
|
463
|
+
},
|
|
396
464
|
/**
|
|
397
465
|
* Asserts that a value is _not_ a string.
|
|
398
466
|
*
|
|
@@ -561,7 +629,7 @@ export const runtimeTypeGuards = {
|
|
|
561
629
|
* ```
|
|
562
630
|
*
|
|
563
631
|
* @see
|
|
564
|
-
* - {@link check.
|
|
632
|
+
* - {@link check.isNotNull} : the opposite check.
|
|
565
633
|
*/
|
|
566
634
|
isNull(actual) {
|
|
567
635
|
return actual === null;
|
|
@@ -581,7 +649,7 @@ export const runtimeTypeGuards = {
|
|
|
581
649
|
* ```
|
|
582
650
|
*
|
|
583
651
|
* @see
|
|
584
|
-
* - {@link check.
|
|
652
|
+
* - {@link check.isNotNumber} : the opposite check.
|
|
585
653
|
*/
|
|
586
654
|
isNumber(actual) {
|
|
587
655
|
return typeof actual === 'number';
|
|
@@ -601,11 +669,44 @@ export const runtimeTypeGuards = {
|
|
|
601
669
|
* ```
|
|
602
670
|
*
|
|
603
671
|
* @see
|
|
604
|
-
* - {@link check.
|
|
672
|
+
* - {@link check.isNotObject} : the opposite check.
|
|
605
673
|
*/
|
|
606
674
|
isObject(actual) {
|
|
607
675
|
return !Array.isArray(actual) && typeof actual === 'object' && !!actual;
|
|
608
676
|
},
|
|
677
|
+
/**
|
|
678
|
+
* Checks that a value is a plain object. This excludes arrays and class instances.
|
|
679
|
+
*
|
|
680
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
681
|
+
* that's impossible).
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
*
|
|
685
|
+
* ```ts
|
|
686
|
+
* import {check} from '@augment-vir/assert';
|
|
687
|
+
*
|
|
688
|
+
* check.isPlainObject({}); // returns `true`
|
|
689
|
+
* check.isPlainObject({value: 'key'}); // returns `true`
|
|
690
|
+
* check.isPlainObject(null); // returns `false`
|
|
691
|
+
* check.isPlainObject(new RegExp()); // returns `false`
|
|
692
|
+
* check.isPlainObject(new Date()); // returns `false`
|
|
693
|
+
* ```
|
|
694
|
+
*
|
|
695
|
+
* @see
|
|
696
|
+
* - {@link check.isNotPlainObject} : the opposite check.
|
|
697
|
+
* - {@link check.isObject} : a more generic object check.
|
|
698
|
+
*/
|
|
699
|
+
isPlainObject(actual) {
|
|
700
|
+
if (typeof actual !== 'object' || actual == undefined) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
704
|
+
return ((prototype == undefined ||
|
|
705
|
+
prototype === Object.prototype ||
|
|
706
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
707
|
+
!(Symbol.toStringTag in actual) &&
|
|
708
|
+
!(Symbol.iterator in actual));
|
|
709
|
+
},
|
|
609
710
|
/**
|
|
610
711
|
* Checks that a value is a string.
|
|
611
712
|
*
|
|
@@ -621,7 +722,7 @@ export const runtimeTypeGuards = {
|
|
|
621
722
|
* ```
|
|
622
723
|
*
|
|
623
724
|
* @see
|
|
624
|
-
* - {@link check.
|
|
725
|
+
* - {@link check.isNotString} : the opposite check.
|
|
625
726
|
*/
|
|
626
727
|
isString(actual) {
|
|
627
728
|
return typeof actual === 'string';
|
|
@@ -641,7 +742,7 @@ export const runtimeTypeGuards = {
|
|
|
641
742
|
* ```
|
|
642
743
|
*
|
|
643
744
|
* @see
|
|
644
|
-
* - {@link check.
|
|
745
|
+
* - {@link check.isNotSymbol} : the opposite check.
|
|
645
746
|
*/
|
|
646
747
|
isSymbol(actual) {
|
|
647
748
|
return typeof actual === 'symbol';
|
|
@@ -661,7 +762,7 @@ export const runtimeTypeGuards = {
|
|
|
661
762
|
* ```
|
|
662
763
|
*
|
|
663
764
|
* @see
|
|
664
|
-
* - {@link check.
|
|
765
|
+
* - {@link check.isNotUndefined} : the opposite check.
|
|
665
766
|
*/
|
|
666
767
|
isUndefined(actual) {
|
|
667
768
|
return actual === undefined;
|
|
@@ -781,7 +882,7 @@ export const runtimeTypeGuards = {
|
|
|
781
882
|
* ```
|
|
782
883
|
*
|
|
783
884
|
* @see
|
|
784
|
-
* - {@link check.
|
|
885
|
+
* - {@link check.isNumber} : the opposite check.
|
|
785
886
|
*/
|
|
786
887
|
isNotNumber(actual) {
|
|
787
888
|
return typeof actual !== 'number';
|
|
@@ -806,6 +907,36 @@ export const runtimeTypeGuards = {
|
|
|
806
907
|
isNotObject(actual) {
|
|
807
908
|
return Array.isArray(actual) || typeof actual !== 'object' || !actual;
|
|
808
909
|
},
|
|
910
|
+
/**
|
|
911
|
+
* Checks that a value is not a plain object. This includes arrays and class instances.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
*
|
|
915
|
+
* ```ts
|
|
916
|
+
* import {assert} from '@augment-vir/assert';
|
|
917
|
+
*
|
|
918
|
+
* check.isNotPlainObject({}); // returns `false`
|
|
919
|
+
* check.isNotPlainObject({value: 'key'}); // returns `false`
|
|
920
|
+
* check.isNotPlainObject(null); // returns `true`
|
|
921
|
+
* check.isNotPlainObject(new RegExp()); // returns `true`
|
|
922
|
+
* check.isNotPlainObject(new Date()); // returns `true`
|
|
923
|
+
* ```
|
|
924
|
+
*
|
|
925
|
+
* @see
|
|
926
|
+
* - {@link check.isPlainObject} : the opposite check.
|
|
927
|
+
* - {@link check.isNotObject} : a more generic non-object check.
|
|
928
|
+
*/
|
|
929
|
+
isNotPlainObject(actual) {
|
|
930
|
+
if (typeof actual !== 'object' || actual == undefined) {
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
934
|
+
return !((prototype == undefined ||
|
|
935
|
+
prototype === Object.prototype ||
|
|
936
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
937
|
+
!(Symbol.toStringTag in actual) &&
|
|
938
|
+
!(Symbol.iterator in actual));
|
|
939
|
+
},
|
|
809
940
|
/**
|
|
810
941
|
* Checks that a value is _not_ a string.
|
|
811
942
|
*
|
|
@@ -985,7 +1116,7 @@ export const runtimeTypeGuards = {
|
|
|
985
1116
|
* @returns The value if the assertion passes.
|
|
986
1117
|
* @throws {@link AssertionError} If the assertion failed.
|
|
987
1118
|
* @see
|
|
988
|
-
* - {@link assertWrap.
|
|
1119
|
+
* - {@link assertWrap.isNotNull} : the opposite assertion.
|
|
989
1120
|
*/
|
|
990
1121
|
isNull(actual, failureMessage) {
|
|
991
1122
|
if (actual !== null) {
|
|
@@ -1011,7 +1142,7 @@ export const runtimeTypeGuards = {
|
|
|
1011
1142
|
* @returns The value if the assertion passes.
|
|
1012
1143
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1013
1144
|
* @see
|
|
1014
|
-
* - {@link assertWrap.
|
|
1145
|
+
* - {@link assertWrap.isNotNumber} : the opposite assertion.
|
|
1015
1146
|
*/
|
|
1016
1147
|
isNumber(actual, failureMessage) {
|
|
1017
1148
|
if (typeof actual !== 'number' || isNaN(actual)) {
|
|
@@ -1037,7 +1168,7 @@ export const runtimeTypeGuards = {
|
|
|
1037
1168
|
* @returns The value if the assertion passes.
|
|
1038
1169
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1039
1170
|
* @see
|
|
1040
|
-
* - {@link assertWrap.
|
|
1171
|
+
* - {@link assertWrap.isNotObject} : the opposite assertion.
|
|
1041
1172
|
*/
|
|
1042
1173
|
isObject(actual, failureMessage) {
|
|
1043
1174
|
if (Array.isArray(actual) || typeof actual !== 'object' || !actual) {
|
|
@@ -1045,6 +1176,43 @@ export const runtimeTypeGuards = {
|
|
|
1045
1176
|
}
|
|
1046
1177
|
return actual;
|
|
1047
1178
|
},
|
|
1179
|
+
/**
|
|
1180
|
+
* Asserts that a value is a plain object. This excludes arrays and class instances. Returns
|
|
1181
|
+
* the value if the assertion passes.
|
|
1182
|
+
*
|
|
1183
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1184
|
+
* that's impossible).
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
*
|
|
1188
|
+
* ```ts
|
|
1189
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
1190
|
+
*
|
|
1191
|
+
* assertWrap.isPlainObject({}); // returns `{}`
|
|
1192
|
+
* assertWrap.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
1193
|
+
* assertWrap.isPlainObject(null); // throws an error
|
|
1194
|
+
* assertWrap.isPlainObject(new RegExp()); // throws an error
|
|
1195
|
+
* assertWrap.isPlainObject(new Date()); // throws an error
|
|
1196
|
+
* ```
|
|
1197
|
+
*
|
|
1198
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1199
|
+
* @see
|
|
1200
|
+
* - {@link assertWrap.isNotPlainObject} : the opposite assertion.
|
|
1201
|
+
* - {@link assertWrap.isObject} : a more generic object assertion.
|
|
1202
|
+
*/
|
|
1203
|
+
isPlainObject(actual, failureMessage) {
|
|
1204
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
1205
|
+
if (typeof actual !== 'object' ||
|
|
1206
|
+
actual == undefined ||
|
|
1207
|
+
!((prototype == undefined ||
|
|
1208
|
+
prototype === Object.prototype ||
|
|
1209
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
1210
|
+
!(Symbol.toStringTag in actual) &&
|
|
1211
|
+
!(Symbol.iterator in actual))) {
|
|
1212
|
+
throw new AssertionError(`'${stringify(actual)}' is not a plain object.`, failureMessage);
|
|
1213
|
+
}
|
|
1214
|
+
return actual;
|
|
1215
|
+
},
|
|
1048
1216
|
/**
|
|
1049
1217
|
* Asserts that a value is a string. Returns the value if the assertion passes.
|
|
1050
1218
|
*
|
|
@@ -1062,7 +1230,7 @@ export const runtimeTypeGuards = {
|
|
|
1062
1230
|
* @returns The value if the assertion passes.
|
|
1063
1231
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1064
1232
|
* @see
|
|
1065
|
-
* - {@link assertWrap.
|
|
1233
|
+
* - {@link assertWrap.isNotString} : the opposite assertion.
|
|
1066
1234
|
*/
|
|
1067
1235
|
isString(actual, failureMessage) {
|
|
1068
1236
|
if (typeof actual !== 'string') {
|
|
@@ -1096,7 +1264,7 @@ export const runtimeTypeGuards = {
|
|
|
1096
1264
|
* @returns The value if the assertion passes.
|
|
1097
1265
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1098
1266
|
* @see
|
|
1099
|
-
* - {@link assertWrap.
|
|
1267
|
+
* - {@link assertWrap.isNotSymbol} : the opposite assertion.
|
|
1100
1268
|
*/
|
|
1101
1269
|
isSymbol(actual, failureMessage) {
|
|
1102
1270
|
if (typeof actual !== 'symbol') {
|
|
@@ -1121,7 +1289,7 @@ export const runtimeTypeGuards = {
|
|
|
1121
1289
|
* @returns The value if the assertion passes.
|
|
1122
1290
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1123
1291
|
* @see
|
|
1124
|
-
* - {@link assertWrap.
|
|
1292
|
+
* - {@link assertWrap.isNotUndefined} : the opposite assertion.
|
|
1125
1293
|
*/
|
|
1126
1294
|
isUndefined(actual, failureMessage) {
|
|
1127
1295
|
if (typeof actual !== 'undefined') {
|
|
@@ -1272,7 +1440,7 @@ export const runtimeTypeGuards = {
|
|
|
1272
1440
|
* @returns The value if the assertion passes.
|
|
1273
1441
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1274
1442
|
* @see
|
|
1275
|
-
* - {@link assertWrap.
|
|
1443
|
+
* - {@link assertWrap.isNumber} : the opposite assertion.
|
|
1276
1444
|
*/
|
|
1277
1445
|
isNotNumber(actual, failureMessage) {
|
|
1278
1446
|
if (typeof actual === 'number') {
|
|
@@ -1306,6 +1474,43 @@ export const runtimeTypeGuards = {
|
|
|
1306
1474
|
}
|
|
1307
1475
|
return actual;
|
|
1308
1476
|
},
|
|
1477
|
+
/**
|
|
1478
|
+
* Asserts that a value is a not plain object. This includes arrays and class instances.
|
|
1479
|
+
* Returns the value if the assertion passes.
|
|
1480
|
+
*
|
|
1481
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1482
|
+
* that's impossible).
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
*
|
|
1486
|
+
* ```ts
|
|
1487
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
1488
|
+
*
|
|
1489
|
+
* assertWrap.isNotPlainObject({}); // throws an error
|
|
1490
|
+
* assertWrap.isNotPlainObject({value: 'key'}); // throws an error
|
|
1491
|
+
* assertWrap.isNotPlainObject(null); // returns `null`
|
|
1492
|
+
* assertWrap.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
1493
|
+
* assertWrap.isNotPlainObject(new Date()); // returns the Date instance
|
|
1494
|
+
* ```
|
|
1495
|
+
*
|
|
1496
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
1497
|
+
* @see
|
|
1498
|
+
* - {@link assertWrap.isPlainObject} : the opposite assertion.
|
|
1499
|
+
* - {@link assertWrap.isObject} : a more generic non-object assertion.
|
|
1500
|
+
*/
|
|
1501
|
+
isNotPlainObject(actual, failureMessage) {
|
|
1502
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
1503
|
+
if (typeof actual !== 'object' ||
|
|
1504
|
+
actual == undefined ||
|
|
1505
|
+
!((prototype == undefined ||
|
|
1506
|
+
prototype === Object.prototype ||
|
|
1507
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
1508
|
+
!(Symbol.toStringTag in actual) &&
|
|
1509
|
+
!(Symbol.iterator in actual))) {
|
|
1510
|
+
return actual;
|
|
1511
|
+
}
|
|
1512
|
+
throw new AssertionError(`'${stringify(actual)}' is a plain object.`, failureMessage);
|
|
1513
|
+
},
|
|
1309
1514
|
/**
|
|
1310
1515
|
* Asserts that a value is _not_ a string. Returns the value if the assertion passes.
|
|
1311
1516
|
*
|
|
@@ -1509,7 +1714,7 @@ export const runtimeTypeGuards = {
|
|
|
1509
1714
|
*
|
|
1510
1715
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1511
1716
|
* @see
|
|
1512
|
-
* - {@link checkWrap.
|
|
1717
|
+
* - {@link checkWrap.isNotNull} : the opposite check.
|
|
1513
1718
|
*/
|
|
1514
1719
|
isNull(actual) {
|
|
1515
1720
|
if (actual === null) {
|
|
@@ -1536,7 +1741,7 @@ export const runtimeTypeGuards = {
|
|
|
1536
1741
|
*
|
|
1537
1742
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1538
1743
|
* @see
|
|
1539
|
-
* - {@link checkWrap.
|
|
1744
|
+
* - {@link checkWrap.isNotNumber} : the opposite check.
|
|
1540
1745
|
*/
|
|
1541
1746
|
isNumber(actual) {
|
|
1542
1747
|
if (typeof actual === 'number') {
|
|
@@ -1563,7 +1768,7 @@ export const runtimeTypeGuards = {
|
|
|
1563
1768
|
*
|
|
1564
1769
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1565
1770
|
* @see
|
|
1566
|
-
* - {@link checkWrap.
|
|
1771
|
+
* - {@link checkWrap.isNotObject} : the opposite check.
|
|
1567
1772
|
*/
|
|
1568
1773
|
isObject(actual) {
|
|
1569
1774
|
if (!Array.isArray(actual) && typeof actual === 'object' && !!actual) {
|
|
@@ -1573,6 +1778,46 @@ export const runtimeTypeGuards = {
|
|
|
1573
1778
|
return undefined;
|
|
1574
1779
|
}
|
|
1575
1780
|
},
|
|
1781
|
+
/**
|
|
1782
|
+
* Checks that a value is a plain object. This excludes arrays and class instances. Returns
|
|
1783
|
+
* the value if the check passes, otherwise `undefined`.
|
|
1784
|
+
*
|
|
1785
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
1786
|
+
* that's impossible).
|
|
1787
|
+
*
|
|
1788
|
+
* @example
|
|
1789
|
+
*
|
|
1790
|
+
* ```ts
|
|
1791
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
1792
|
+
*
|
|
1793
|
+
* checkWrap.isPlainObject({}); // returns `{}`
|
|
1794
|
+
* checkWrap.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
1795
|
+
* checkWrap.isPlainObject(null); // returns `undefined`
|
|
1796
|
+
* checkWrap.isPlainObject(new RegExp()); // returns `undefined`
|
|
1797
|
+
* checkWrap.isPlainObject(new Date()); // returns `undefined`
|
|
1798
|
+
* ```
|
|
1799
|
+
*
|
|
1800
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1801
|
+
* @see
|
|
1802
|
+
* - {@link checkWrap.isNotPlainObject} : the opposite check.
|
|
1803
|
+
* - {@link checkWrap.isObject} : a more generic object check.
|
|
1804
|
+
*/
|
|
1805
|
+
isPlainObject(actual) {
|
|
1806
|
+
if (typeof actual !== 'object' || actual == undefined) {
|
|
1807
|
+
return undefined;
|
|
1808
|
+
}
|
|
1809
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
1810
|
+
if ((prototype == undefined ||
|
|
1811
|
+
prototype === Object.prototype ||
|
|
1812
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
1813
|
+
!(Symbol.toStringTag in actual) &&
|
|
1814
|
+
!(Symbol.iterator in actual)) {
|
|
1815
|
+
return actual;
|
|
1816
|
+
}
|
|
1817
|
+
else {
|
|
1818
|
+
return undefined;
|
|
1819
|
+
}
|
|
1820
|
+
},
|
|
1576
1821
|
/**
|
|
1577
1822
|
* Checks that a value is a string. Returns the value if the check passes, otherwise
|
|
1578
1823
|
* `undefined`.
|
|
@@ -1590,7 +1835,7 @@ export const runtimeTypeGuards = {
|
|
|
1590
1835
|
*
|
|
1591
1836
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1592
1837
|
* @see
|
|
1593
|
-
* - {@link checkWrap.
|
|
1838
|
+
* - {@link checkWrap.isNotString} : the opposite check.
|
|
1594
1839
|
*/
|
|
1595
1840
|
isString(actual) {
|
|
1596
1841
|
if (typeof actual === 'string') {
|
|
@@ -1617,7 +1862,7 @@ export const runtimeTypeGuards = {
|
|
|
1617
1862
|
*
|
|
1618
1863
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1619
1864
|
* @see
|
|
1620
|
-
* - {@link checkWrap.
|
|
1865
|
+
* - {@link checkWrap.isNotSymbol} : the opposite check.
|
|
1621
1866
|
*/
|
|
1622
1867
|
isSymbol(actual) {
|
|
1623
1868
|
if (typeof actual === 'symbol') {
|
|
@@ -1779,7 +2024,7 @@ export const runtimeTypeGuards = {
|
|
|
1779
2024
|
*
|
|
1780
2025
|
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
1781
2026
|
* @see
|
|
1782
|
-
* - {@link checkWrap.
|
|
2027
|
+
* - {@link checkWrap.isNumber} : the opposite check.
|
|
1783
2028
|
*/
|
|
1784
2029
|
isNotNumber(actual) {
|
|
1785
2030
|
if (typeof actual === 'number') {
|
|
@@ -1816,6 +2061,46 @@ export const runtimeTypeGuards = {
|
|
|
1816
2061
|
return undefined;
|
|
1817
2062
|
}
|
|
1818
2063
|
},
|
|
2064
|
+
/**
|
|
2065
|
+
* Checks that a value is not a plain object. This includes arrays and class instances.
|
|
2066
|
+
* Returns the value if the check passes, otherwise `undefined`.
|
|
2067
|
+
*
|
|
2068
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
2069
|
+
* that's impossible).
|
|
2070
|
+
*
|
|
2071
|
+
* @example
|
|
2072
|
+
*
|
|
2073
|
+
* ```ts
|
|
2074
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
2075
|
+
*
|
|
2076
|
+
* checkWrap.isNotPlainObject({}); // returns `undefined`
|
|
2077
|
+
* checkWrap.isNotPlainObject({value: 'key'}); // returns `undefined`
|
|
2078
|
+
* checkWrap.isNotPlainObject(null); // returns `null`
|
|
2079
|
+
* checkWrap.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
2080
|
+
* checkWrap.isNotPlainObject(new Date()); // returns the Date instance
|
|
2081
|
+
* ```
|
|
2082
|
+
*
|
|
2083
|
+
* @returns The value if the check passes. Otherwise, `undefined`.
|
|
2084
|
+
* @see
|
|
2085
|
+
* - {@link checkWrap.isPlainObject} : the opposite check.
|
|
2086
|
+
* - {@link checkWrap.isNotObject} : a more generic non-object check.
|
|
2087
|
+
*/
|
|
2088
|
+
isNotPlainObject(actual) {
|
|
2089
|
+
if (typeof actual !== 'object' || actual == undefined) {
|
|
2090
|
+
return actual;
|
|
2091
|
+
}
|
|
2092
|
+
const prototype = Object.getPrototypeOf(actual);
|
|
2093
|
+
if ((prototype == undefined ||
|
|
2094
|
+
prototype === Object.prototype ||
|
|
2095
|
+
Object.getPrototypeOf(prototype) == undefined) &&
|
|
2096
|
+
!(Symbol.toStringTag in actual) &&
|
|
2097
|
+
!(Symbol.iterator in actual)) {
|
|
2098
|
+
return undefined;
|
|
2099
|
+
}
|
|
2100
|
+
else {
|
|
2101
|
+
return actual;
|
|
2102
|
+
}
|
|
2103
|
+
},
|
|
1819
2104
|
/**
|
|
1820
2105
|
* Checks that a value is _not_ a string. Returns the value if the check passes, otherwise
|
|
1821
2106
|
* `undefined`.
|
|
@@ -1975,7 +2260,7 @@ export const runtimeTypeGuards = {
|
|
|
1975
2260
|
*
|
|
1976
2261
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1977
2262
|
* @see
|
|
1978
|
-
* - {@link waitUntil.
|
|
2263
|
+
* - {@link waitUntil.isNotNull} : the opposite assertion.
|
|
1979
2264
|
*/
|
|
1980
2265
|
isNull: createWaitUntil(assertions.isNull),
|
|
1981
2266
|
/**
|
|
@@ -1995,7 +2280,7 @@ export const runtimeTypeGuards = {
|
|
|
1995
2280
|
*
|
|
1996
2281
|
* @throws {@link AssertionError} If the assertion failed.
|
|
1997
2282
|
* @see
|
|
1998
|
-
* - {@link waitUntil.
|
|
2283
|
+
* - {@link waitUntil.isNotNumber} : the opposite assertion.
|
|
1999
2284
|
*/
|
|
2000
2285
|
isNumber: createWaitUntil(assertions.isNumber),
|
|
2001
2286
|
/**
|
|
@@ -2017,9 +2302,35 @@ export const runtimeTypeGuards = {
|
|
|
2017
2302
|
*
|
|
2018
2303
|
* @throws {@link AssertionError} If the assertion failed.
|
|
2019
2304
|
* @see
|
|
2020
|
-
* - {@link waitUntil.
|
|
2305
|
+
* - {@link waitUntil.isNotObject} : the opposite assertion.
|
|
2021
2306
|
*/
|
|
2022
2307
|
isObject: createWaitUntil(assertions.isObject),
|
|
2308
|
+
/**
|
|
2309
|
+
* Repeatedly calls a callback until its output is a plain object. This excludes arrays and
|
|
2310
|
+
* class instances. Once the callback output passes, it is returned. If the attempts time
|
|
2311
|
+
* out, an error is thrown.
|
|
2312
|
+
*
|
|
2313
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
2314
|
+
* that's impossible).
|
|
2315
|
+
*
|
|
2316
|
+
* @example
|
|
2317
|
+
*
|
|
2318
|
+
* ```ts
|
|
2319
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
2320
|
+
*
|
|
2321
|
+
* waitUntil.isPlainObject({}); // returns `{}`
|
|
2322
|
+
* waitUntil.isPlainObject({value: 'key'}); // returns `{value: 'key'}`
|
|
2323
|
+
* waitUntil.isPlainObject(null); // throws an error
|
|
2324
|
+
* waitUntil.isPlainObject(new RegExp()); // throws an error
|
|
2325
|
+
* waitUntil.isPlainObject(new Date()); // throws an error
|
|
2326
|
+
* ```
|
|
2327
|
+
*
|
|
2328
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
2329
|
+
* @see
|
|
2330
|
+
* - {@link waitUntil.isNotPlainObject} : the opposite assertion.
|
|
2331
|
+
* - {@link waitUntil.isObject} : a more generic object assertion.
|
|
2332
|
+
*/
|
|
2333
|
+
isPlainObject: createWaitUntil(assertions.isPlainObject),
|
|
2023
2334
|
/**
|
|
2024
2335
|
* Repeatedly calls a callback until its output is a string. Once the callback output
|
|
2025
2336
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
|
@@ -2037,7 +2348,7 @@ export const runtimeTypeGuards = {
|
|
|
2037
2348
|
*
|
|
2038
2349
|
* @throws {@link AssertionError} If the assertion failed.
|
|
2039
2350
|
* @see
|
|
2040
|
-
* - {@link waitUntil.
|
|
2351
|
+
* - {@link waitUntil.isNotString} : the opposite assertion.
|
|
2041
2352
|
*/
|
|
2042
2353
|
isString: createWaitUntil(assertions.isString),
|
|
2043
2354
|
/**
|
|
@@ -2057,7 +2368,7 @@ export const runtimeTypeGuards = {
|
|
|
2057
2368
|
*
|
|
2058
2369
|
* @throws {@link AssertionError} If the assertion failed.
|
|
2059
2370
|
* @see
|
|
2060
|
-
* - {@link waitUntil.
|
|
2371
|
+
* - {@link waitUntil.isNotSymbol} : the opposite assertion.
|
|
2061
2372
|
*/
|
|
2062
2373
|
isSymbol: createWaitUntil(assertions.isSymbol),
|
|
2063
2374
|
/**
|
|
@@ -2077,7 +2388,7 @@ export const runtimeTypeGuards = {
|
|
|
2077
2388
|
*
|
|
2078
2389
|
* @throws {@link AssertionError} If the assertion failed.
|
|
2079
2390
|
* @see
|
|
2080
|
-
* - {@link waitUntil.
|
|
2391
|
+
* - {@link waitUntil.isNotUndefined} : the opposite assertion.
|
|
2081
2392
|
*/
|
|
2082
2393
|
isUndefined: createWaitUntil(assertions.isUndefined),
|
|
2083
2394
|
/**
|
|
@@ -2204,7 +2515,7 @@ export const runtimeTypeGuards = {
|
|
|
2204
2515
|
*
|
|
2205
2516
|
* @throws {@link AssertionError} If the assertion failed.
|
|
2206
2517
|
* @see
|
|
2207
|
-
* - {@link waitUntil.
|
|
2518
|
+
* - {@link waitUntil.isNumber} : the opposite assertion.
|
|
2208
2519
|
*/
|
|
2209
2520
|
isNotNumber: createWaitUntil(assertions.isNotNumber),
|
|
2210
2521
|
/**
|
|
@@ -2230,6 +2541,32 @@ export const runtimeTypeGuards = {
|
|
|
2230
2541
|
* - {@link waitUntil.isFunction} : the opposite assertion.
|
|
2231
2542
|
*/
|
|
2232
2543
|
isNotObject: createWaitUntil(assertions.isNotObject),
|
|
2544
|
+
/**
|
|
2545
|
+
* Repeatedly calls a callback until its output is not a plain object. This includes arrays
|
|
2546
|
+
* and class instances. Once the callback output passes, it is returned. If the attempts
|
|
2547
|
+
* time out, an error is thrown.
|
|
2548
|
+
*
|
|
2549
|
+
* Type guards the value but does not exclude class instances from the type guard (because
|
|
2550
|
+
* that's impossible).
|
|
2551
|
+
*
|
|
2552
|
+
* @example
|
|
2553
|
+
*
|
|
2554
|
+
* ```ts
|
|
2555
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
2556
|
+
*
|
|
2557
|
+
* waitUntil.isNotPlainObject({}); // throws an error
|
|
2558
|
+
* waitUntil.isNotPlainObject({value: 'key'}); // throws an error
|
|
2559
|
+
* waitUntil.isNotPlainObject(null); // returns `null`
|
|
2560
|
+
* waitUntil.isNotPlainObject(new RegExp()); // returns the RegExp instance
|
|
2561
|
+
* waitUntil.isNotPlainObject(new Date()); // returns the Date instance
|
|
2562
|
+
* ```
|
|
2563
|
+
*
|
|
2564
|
+
* @throws {@link AssertionError} If the assertion failed.
|
|
2565
|
+
* @see
|
|
2566
|
+
* - {@link waitUntil.isPlainObject} : the opposite assertion.
|
|
2567
|
+
* - {@link waitUntil.isNotObject} : a more generic non-object assertion.
|
|
2568
|
+
*/
|
|
2569
|
+
isNotPlainObject: createWaitUntil(assertions.isNotPlainObject),
|
|
2233
2570
|
/**
|
|
2234
2571
|
* Repeatedly calls a callback until its output is _not_ a string. Once the callback output
|
|
2235
2572
|
* passes, it is returned. If the attempts time out, an error is thrown.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/assert",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.49.0",
|
|
4
4
|
"description": "A collection of assertions for test and production code alike.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"test:update": "npm test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@augment-vir/core": "^31.
|
|
45
|
+
"@augment-vir/core": "^31.49.0",
|
|
46
46
|
"@date-vir/duration": "^8.0.0",
|
|
47
47
|
"deep-eql": "^5.0.2",
|
|
48
48
|
"expect-type": "^1.2.2",
|
|
49
|
-
"type-fest": "^5.
|
|
49
|
+
"type-fest": "^5.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/deep-eql": "^4.0.2",
|