@augment-vir/assert 30.0.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/assertions/boolean.d.ts +97 -0
- package/dist/assertions/boolean.js +47 -0
- package/dist/assertions/boundary.d.ts +83 -0
- package/dist/assertions/boundary.js +104 -0
- package/dist/assertions/enum.d.ts +38 -0
- package/dist/assertions/enum.js +42 -0
- package/dist/assertions/equality/entry-equality.d.ts +40 -0
- package/dist/assertions/equality/entry-equality.js +56 -0
- package/dist/assertions/equality/json-equality.d.ts +42 -0
- package/dist/assertions/equality/json-equality.js +75 -0
- package/dist/assertions/equality/simple-equality.d.ts +85 -0
- package/dist/assertions/equality/simple-equality.js +61 -0
- package/dist/assertions/equality/ts-type-equality.d.ts +42 -0
- package/dist/assertions/equality/ts-type-equality.js +18 -0
- package/dist/assertions/extendable-assertions.d.ts +762 -0
- package/dist/assertions/extendable-assertions.js +108 -0
- package/dist/assertions/http.d.ts +36 -0
- package/dist/assertions/http.js +41 -0
- package/dist/assertions/instance.d.ts +43 -0
- package/dist/assertions/instance.js +41 -0
- package/dist/assertions/keys.d.ts +90 -0
- package/dist/assertions/keys.js +111 -0
- package/dist/assertions/length.d.ts +56 -0
- package/dist/assertions/length.js +68 -0
- package/dist/assertions/nullish.d.ts +43 -0
- package/dist/assertions/nullish.js +42 -0
- package/dist/assertions/numeric.d.ts +69 -0
- package/dist/assertions/numeric.js +60 -0
- package/dist/assertions/output.d.ts +83 -0
- package/dist/assertions/output.example.d.ts +1 -0
- package/dist/assertions/output.example.js +13 -0
- package/dist/assertions/output.js +173 -0
- package/dist/assertions/primitive.d.ts +58 -0
- package/dist/assertions/primitive.js +62 -0
- package/dist/assertions/promise.d.ts +65 -0
- package/dist/assertions/promise.js +69 -0
- package/dist/assertions/regexp.d.ts +19 -0
- package/dist/assertions/regexp.js +18 -0
- package/dist/assertions/runtime-type.d.ts +274 -0
- package/dist/assertions/runtime-type.example.d.ts +1 -0
- package/dist/assertions/runtime-type.example.js +3 -0
- package/dist/assertions/runtime-type.js +242 -0
- package/dist/assertions/throws.d.ts +109 -0
- package/dist/assertions/throws.example.d.ts +1 -0
- package/dist/assertions/throws.example.js +11 -0
- package/dist/assertions/throws.js +166 -0
- package/dist/assertions/uuid.d.ts +35 -0
- package/dist/assertions/uuid.js +33 -0
- package/dist/assertions/values.d.ts +106 -0
- package/dist/assertions/values.js +113 -0
- package/dist/augments/assertion-exports.d.ts +5 -0
- package/dist/augments/assertion-exports.js +1 -0
- package/dist/augments/assertion.error.d.ts +23 -0
- package/dist/augments/assertion.error.example.d.ts +1 -0
- package/dist/augments/assertion.error.example.js +3 -0
- package/dist/augments/assertion.error.js +26 -0
- package/dist/augments/guards/assert-wrap.d.ts +244 -0
- package/dist/augments/guards/assert-wrap.example.d.ts +1 -0
- package/dist/augments/guards/assert-wrap.example.js +9 -0
- package/dist/augments/guards/assert-wrap.js +32 -0
- package/dist/augments/guards/assert.d.ts +177 -0
- package/dist/augments/guards/assert.example.d.ts +1 -0
- package/dist/augments/guards/assert.example.js +4 -0
- package/dist/augments/guards/assert.js +32 -0
- package/dist/augments/guards/check-wrap.d.ts +247 -0
- package/dist/augments/guards/check-wrap.example.d.ts +1 -0
- package/dist/augments/guards/check-wrap.example.js +9 -0
- package/dist/augments/guards/check-wrap.js +34 -0
- package/dist/augments/guards/check.d.ts +229 -0
- package/dist/augments/guards/check.example.d.ts +1 -0
- package/dist/augments/guards/check.example.js +5 -0
- package/dist/augments/guards/check.js +21 -0
- package/dist/augments/guards/wait-until.d.ts +262 -0
- package/dist/augments/guards/wait-until.example.d.ts +1 -0
- package/dist/augments/guards/wait-until.example.js +13 -0
- package/dist/augments/guards/wait-until.js +34 -0
- package/dist/augments/if-equals.d.ts +17 -0
- package/dist/augments/if-equals.js +1 -0
- package/dist/guard-types/assert-function.d.ts +2 -0
- package/dist/guard-types/assert-function.js +3 -0
- package/dist/guard-types/assert-wrap-function.d.ts +9 -0
- package/dist/guard-types/assert-wrap-function.js +14 -0
- package/dist/guard-types/check-function.d.ts +11 -0
- package/dist/guard-types/check-function.js +22 -0
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +9 -0
- package/dist/guard-types/check-wrap-wrapper-function.js +19 -0
- package/dist/guard-types/guard-group.d.ts +13 -0
- package/dist/guard-types/guard-group.js +3 -0
- package/dist/guard-types/guard-override.d.ts +4 -0
- package/dist/guard-types/guard-override.js +10 -0
- package/dist/guard-types/wait-until-function.d.ts +63 -0
- package/dist/guard-types/wait-until-function.js +95 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/test-timeout.mock.d.ts +3 -0
- package/dist/test-timeout.mock.js +8 -0
- package/package.json +54 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { booleanGuards } from './boolean.js';
|
|
2
|
+
import { boundaryGuards } from './boundary.js';
|
|
3
|
+
import { enumGuards } from './enum.js';
|
|
4
|
+
import { entryEqualityGuards } from './equality/entry-equality.js';
|
|
5
|
+
import { jsonEqualityGuards } from './equality/json-equality.js';
|
|
6
|
+
import { simpleEqualityGuards } from './equality/simple-equality.js';
|
|
7
|
+
import { httpGuards } from './http.js';
|
|
8
|
+
import { instanceGuards } from './instance.js';
|
|
9
|
+
import { keyGuards } from './keys.js';
|
|
10
|
+
import { lengthGuards } from './length.js';
|
|
11
|
+
import { nullishGuards } from './nullish.js';
|
|
12
|
+
import { numericGuards } from './numeric.js';
|
|
13
|
+
import { outputGuards } from './output.js';
|
|
14
|
+
import { primitiveGuards } from './primitive.js';
|
|
15
|
+
import { promiseGuards } from './promise.js';
|
|
16
|
+
import { regexpGuards } from './regexp.js';
|
|
17
|
+
import { runtimeTypeGuards } from './runtime-type.js';
|
|
18
|
+
import { throwGuards } from './throws.js';
|
|
19
|
+
import { uuidGuards } from './uuid.js';
|
|
20
|
+
import { valueGuards } from './values.js';
|
|
21
|
+
export const extendableAssertions = {
|
|
22
|
+
...booleanGuards.assertions,
|
|
23
|
+
...boundaryGuards.assertions,
|
|
24
|
+
...entryEqualityGuards.assertions,
|
|
25
|
+
...enumGuards.assertions,
|
|
26
|
+
...instanceGuards.assertions,
|
|
27
|
+
...jsonEqualityGuards.assertions,
|
|
28
|
+
...keyGuards.assertions,
|
|
29
|
+
...lengthGuards.assertions,
|
|
30
|
+
...nullishGuards.assertions,
|
|
31
|
+
...numericGuards.assertions,
|
|
32
|
+
...primitiveGuards.assertions,
|
|
33
|
+
...promiseGuards.assertions,
|
|
34
|
+
...regexpGuards.assertions,
|
|
35
|
+
...runtimeTypeGuards.assertions,
|
|
36
|
+
...simpleEqualityGuards.assertions,
|
|
37
|
+
...throwGuards.assertions,
|
|
38
|
+
...uuidGuards.assertions,
|
|
39
|
+
...valueGuards.assertions,
|
|
40
|
+
...httpGuards.assertions,
|
|
41
|
+
...outputGuards.assertions,
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* These overrides are required for more complex guards because TypeScript won't allow us to
|
|
45
|
+
* maintain function type parameters when mapping such functions.
|
|
46
|
+
*/
|
|
47
|
+
export const guardOverrides = [
|
|
48
|
+
booleanGuards,
|
|
49
|
+
boundaryGuards,
|
|
50
|
+
entryEqualityGuards,
|
|
51
|
+
enumGuards,
|
|
52
|
+
instanceGuards,
|
|
53
|
+
jsonEqualityGuards,
|
|
54
|
+
keyGuards,
|
|
55
|
+
lengthGuards,
|
|
56
|
+
nullishGuards,
|
|
57
|
+
numericGuards,
|
|
58
|
+
primitiveGuards,
|
|
59
|
+
promiseGuards,
|
|
60
|
+
regexpGuards,
|
|
61
|
+
runtimeTypeGuards,
|
|
62
|
+
simpleEqualityGuards,
|
|
63
|
+
throwGuards,
|
|
64
|
+
uuidGuards,
|
|
65
|
+
valueGuards,
|
|
66
|
+
httpGuards,
|
|
67
|
+
outputGuards,
|
|
68
|
+
];
|
|
69
|
+
export const checkOverrides = Object.assign({}, ...guardOverrides
|
|
70
|
+
.map((entry) => {
|
|
71
|
+
if ('checkOverrides' in entry) {
|
|
72
|
+
return entry.checkOverrides;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.filter((entry) => !!entry));
|
|
79
|
+
export const assertWrapOverrides = Object.assign({}, ...guardOverrides
|
|
80
|
+
.map((entry) => {
|
|
81
|
+
if ('assertWrapOverrides' in entry) {
|
|
82
|
+
return entry.assertWrapOverrides;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.filter((entry) => !!entry));
|
|
89
|
+
export const checkWrapOverrides = Object.assign({}, ...guardOverrides
|
|
90
|
+
.map((entry) => {
|
|
91
|
+
if ('checkWrapOverrides' in entry) {
|
|
92
|
+
return entry.checkWrapOverrides;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
.filter((entry) => !!entry));
|
|
99
|
+
export const waitUntilOverrides = Object.assign({}, ...guardOverrides
|
|
100
|
+
.map((entry) => {
|
|
101
|
+
if ('waitUntilOverrides' in entry) {
|
|
102
|
+
return entry.waitUntilOverrides;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
.filter((entry) => !!entry));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HttpStatus, type HttpStatusByCategory, type HttpStatusCategory, type MaybePromise, type NarrowToExpected } from '@augment-vir/core';
|
|
2
|
+
import type { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
3
|
+
declare function isHttpStatus(actual: unknown, failureMessage?: string | undefined): asserts actual is HttpStatus;
|
|
4
|
+
declare function isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined): asserts actual is NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
5
|
+
export declare const httpGuards: {
|
|
6
|
+
assertions: {
|
|
7
|
+
/**
|
|
8
|
+
* Checks that a value is a standardized HTTP status code. See {@link HttpStatus} for the
|
|
9
|
+
* statuses.
|
|
10
|
+
*
|
|
11
|
+
* Type guards the value.
|
|
12
|
+
*/
|
|
13
|
+
isHttpStatus: typeof isHttpStatus;
|
|
14
|
+
/**
|
|
15
|
+
* Checks that a value is a standardized HTTP status code within the given category of HTTP
|
|
16
|
+
* status codes. See {@link HttpStatus} for the statuses and {@link HttpStatusCategory} for the
|
|
17
|
+
* categories.
|
|
18
|
+
*
|
|
19
|
+
* Type guards the value.
|
|
20
|
+
*/
|
|
21
|
+
isHttpStatusCategory: typeof isHttpStatusCategory;
|
|
22
|
+
};
|
|
23
|
+
checkOverrides: {
|
|
24
|
+
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => actual is NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
25
|
+
};
|
|
26
|
+
assertWrapOverrides: {
|
|
27
|
+
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
28
|
+
};
|
|
29
|
+
checkWrapOverrides: {
|
|
30
|
+
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => NarrowToExpected<Actual, HttpStatusByCategory<Category>> | undefined;
|
|
31
|
+
};
|
|
32
|
+
waitUntilOverrides: {
|
|
33
|
+
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(category: Category, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, HttpStatusByCategory<Category>>>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HttpStatus, httpStatusByCategory, stringify, } from '@augment-vir/core';
|
|
2
|
+
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
+
import { autoGuard } from '../guard-types/guard-override.js';
|
|
4
|
+
import { isEnumValue } from './enum.js';
|
|
5
|
+
import { isIn } from './values.js';
|
|
6
|
+
function isHttpStatus(actual, failureMessage) {
|
|
7
|
+
try {
|
|
8
|
+
isEnumValue(actual, HttpStatus);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new AssertionError(`${stringify(actual)} is not a valid http status.`, failureMessage);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function isHttpStatusCategory(actual, category, failureMessage) {
|
|
15
|
+
try {
|
|
16
|
+
isEnumValue(actual, HttpStatus);
|
|
17
|
+
isIn(actual, httpStatusByCategory[category]);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new AssertionError(`${stringify(actual)} is not a '${category}' http status.`, failureMessage);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const assertions = {
|
|
24
|
+
isHttpStatus,
|
|
25
|
+
isHttpStatusCategory,
|
|
26
|
+
};
|
|
27
|
+
export const httpGuards = {
|
|
28
|
+
assertions,
|
|
29
|
+
checkOverrides: {
|
|
30
|
+
isHttpStatusCategory: autoGuard(),
|
|
31
|
+
},
|
|
32
|
+
assertWrapOverrides: {
|
|
33
|
+
isHttpStatusCategory: autoGuard(),
|
|
34
|
+
},
|
|
35
|
+
checkWrapOverrides: {
|
|
36
|
+
isHttpStatusCategory: autoGuard(),
|
|
37
|
+
},
|
|
38
|
+
waitUntilOverrides: {
|
|
39
|
+
isHttpStatusCategory: autoGuard(),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/core';
|
|
2
|
+
import { Constructor } from 'type-fest';
|
|
3
|
+
import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
4
|
+
/** Wraps the JavaScript built-in "instanceof" in a type guard assertion. */
|
|
5
|
+
declare function instanceOf<const Instance>(instance: unknown,
|
|
6
|
+
/** The constructor that the "instance" input will be checked against. */
|
|
7
|
+
constructor: Constructor<Instance>,
|
|
8
|
+
/** Message to include in error message if this assertion fails. */
|
|
9
|
+
failureMessage?: string | undefined): asserts instance is Instance;
|
|
10
|
+
declare function notInstanceOf<const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>, failureMessage?: string | undefined): asserts instance is Exclude<Actual, Instance>;
|
|
11
|
+
export declare const instanceGuards: {
|
|
12
|
+
assertions: {
|
|
13
|
+
/**
|
|
14
|
+
* Check if a value is an instance of the given class constructor.
|
|
15
|
+
*
|
|
16
|
+
* Type guards the value.
|
|
17
|
+
*/
|
|
18
|
+
instanceOf: typeof instanceOf;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a value is _not_ an instance of the given class constructor.
|
|
21
|
+
*
|
|
22
|
+
* Type guards the value when possible.
|
|
23
|
+
*/
|
|
24
|
+
notInstanceOf: typeof notInstanceOf;
|
|
25
|
+
};
|
|
26
|
+
checkOverrides: {
|
|
27
|
+
instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>) => instance is Instance;
|
|
28
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>) => instance is Exclude<Actual, Instance>;
|
|
29
|
+
};
|
|
30
|
+
assertWrapOverrides: {
|
|
31
|
+
instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>, failureMessage?: string | undefined) => Instance;
|
|
32
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>, failureMessage?: string | undefined) => Exclude<Actual, Instance>;
|
|
33
|
+
};
|
|
34
|
+
checkWrapOverrides: {
|
|
35
|
+
instanceOf: <const Instance>(instance: unknown, constructor: Constructor<Instance>) => Instance | undefined;
|
|
36
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: Constructor<Instance>) => Exclude<Actual, Instance> | undefined;
|
|
37
|
+
};
|
|
38
|
+
waitUntilOverrides: {
|
|
39
|
+
instanceOf: <const Instance>(constructor: Constructor<Instance>, callback: () => MaybePromise<unknown>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Instance>;
|
|
40
|
+
notInstanceOf: <const Actual, const Instance>(constructor: Constructor<Instance>, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, Instance>>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { stringify } from '@augment-vir/core';
|
|
2
|
+
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
+
import { autoGuard } from '../guard-types/guard-override.js';
|
|
4
|
+
/** Wraps the JavaScript built-in "instanceof" in a type guard assertion. */
|
|
5
|
+
function instanceOf(instance,
|
|
6
|
+
/** The constructor that the "instance" input will be checked against. */
|
|
7
|
+
constructor,
|
|
8
|
+
/** Message to include in error message if this assertion fails. */
|
|
9
|
+
failureMessage) {
|
|
10
|
+
if (!(instance instanceof constructor)) {
|
|
11
|
+
throw new AssertionError(`'${stringify(instance)}' is not an instance of '${constructor.name}'`, failureMessage);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function notInstanceOf(instance, constructor, failureMessage) {
|
|
15
|
+
if (instance instanceof constructor) {
|
|
16
|
+
throw new AssertionError(`'${stringify(instance)}' is an instance of '${constructor.name}'`, failureMessage);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const assertions = {
|
|
20
|
+
instanceOf,
|
|
21
|
+
notInstanceOf,
|
|
22
|
+
};
|
|
23
|
+
export const instanceGuards = {
|
|
24
|
+
assertions,
|
|
25
|
+
checkOverrides: {
|
|
26
|
+
instanceOf: autoGuard(),
|
|
27
|
+
notInstanceOf: autoGuard(),
|
|
28
|
+
},
|
|
29
|
+
assertWrapOverrides: {
|
|
30
|
+
instanceOf: autoGuard(),
|
|
31
|
+
notInstanceOf: autoGuard(),
|
|
32
|
+
},
|
|
33
|
+
checkWrapOverrides: {
|
|
34
|
+
instanceOf: autoGuard(),
|
|
35
|
+
notInstanceOf: autoGuard(),
|
|
36
|
+
},
|
|
37
|
+
waitUntilOverrides: {
|
|
38
|
+
instanceOf: autoGuard(),
|
|
39
|
+
notInstanceOf: autoGuard(),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { MaybePromise, NarrowToExpected, type RequiredKeysOf } from '@augment-vir/core';
|
|
2
|
+
import { SetRequired } from 'type-fest';
|
|
3
|
+
import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
4
|
+
declare function isKeyOf<const Parent>(key: PropertyKey, parent: Parent, failureMessage?: string | undefined): asserts key is keyof Parent;
|
|
5
|
+
declare function isNotKeyOf<const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined): asserts key is Exclude<Key, RequiredKeysOf<Parent>>;
|
|
6
|
+
/** Helper type for `hasKey`. */
|
|
7
|
+
type ExtractValue<Key extends PropertyKey, Parent> = Key extends keyof Parent ? SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never;
|
|
8
|
+
/** Helper type for `hasKey`. */
|
|
9
|
+
type CombinedParentValue<Key extends PropertyKey, Parent> = ExtractValue<Key, Parent> extends never ? unknown : ExtractValue<Key, Parent>;
|
|
10
|
+
/** Helper type for `hasKey`. */
|
|
11
|
+
type CombineTypeWithKey<Key extends PropertyKey, Parent> = Parent & Record<Key, CombinedParentValue<Key, Parent>>;
|
|
12
|
+
/** Check if an object has the given property. */
|
|
13
|
+
declare function hasKey<const Key extends PropertyKey, const Parent>(parent: Parent, key: Key, failureMessage?: string | undefined): asserts parent is CombineTypeWithKey<Key, Parent>;
|
|
14
|
+
declare function lacksKey<const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined): asserts parent is Exclude<Parent, Record<Key, any>>;
|
|
15
|
+
/** Check if an object has all the given properties. */
|
|
16
|
+
declare function hasKeys<const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>, failureMessage?: string | undefined): asserts parent is CombineTypeWithKey<Keys, Parent>;
|
|
17
|
+
declare function lacksKeys<const Parent, const Key extends PropertyKey>(parent: Parent, keys: ReadonlyArray<Key>, failureMessage?: string | undefined): asserts parent is Exclude<Parent, Partial<Record<Key, any>>>;
|
|
18
|
+
export declare const keyGuards: {
|
|
19
|
+
assertions: {
|
|
20
|
+
/**
|
|
21
|
+
* Check if a key (or property) is contained within a parent value.
|
|
22
|
+
*
|
|
23
|
+
* Type guards the key.
|
|
24
|
+
*/
|
|
25
|
+
isKeyOf: typeof isKeyOf;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a key (or property) is _not_ contained within a parent value.
|
|
28
|
+
*
|
|
29
|
+
* Type guards the key.
|
|
30
|
+
*/
|
|
31
|
+
isNotKeyOf: typeof isNotKeyOf;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a parent value has a key (or property).
|
|
34
|
+
*
|
|
35
|
+
* Type guards the parent value.
|
|
36
|
+
*/
|
|
37
|
+
hasKey: typeof hasKey;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a parent value does _not_ have a key (or property).
|
|
40
|
+
*
|
|
41
|
+
* Type guards the parent value when possible.
|
|
42
|
+
*/
|
|
43
|
+
lacksKey: typeof lacksKey;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a parent value has multiple keys (or properties).
|
|
46
|
+
*
|
|
47
|
+
* Type guards the parent value.
|
|
48
|
+
*/
|
|
49
|
+
hasKeys: typeof hasKeys;
|
|
50
|
+
/**
|
|
51
|
+
* Check if a parent value does _not_ have multiple keys (or properties).
|
|
52
|
+
*
|
|
53
|
+
* Type guards the parent value when possible.
|
|
54
|
+
*/
|
|
55
|
+
lacksKeys: typeof lacksKeys;
|
|
56
|
+
};
|
|
57
|
+
checkOverrides: {
|
|
58
|
+
isKeyOf: <const Parent>(key: PropertyKey, parent: Parent) => key is keyof Parent;
|
|
59
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => key is Exclude<Key, RequiredKeysOf<Parent>>;
|
|
60
|
+
hasKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key) => parent is CombineTypeWithKey<Key, Parent>;
|
|
61
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => parent is Exclude<Parent, Record<Key, any>>;
|
|
62
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>) => parent is CombineTypeWithKey<Keys, Parent>;
|
|
63
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, key: ReadonlyArray<Key>) => parent is Exclude<Parent, Partial<Record<Key, any>>>;
|
|
64
|
+
};
|
|
65
|
+
assertWrapOverrides: {
|
|
66
|
+
isKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => NarrowToExpected<Key, keyof Parent>;
|
|
67
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => Exclude<Key, RequiredKeysOf<Parent>>;
|
|
68
|
+
hasKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => CombineTypeWithKey<Key, Parent>;
|
|
69
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => Exclude<Parent, Record<Key, any>>;
|
|
70
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>, failureMessage?: string | undefined) => CombineTypeWithKey<Keys, Parent>;
|
|
71
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, key: ReadonlyArray<Key>, failureMessage?: string | undefined) => Exclude<Parent, Partial<Record<Key, any>>>;
|
|
72
|
+
};
|
|
73
|
+
checkWrapOverrides: {
|
|
74
|
+
isKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent) => NarrowToExpected<Key, keyof Parent> | undefined;
|
|
75
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => Exclude<Key, RequiredKeysOf<Parent>> | undefined;
|
|
76
|
+
hasKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key) => CombineTypeWithKey<Key, Parent> | undefined;
|
|
77
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => Exclude<Parent, Record<Key, any>> | undefined;
|
|
78
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>) => CombineTypeWithKey<Keys, Parent> | undefined;
|
|
79
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, key: ReadonlyArray<Key>) => Exclude<Parent, Partial<Record<Key, any>>> | undefined;
|
|
80
|
+
};
|
|
81
|
+
waitUntilOverrides: {
|
|
82
|
+
isKeyOf: <const Key extends PropertyKey, const Parent>(parent: Parent, callback: () => MaybePromise<Key>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Key, keyof Parent>>;
|
|
83
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(parent: Parent, callback: () => MaybePromise<Key>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Key, RequiredKeysOf<Parent>>>;
|
|
84
|
+
hasKey: <const Parent, const Key extends PropertyKey>(key: Key, callback: () => MaybePromise<Parent>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<CombineTypeWithKey<Key, Parent>>;
|
|
85
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(key: Key, callback: () => MaybePromise<Parent>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Parent, Record<Key, any>>>;
|
|
86
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(keys: ReadonlyArray<Keys>, callback: () => MaybePromise<Parent>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<CombineTypeWithKey<Keys, Parent>>;
|
|
87
|
+
lacksKeys: <const Parent, const Keys extends PropertyKey>(keys: ReadonlyArray<Keys>, callback: () => MaybePromise<Parent>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Parent, Partial<Record<Keys, any>>>>;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { stringify } from '@augment-vir/core';
|
|
2
|
+
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
+
import { createCheck } from '../guard-types/check-function.js';
|
|
4
|
+
import { autoGuard } from '../guard-types/guard-override.js';
|
|
5
|
+
function isKeyOf(key, parent, failureMessage) {
|
|
6
|
+
try {
|
|
7
|
+
hasKey(parent, key);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new AssertionError(`'${String(key)}' is not a key of '${stringify(parent)}'.`, failureMessage);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function isNotKeyOf(key, parent, failureMessage) {
|
|
14
|
+
try {
|
|
15
|
+
isKeyOf(key, parent);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
throw new AssertionError(`'${String(key)}' is a key of '${stringify(parent)}'.`, failureMessage);
|
|
21
|
+
}
|
|
22
|
+
const hasKeyAttempts = [
|
|
23
|
+
(object, key) => {
|
|
24
|
+
return key in object;
|
|
25
|
+
},
|
|
26
|
+
(object, key) => {
|
|
27
|
+
/** This handles cases where the input object can't use `in` directly, like string literals */
|
|
28
|
+
return key in object.constructor.prototype;
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
/** Check if an object has the given property. */
|
|
32
|
+
function hasKey(parent, key, failureMessage) {
|
|
33
|
+
const message = `'${stringify(parent)}' does not have key '${String(key)}'.`;
|
|
34
|
+
const doesHaveKey = hasKeyAttempts.some((attemptCallback) => {
|
|
35
|
+
try {
|
|
36
|
+
return attemptCallback(parent, key);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!doesHaveKey) {
|
|
43
|
+
throw new AssertionError(message, failureMessage);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function lacksKey(parent, key, failureMessage) {
|
|
47
|
+
try {
|
|
48
|
+
hasKey(parent, key);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
throw new AssertionError(`'${stringify(parent)}' has key '${String(key)}'.`, failureMessage);
|
|
54
|
+
}
|
|
55
|
+
const checkHasKey = createCheck(hasKey);
|
|
56
|
+
/** Check if an object has all the given properties. */
|
|
57
|
+
function hasKeys(parent, keys, failureMessage) {
|
|
58
|
+
const missingKeys = keys.filter((key) => !checkHasKey(parent, key));
|
|
59
|
+
if (missingKeys.length) {
|
|
60
|
+
throw new AssertionError(`'${stringify(parent)}' does not have keys '${missingKeys.join(',')}'.`, failureMessage);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function lacksKeys(parent, keys, failureMessage) {
|
|
64
|
+
const existingKeys = keys.filter((key) => checkHasKey(parent, key));
|
|
65
|
+
if (existingKeys.length) {
|
|
66
|
+
throw new AssertionError(`'${stringify(parent)}' does not lack keys '${existingKeys.join(',')}'.`, failureMessage);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const assertions = {
|
|
70
|
+
isKeyOf,
|
|
71
|
+
isNotKeyOf,
|
|
72
|
+
hasKey,
|
|
73
|
+
lacksKey,
|
|
74
|
+
hasKeys,
|
|
75
|
+
lacksKeys,
|
|
76
|
+
};
|
|
77
|
+
export const keyGuards = {
|
|
78
|
+
assertions,
|
|
79
|
+
checkOverrides: {
|
|
80
|
+
isKeyOf: autoGuard(),
|
|
81
|
+
isNotKeyOf: autoGuard(),
|
|
82
|
+
hasKey: autoGuard(),
|
|
83
|
+
lacksKey: autoGuard(),
|
|
84
|
+
hasKeys: autoGuard(),
|
|
85
|
+
lacksKeys: autoGuard(),
|
|
86
|
+
},
|
|
87
|
+
assertWrapOverrides: {
|
|
88
|
+
isKeyOf: autoGuard(),
|
|
89
|
+
isNotKeyOf: autoGuard(),
|
|
90
|
+
hasKey: autoGuard(),
|
|
91
|
+
lacksKey: autoGuard(),
|
|
92
|
+
hasKeys: autoGuard(),
|
|
93
|
+
lacksKeys: autoGuard(),
|
|
94
|
+
},
|
|
95
|
+
checkWrapOverrides: {
|
|
96
|
+
isKeyOf: autoGuard(),
|
|
97
|
+
isNotKeyOf: autoGuard(),
|
|
98
|
+
hasKey: autoGuard(),
|
|
99
|
+
lacksKey: autoGuard(),
|
|
100
|
+
hasKeys: autoGuard(),
|
|
101
|
+
lacksKeys: autoGuard(),
|
|
102
|
+
},
|
|
103
|
+
waitUntilOverrides: {
|
|
104
|
+
isKeyOf: autoGuard(),
|
|
105
|
+
isNotKeyOf: autoGuard(),
|
|
106
|
+
hasKey: autoGuard(),
|
|
107
|
+
lacksKey: autoGuard(),
|
|
108
|
+
hasKeys: autoGuard(),
|
|
109
|
+
lacksKeys: autoGuard(),
|
|
110
|
+
},
|
|
111
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { MaybePromise, Tuple, type AnyObject, type AtLeastTuple } from '@augment-vir/core';
|
|
2
|
+
import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
3
|
+
declare function isLengthAtLeast<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is AtLeastTuple<Element, Length>;
|
|
4
|
+
declare function isLengthAtLeast(actual: string | AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
5
|
+
declare function isLengthExactly<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is Tuple<Element, Length>;
|
|
6
|
+
declare function isLengthExactly(actual: string | AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
7
|
+
/** These functions are not used at run time, they're only here for types. */
|
|
8
|
+
declare function checkIsLengthAtLeast<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): actual is AtLeastTuple<Element, Length>;
|
|
9
|
+
declare function checkIsLengthAtLeast(actual: string | AnyObject, length: number): boolean;
|
|
10
|
+
declare function assertWrapIsLengthAtLeast<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): AtLeastTuple<Element, Length>;
|
|
11
|
+
declare function assertWrapIsLengthAtLeast<Actual extends string | AnyObject>(actual: Actual, length: number): Actual;
|
|
12
|
+
declare function checkWrapIsLengthAtLeast<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): AtLeastTuple<Element, Length> | undefined;
|
|
13
|
+
declare function checkWrapIsLengthAtLeast<Actual extends string | AnyObject>(actual: Actual, length: number): Actual | undefined;
|
|
14
|
+
declare function waitUntilIsLengthAtLeast<Element, Length extends number>(length: Length, callback: () => MaybePromise<ReadonlyArray<Element | undefined>>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<AtLeastTuple<Element, Length>>;
|
|
15
|
+
declare function waitUntilIsLengthAtLeast<Actual extends string | AnyObject>(length: number, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<Actual>;
|
|
16
|
+
declare function checkIsLengthExactly<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): actual is Tuple<Element, Length>;
|
|
17
|
+
declare function checkIsLengthExactly(actual: string | AnyObject, length: number): boolean;
|
|
18
|
+
declare function assertWrapIsLengthExactly<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): Tuple<Element, Length>;
|
|
19
|
+
declare function assertWrapIsLengthExactly<Actual extends string | AnyObject>(actual: Actual, length: number): Actual;
|
|
20
|
+
declare function checkWrapIsLengthExactly<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): Tuple<Element, Length> | undefined;
|
|
21
|
+
declare function checkWrapIsLengthExactly<Actual extends string | AnyObject>(actual: Actual, length: number): Actual | undefined;
|
|
22
|
+
declare function waitUntilIsLengthExactly<Element, Length extends number>(length: Length, callback: () => MaybePromise<ReadonlyArray<Element | undefined>>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<Tuple<Element, Length>>;
|
|
23
|
+
declare function waitUntilIsLengthExactly<Actual extends string | AnyObject>(length: number, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined): Promise<Actual>;
|
|
24
|
+
export declare const lengthGuards: {
|
|
25
|
+
assertions: {
|
|
26
|
+
/**
|
|
27
|
+
* Check if an array has at least the given length.
|
|
28
|
+
*
|
|
29
|
+
* Type guards the array into an {@link AtLeastTuple}.
|
|
30
|
+
*/
|
|
31
|
+
isLengthAtLeast: typeof isLengthAtLeast;
|
|
32
|
+
/**
|
|
33
|
+
* Check if an array has exactly the given length.
|
|
34
|
+
*
|
|
35
|
+
* Type guards the array into a {@link Tuple}.
|
|
36
|
+
*/
|
|
37
|
+
isLengthExactly: typeof isLengthExactly;
|
|
38
|
+
};
|
|
39
|
+
checkOverrides: {
|
|
40
|
+
isLengthAtLeast: typeof checkIsLengthAtLeast;
|
|
41
|
+
isLengthExactly: typeof checkIsLengthExactly;
|
|
42
|
+
};
|
|
43
|
+
assertWrapOverrides: {
|
|
44
|
+
isLengthAtLeast: typeof assertWrapIsLengthAtLeast;
|
|
45
|
+
isLengthExactly: typeof assertWrapIsLengthExactly;
|
|
46
|
+
};
|
|
47
|
+
checkWrapOverrides: {
|
|
48
|
+
isLengthAtLeast: typeof checkWrapIsLengthAtLeast;
|
|
49
|
+
isLengthExactly: typeof checkWrapIsLengthExactly;
|
|
50
|
+
};
|
|
51
|
+
waitUntilOverrides: {
|
|
52
|
+
isLengthAtLeast: typeof waitUntilIsLengthAtLeast;
|
|
53
|
+
isLengthExactly: typeof waitUntilIsLengthExactly;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { getObjectTypedKeys, } from '@augment-vir/core';
|
|
3
|
+
import { AssertionError } from '../augments/assertion.error.js';
|
|
4
|
+
import { autoGuard } from '../guard-types/guard-override.js';
|
|
5
|
+
function isLengthAtLeast(actual, length, failureMessage) {
|
|
6
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
7
|
+
? actual.length
|
|
8
|
+
: getObjectTypedKeys(actual).length;
|
|
9
|
+
if (actualLength < length) {
|
|
10
|
+
throw new AssertionError(`Length '${actual.length}' is not at least '${length}'.`, failureMessage);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function isLengthExactly(actual, length, failureMessage) {
|
|
14
|
+
const actualLength = Array.isArray(actual) || typeof actual === 'string'
|
|
15
|
+
? actual.length
|
|
16
|
+
: getObjectTypedKeys(actual).length;
|
|
17
|
+
if (actualLength !== length) {
|
|
18
|
+
throw new AssertionError(`Length '${actual.length}' is not exactly '${length}'.`, failureMessage);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function checkIsLengthAtLeast(actual, length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function assertWrapIsLengthAtLeast(actual, length) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function checkWrapIsLengthAtLeast(actual, length) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function waitUntilIsLengthAtLeast(length, callback, options, failureMessage) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function checkIsLengthExactly(actual, length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function assertWrapIsLengthExactly(actual, length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function checkWrapIsLengthExactly(actual, length) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function waitUntilIsLengthExactly(length, callback, options, failureMessage) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/* node:coverage enable */
|
|
46
|
+
const assertions = {
|
|
47
|
+
isLengthAtLeast,
|
|
48
|
+
isLengthExactly,
|
|
49
|
+
};
|
|
50
|
+
export const lengthGuards = {
|
|
51
|
+
assertions,
|
|
52
|
+
checkOverrides: {
|
|
53
|
+
isLengthAtLeast: autoGuard(),
|
|
54
|
+
isLengthExactly: autoGuard(),
|
|
55
|
+
},
|
|
56
|
+
assertWrapOverrides: {
|
|
57
|
+
isLengthAtLeast: autoGuard(),
|
|
58
|
+
isLengthExactly: autoGuard(),
|
|
59
|
+
},
|
|
60
|
+
checkWrapOverrides: {
|
|
61
|
+
isLengthAtLeast: autoGuard(),
|
|
62
|
+
isLengthExactly: autoGuard(),
|
|
63
|
+
},
|
|
64
|
+
waitUntilOverrides: {
|
|
65
|
+
isLengthAtLeast: autoGuard(),
|
|
66
|
+
isLengthExactly: autoGuard(),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MaybePromise } from '@augment-vir/core';
|
|
2
|
+
import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
3
|
+
declare function isDefined<const Actual>(
|
|
4
|
+
/** The value to check. */
|
|
5
|
+
input: Actual,
|
|
6
|
+
/** Message to include in error message if this assertion fails. */
|
|
7
|
+
failureMessage?: string | undefined): asserts input is Exclude<Actual, undefined | null>;
|
|
8
|
+
declare function isNullish(
|
|
9
|
+
/** The value to check. */
|
|
10
|
+
input: unknown,
|
|
11
|
+
/** Message to include in error message if this assertion fails. */
|
|
12
|
+
failureMessage?: string | undefined): asserts input is null | undefined;
|
|
13
|
+
export declare const nullishGuards: {
|
|
14
|
+
assertions: {
|
|
15
|
+
/**
|
|
16
|
+
* Checks that a value is defined (not `null` and not `undefined`).
|
|
17
|
+
*
|
|
18
|
+
* Type guards the value.
|
|
19
|
+
*/
|
|
20
|
+
isDefined: typeof isDefined;
|
|
21
|
+
/**
|
|
22
|
+
* Checks that a value is nullish (`null` or `undefined`).
|
|
23
|
+
*
|
|
24
|
+
* Type guards the value.
|
|
25
|
+
*/
|
|
26
|
+
isNullish: typeof isNullish;
|
|
27
|
+
};
|
|
28
|
+
checkOverrides: {
|
|
29
|
+
isDefined: <Actual>(input: Actual) => input is Exclude<Actual, undefined | null>;
|
|
30
|
+
};
|
|
31
|
+
assertWrapOverrides: {
|
|
32
|
+
isDefined: <Actual>(input: Actual, failureMessage?: string | undefined) => Exclude<Actual, undefined | null>;
|
|
33
|
+
};
|
|
34
|
+
/** Nullish checks don't make any sense on `checkWrap`. */
|
|
35
|
+
checkWrapOverrides: {
|
|
36
|
+
isDefined: undefined;
|
|
37
|
+
isNullish: undefined;
|
|
38
|
+
};
|
|
39
|
+
waitUntilOverrides: {
|
|
40
|
+
isDefined: <Actual>(callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, undefined | null>>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export {};
|