@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,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A group of guard methods that do the following:
|
|
3
|
+
*
|
|
4
|
+
* 1. Run the method's assertion on the given inputs.
|
|
5
|
+
* 2. If the assertion fails, throws an error.
|
|
6
|
+
* 3. If the assertion succeeds, the first input is returned and (when possible) type guarded.
|
|
7
|
+
*
|
|
8
|
+
* @category Assert
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
13
|
+
*
|
|
14
|
+
* // `result1` will be `['a']`
|
|
15
|
+
* const result1 = assertWrap.deepEquals(['a'], ['a']);
|
|
16
|
+
*
|
|
17
|
+
* const value: unknown = 'some value' as unknown;
|
|
18
|
+
* // `result2` will be `'some value'` and it will have the type of `string`
|
|
19
|
+
* const result2 = assertWrap.isString(value);
|
|
20
|
+
*
|
|
21
|
+
* const value2: unknown = 'some value' as unknown;
|
|
22
|
+
* // this will throw an error
|
|
23
|
+
* const result3 = assertWrap.isNumber(value2);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @returns The original value if expectations are met.
|
|
27
|
+
* @throws {@link AssertionError} When the assertion fails.
|
|
28
|
+
* @package @augment-vir/assert
|
|
29
|
+
*/
|
|
30
|
+
export declare const assertWrap: import("../../guard-types/assert-wrap-function.js").AssertWrapGroup<{
|
|
31
|
+
output: {
|
|
32
|
+
<const FunctionToCall extends import("@augment-vir/core").AnyFunction>(functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<NoInfer<FunctionToCall>>> extends true ? void : Promise<void> : void;
|
|
33
|
+
<const FunctionToCall extends import("@augment-vir/core").AnyFunction>(asserter: import("../assertion-exports.js").CustomOutputAsserter<NoInfer<FunctionToCall>>, functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<NoInfer<FunctionToCall>>> extends true ? void : Promise<void> : void;
|
|
34
|
+
};
|
|
35
|
+
isHttpStatus: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").HttpStatus;
|
|
36
|
+
isHttpStatusCategory: <const Actual, const Category extends import("@augment-vir/core").HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToExpected<Actual, import("@augment-vir/core").HttpStatusByCategory<Category>>;
|
|
37
|
+
hasValue: (parent: object, value: unknown, failureMessage?: string | undefined) => void;
|
|
38
|
+
lacksValue: (parent: object, value: unknown, failureMessage?: string | undefined) => void;
|
|
39
|
+
hasValues: (parent: object, values: ReadonlyArray<unknown>, failureMessage?: string | undefined) => void;
|
|
40
|
+
lacksValues: (parent: object, values: ReadonlyArray<unknown>, failureMessage?: string | undefined) => void;
|
|
41
|
+
isIn: typeof import("../../assertions/values.js").isIn;
|
|
42
|
+
isNotIn: <const Parent extends object | string, const Child>(child: Child, parent: Parent, failureMessage?: string | undefined) => asserts child is Exclude<Child, import("@augment-vir/core").Values<Parent>>;
|
|
43
|
+
isEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToActual<Actual, import("../assertion-exports.js").Empty>;
|
|
44
|
+
isNotEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("../assertion-exports.js").Empty>;
|
|
45
|
+
isUuid: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").Uuid;
|
|
46
|
+
isNotUuid: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("@augment-vir/core").Uuid>;
|
|
47
|
+
isError: (actual: unknown, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined) => asserts actual is Error;
|
|
48
|
+
throws: {
|
|
49
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, never>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): void;
|
|
50
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, Promise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): Promise<void>;
|
|
51
|
+
(callback: import("@augment-vir/core").TypedFunction<void, any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): void;
|
|
52
|
+
(callback: import("@augment-vir/core").TypedFunction<void, import("@augment-vir/core").MaybePromise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): import("@augment-vir/core").MaybePromise<void>;
|
|
53
|
+
};
|
|
54
|
+
strictEquals: typeof import("../../assertions/equality/simple-equality.js").strictEquals;
|
|
55
|
+
notStrictEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
56
|
+
looseEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
57
|
+
notLooseEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
58
|
+
deepEquals: typeof import("../../assertions/equality/simple-equality.js").deepEquals;
|
|
59
|
+
notDeepEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
60
|
+
isArray: (actual: unknown, failureMessage?: string | undefined) => asserts actual is unknown[];
|
|
61
|
+
isBigInt: (actual: unknown, failureMessage?: string | undefined) => asserts actual is bigint;
|
|
62
|
+
isBoolean: (actual: unknown, failureMessage?: string | undefined) => asserts actual is boolean;
|
|
63
|
+
isFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToActual<Actual, import("@augment-vir/core").AnyFunction>;
|
|
64
|
+
isNull: (actual: unknown, failureMessage?: string | undefined) => asserts actual is null;
|
|
65
|
+
isNumber: (actual: unknown, failureMessage?: string | undefined) => asserts actual is number;
|
|
66
|
+
isObject: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").UnknownObject;
|
|
67
|
+
isString: (actual: unknown, failureMessage?: string | undefined) => asserts actual is string;
|
|
68
|
+
isSymbol: (actual: unknown, failureMessage?: string | undefined) => asserts actual is symbol;
|
|
69
|
+
isUndefined: (actual: unknown, failureMessage?: string | undefined) => asserts actual is undefined;
|
|
70
|
+
isNotArray: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, ReadonlyArray<unknown>>;
|
|
71
|
+
isNotBigInt: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, bigint>;
|
|
72
|
+
isNotBoolean: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, boolean>;
|
|
73
|
+
isNotFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("@augment-vir/core").AnyFunction>;
|
|
74
|
+
isNotNumber: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, number>;
|
|
75
|
+
isNotObject: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("@augment-vir/core").UnknownObject>;
|
|
76
|
+
isNotString: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, string>;
|
|
77
|
+
isNotSymbol: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, symbol>;
|
|
78
|
+
isNotUndefined: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, undefined>;
|
|
79
|
+
isNotNull: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, null>;
|
|
80
|
+
matches: (actual: string, expected: RegExp, failureMessage?: string | undefined) => void;
|
|
81
|
+
mismatches: (actual: string, expected: RegExp, failureMessage?: string | undefined) => void;
|
|
82
|
+
isPromiseLike: (actual: unknown, failureMessage?: string | undefined) => asserts actual is PromiseLike<any>;
|
|
83
|
+
isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, PromiseLike<any>>;
|
|
84
|
+
isPromise: (actual: unknown, failureMessage?: string | undefined) => asserts actual is Promise<any>;
|
|
85
|
+
isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, Promise<any>>;
|
|
86
|
+
isPropertyKey: (input: unknown, failureMessage?: string | undefined) => asserts input is PropertyKey;
|
|
87
|
+
isNotPropertyKey: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, PropertyKey>;
|
|
88
|
+
isPrimitive: (input: unknown, failureMessage?: string | undefined) => asserts input is import("type-fest").Primitive;
|
|
89
|
+
isNotPrimitive: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, import("type-fest").Primitive>;
|
|
90
|
+
isAbove: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
91
|
+
isAtLeast: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
92
|
+
isBelow: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
93
|
+
isAtMost: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
94
|
+
isNaN: (actual: number, failureMessage?: string | undefined) => void;
|
|
95
|
+
isFinite: (actual: number, failureMessage?: string | undefined) => void;
|
|
96
|
+
isInfinite: (actual: number, failureMessage?: string | undefined) => void;
|
|
97
|
+
isApproximately: (actual: number, expected: number, delta: number, failureMessage?: string | undefined) => void;
|
|
98
|
+
isNotApproximately: (actual: number, expected: number, delta: number, failureMessage?: string | undefined) => void;
|
|
99
|
+
isDefined: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, undefined | null>;
|
|
100
|
+
isNullish: (input: unknown, failureMessage?: string | undefined) => asserts input is null | undefined;
|
|
101
|
+
isLengthAtLeast: {
|
|
102
|
+
<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is import("@augment-vir/core").AtLeastTuple<Element, Length>;
|
|
103
|
+
(actual: string | import("@augment-vir/core").AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
104
|
+
};
|
|
105
|
+
isLengthExactly: {
|
|
106
|
+
<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is import("@augment-vir/core").Tuple<Element, Length>;
|
|
107
|
+
(actual: string | import("@augment-vir/core").AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
108
|
+
};
|
|
109
|
+
isKeyOf: <const Parent>(key: PropertyKey, parent: Parent, failureMessage?: string | undefined) => asserts key is keyof Parent;
|
|
110
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => asserts key is Exclude<Key, import("@augment-vir/core").RequiredKeysOf<Parent>>;
|
|
111
|
+
hasKey: <const Key extends PropertyKey, const Parent>(parent: Parent, key: Key, failureMessage?: string | undefined) => asserts parent is Parent & Record<Key, (Key extends keyof Parent ? import("type-fest").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never) extends never ? unknown : Key extends keyof Parent ? import("type-fest").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never>;
|
|
112
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => asserts parent is Exclude<Parent, Record<Key, any>>;
|
|
113
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>, failureMessage?: string | undefined) => asserts parent is Parent & Record<Keys, (Keys extends keyof Parent ? import("type-fest").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never) extends never ? unknown : Keys extends keyof Parent ? import("type-fest").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never>;
|
|
114
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, keys: ReadonlyArray<Key>, failureMessage?: string | undefined) => asserts parent is Exclude<Parent, Partial<Record<Key, any>>>;
|
|
115
|
+
jsonEquals: <const Actual, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => asserts actual is Expected;
|
|
116
|
+
notJsonEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
117
|
+
instanceOf: <const Instance>(instance: unknown, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => asserts instance is Instance;
|
|
118
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => asserts instance is Exclude<Actual, Instance>;
|
|
119
|
+
isEnumValue: typeof import("../../assertions/enum.js").isEnumValue;
|
|
120
|
+
isNotEnumValue: <const Actual, const Expected extends import("@augment-vir/core").EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => asserts child is Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
|
|
121
|
+
entriesEqual: <const Actual extends object, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => asserts actual is Expected;
|
|
122
|
+
notEntriesEqual: (actual: object, expected: object, failureMessage?: string | undefined) => void;
|
|
123
|
+
endsWith: {
|
|
124
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
125
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
126
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
127
|
+
};
|
|
128
|
+
endsWithout: {
|
|
129
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
130
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
131
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
132
|
+
};
|
|
133
|
+
startsWith: {
|
|
134
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
135
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
136
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
137
|
+
};
|
|
138
|
+
startsWithout: {
|
|
139
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
140
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
141
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
142
|
+
};
|
|
143
|
+
isFalsy: (input: unknown, failureMessage?: string | undefined) => asserts input is import("../assertion-exports.js").FalsyValue;
|
|
144
|
+
isTruthy: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is import("../assertion-exports.js").Truthy<Actual>;
|
|
145
|
+
isTrue: (input: unknown, failureMessage?: string | undefined) => asserts input is true;
|
|
146
|
+
isFalse: (input: unknown, failureMessage?: string | undefined) => asserts input is false;
|
|
147
|
+
}, {
|
|
148
|
+
isFalsy: <T>(input: T, failureMessage?: string | undefined) => import("../assertion-exports.js").Falsy<T>;
|
|
149
|
+
isTruthy: <T>(input: T, failureMessage?: string | undefined) => import("../assertion-exports.js").Truthy<T>;
|
|
150
|
+
} & {
|
|
151
|
+
strictEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, Expected>;
|
|
152
|
+
deepEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, Expected>;
|
|
153
|
+
} & {
|
|
154
|
+
output: {
|
|
155
|
+
<const FunctionToCall extends import("@augment-vir/core").AnyFunction>(functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<FunctionToCall>> extends true ? Awaited<ReturnType<NoInfer<FunctionToCall>>> : Promise<Awaited<ReturnType<NoInfer<FunctionToCall>>>> : Awaited<ReturnType<NoInfer<FunctionToCall>>>;
|
|
156
|
+
<const FunctionToCall extends import("@augment-vir/core").AnyFunction>(asserter: import("../assertion-exports.js").CustomOutputAsserter<NoInfer<FunctionToCall>>, functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<FunctionToCall>> extends true ? Awaited<ReturnType<NoInfer<FunctionToCall>>> : Promise<Awaited<ReturnType<NoInfer<FunctionToCall>>>> : Awaited<ReturnType<NoInfer<FunctionToCall>>>;
|
|
157
|
+
};
|
|
158
|
+
} & {
|
|
159
|
+
isFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToActual<Actual, import("@augment-vir/core").AnyFunction>;
|
|
160
|
+
isSymbol: <const Actual>(actual: Actual, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, symbol>;
|
|
161
|
+
isNotArray: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, ReadonlyArray<unknown>>;
|
|
162
|
+
isNotBigInt: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, bigint>;
|
|
163
|
+
isNotBoolean: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, boolean>;
|
|
164
|
+
isNotFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, import("@augment-vir/core").AnyFunction>;
|
|
165
|
+
isNotNull: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, null>;
|
|
166
|
+
isNotNumber: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, number>;
|
|
167
|
+
isNotObject: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, import("@augment-vir/core").UnknownObject>;
|
|
168
|
+
isNotString: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, string>;
|
|
169
|
+
isNotUndefined: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, undefined>;
|
|
170
|
+
isNotSymbol: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, symbol>;
|
|
171
|
+
} & {
|
|
172
|
+
throws: {
|
|
173
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, never>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): Error;
|
|
174
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, Promise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): Promise<Error>;
|
|
175
|
+
(callback: import("@augment-vir/core").TypedFunction<void, any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): Error;
|
|
176
|
+
(callback: import("@augment-vir/core").TypedFunction<void, import("@augment-vir/core").MaybePromise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): import("@augment-vir/core").MaybePromise<Error>;
|
|
177
|
+
};
|
|
178
|
+
} & {
|
|
179
|
+
isIn: <const Child, const Parent>(child: Child, parent: Parent, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Child, import("@augment-vir/core").Values<Parent>>;
|
|
180
|
+
isNotIn: <const Parent, const Child>(child: Child, parent: Parent, failureMessage?: string | undefined) => Exclude<Child, import("@augment-vir/core").Values<Parent>>;
|
|
181
|
+
isEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToActual<Actual, import("../assertion-exports.js").Empty>;
|
|
182
|
+
isNotEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual) => Exclude<Actual, import("../assertion-exports.js").Empty>;
|
|
183
|
+
} & {
|
|
184
|
+
endsWith: {
|
|
185
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): typeof parent;
|
|
186
|
+
(parent: string, child: string, failureMessage?: string | undefined): typeof parent;
|
|
187
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): typeof parent;
|
|
188
|
+
};
|
|
189
|
+
endsWithout: {
|
|
190
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): typeof parent;
|
|
191
|
+
(parent: string, child: string, failureMessage?: string | undefined): typeof parent;
|
|
192
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): typeof parent;
|
|
193
|
+
};
|
|
194
|
+
startsWith: {
|
|
195
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): typeof parent;
|
|
196
|
+
(parent: string, child: string, failureMessage?: string | undefined): typeof parent;
|
|
197
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): typeof parent;
|
|
198
|
+
};
|
|
199
|
+
startsWithout: {
|
|
200
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): typeof parent;
|
|
201
|
+
(parent: string, child: string, failureMessage?: string | undefined): typeof parent;
|
|
202
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): typeof parent;
|
|
203
|
+
};
|
|
204
|
+
} & {
|
|
205
|
+
isEnumValue: <const Actual, const Expected extends import("@augment-vir/core").EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, Expected[keyof Expected]>;
|
|
206
|
+
isNotEnumValue: <const Actual, const Expected extends import("@augment-vir/core").EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
|
|
207
|
+
} & {
|
|
208
|
+
entriesEqual: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, Expected>;
|
|
209
|
+
} & {
|
|
210
|
+
jsonEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, Expected>;
|
|
211
|
+
} & {
|
|
212
|
+
isHttpStatusCategory: <const Actual, const Category extends import("@augment-vir/core").HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Actual, import("@augment-vir/core").HttpStatusByCategory<Category>>;
|
|
213
|
+
} & {
|
|
214
|
+
instanceOf: <const Instance>(instance: unknown, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => Instance;
|
|
215
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => Exclude<Actual, Instance>;
|
|
216
|
+
} & {
|
|
217
|
+
isKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => import("@augment-vir/core").NarrowToExpected<Key, keyof Parent>;
|
|
218
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => Exclude<Key, import("@augment-vir/core").RequiredKeysOf<Parent>>;
|
|
219
|
+
hasKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => Parent & Record<Key, (Key extends keyof Parent ? import("type-fest").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never) extends never ? unknown : Key extends keyof Parent ? import("type-fest").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never>;
|
|
220
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => Exclude<Parent, Record<Key, any>>;
|
|
221
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>, failureMessage?: string | undefined) => Parent & Record<Keys, (Keys extends keyof Parent ? import("type-fest").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never) extends never ? unknown : Keys extends keyof Parent ? import("type-fest").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("type-fest").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never>;
|
|
222
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, key: ReadonlyArray<Key>, failureMessage?: string | undefined) => Exclude<Parent, Partial<Record<Key, any>>>;
|
|
223
|
+
} & {
|
|
224
|
+
isLengthAtLeast: {
|
|
225
|
+
<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): import("@augment-vir/core").AtLeastTuple<Element, Length>;
|
|
226
|
+
<Actual extends string | import("@augment-vir/core").AnyObject>(actual: Actual, length: number): Actual;
|
|
227
|
+
};
|
|
228
|
+
isLengthExactly: {
|
|
229
|
+
<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): import("@augment-vir/core").Tuple<Element, Length>;
|
|
230
|
+
<Actual extends string | import("@augment-vir/core").AnyObject>(actual: Actual, length: number): Actual;
|
|
231
|
+
};
|
|
232
|
+
} & {
|
|
233
|
+
isDefined: <Actual>(input: Actual, failureMessage?: string | undefined) => Exclude<Actual, undefined | null>;
|
|
234
|
+
} & {
|
|
235
|
+
isNotPrimitive: <const Actual>(input: Actual, failureMessage?: string | undefined) => Exclude<Actual, import("type-fest").Primitive>;
|
|
236
|
+
isNotPropertyKey: <const Actual>(input: Actual, failureMessage?: string | undefined) => Exclude<Actual, PropertyKey>;
|
|
237
|
+
} & {
|
|
238
|
+
isPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Extract<Actual, Promise<any>>;
|
|
239
|
+
isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, Promise<any>>;
|
|
240
|
+
isPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Extract<Actual, PromiseLike<any>>;
|
|
241
|
+
isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, PromiseLike<any>>;
|
|
242
|
+
} & {
|
|
243
|
+
isNotUuid: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, import("@augment-vir/core").Uuid>;
|
|
244
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assertWrap } from '@augment-vir/assert';
|
|
2
|
+
// `result1` will be `['a']`
|
|
3
|
+
const result1 = assertWrap.deepEquals(['a'], ['a']);
|
|
4
|
+
const value = 'some value';
|
|
5
|
+
// `result2` will be `'some value'` and it will have the type of `string`
|
|
6
|
+
const result2 = assertWrap.isString(value);
|
|
7
|
+
const value2 = 'some value';
|
|
8
|
+
// this will throw an error
|
|
9
|
+
const result3 = assertWrap.isNumber(value2);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { assertWrapOverrides, extendableAssertions } from '../../assertions/extendable-assertions.js';
|
|
2
|
+
import { createAssertWrapGroup } from '../../guard-types/assert-wrap-function.js';
|
|
3
|
+
/**
|
|
4
|
+
* A group of guard methods that do the following:
|
|
5
|
+
*
|
|
6
|
+
* 1. Run the method's assertion on the given inputs.
|
|
7
|
+
* 2. If the assertion fails, throws an error.
|
|
8
|
+
* 3. If the assertion succeeds, the first input is returned and (when possible) type guarded.
|
|
9
|
+
*
|
|
10
|
+
* @category Assert
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
15
|
+
*
|
|
16
|
+
* // `result1` will be `['a']`
|
|
17
|
+
* const result1 = assertWrap.deepEquals(['a'], ['a']);
|
|
18
|
+
*
|
|
19
|
+
* const value: unknown = 'some value' as unknown;
|
|
20
|
+
* // `result2` will be `'some value'` and it will have the type of `string`
|
|
21
|
+
* const result2 = assertWrap.isString(value);
|
|
22
|
+
*
|
|
23
|
+
* const value2: unknown = 'some value' as unknown;
|
|
24
|
+
* // this will throw an error
|
|
25
|
+
* const result3 = assertWrap.isNumber(value2);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @returns The original value if expectations are met.
|
|
29
|
+
* @throws {@link AssertionError} When the assertion fails.
|
|
30
|
+
* @package @augment-vir/assert
|
|
31
|
+
*/
|
|
32
|
+
export const assertWrap = createAssertWrapGroup(extendableAssertions, assertWrapOverrides);
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { AnyFunction } from '@augment-vir/core';
|
|
2
|
+
declare const allAssertions: {
|
|
3
|
+
fail(failureMessage?: string | undefined): never;
|
|
4
|
+
output: {
|
|
5
|
+
<const FunctionToCall extends AnyFunction>(functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<NoInfer<FunctionToCall>>> extends true ? void : Promise<void> : void;
|
|
6
|
+
<const FunctionToCall extends AnyFunction>(asserter: import("../assertion-exports.js").CustomOutputAsserter<NoInfer<FunctionToCall>>, functionToCall: FunctionToCall, inputs: Parameters<NoInfer<FunctionToCall>>, expectedOutput: Awaited<ReturnType<NoInfer<FunctionToCall>>>, failureMessage?: string | undefined): Promise<any> extends ReturnType<NoInfer<FunctionToCall>> ? import("type-fest").IsAny<ReturnType<NoInfer<FunctionToCall>>> extends true ? void : Promise<void> : void;
|
|
7
|
+
};
|
|
8
|
+
isHttpStatus: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").HttpStatus;
|
|
9
|
+
isHttpStatusCategory: <const Actual, const Category extends import("@augment-vir/core").HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToExpected<Actual, import("@augment-vir/core").HttpStatusByCategory<Category>>;
|
|
10
|
+
hasValue: (parent: object, value: unknown, failureMessage?: string | undefined) => void;
|
|
11
|
+
lacksValue: (parent: object, value: unknown, failureMessage?: string | undefined) => void;
|
|
12
|
+
hasValues: (parent: object, values: ReadonlyArray<unknown>, failureMessage?: string | undefined) => void;
|
|
13
|
+
lacksValues: (parent: object, values: ReadonlyArray<unknown>, failureMessage?: string | undefined) => void;
|
|
14
|
+
isIn: typeof import("../../assertions/values.js").isIn;
|
|
15
|
+
isNotIn: <const Parent extends object | string, const Child>(child: Child, parent: Parent, failureMessage?: string | undefined) => asserts child is Exclude<Child, import("@augment-vir/core").Values<Parent>>;
|
|
16
|
+
isEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToActual<Actual, import("../assertion-exports.js").Empty>;
|
|
17
|
+
isNotEmpty: <const Actual extends import("../assertion-exports.js").CanBeEmpty>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("../assertion-exports.js").Empty>;
|
|
18
|
+
isUuid: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").Uuid;
|
|
19
|
+
isNotUuid: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("@augment-vir/core").Uuid>;
|
|
20
|
+
isError: (actual: unknown, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined) => asserts actual is Error;
|
|
21
|
+
throws: {
|
|
22
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, never>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): void;
|
|
23
|
+
(callbackOrPromise: import("@augment-vir/core").TypedFunction<void, Promise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): Promise<void>;
|
|
24
|
+
(callback: import("@augment-vir/core").TypedFunction<void, any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): void;
|
|
25
|
+
(callback: import("@augment-vir/core").TypedFunction<void, import("@augment-vir/core").MaybePromise<any>> | Promise<any>, matchOptions?: import("../assertion-exports.js").ErrorMatchOptions | undefined, failureMessage?: string | undefined): import("@augment-vir/core").MaybePromise<void>;
|
|
26
|
+
};
|
|
27
|
+
strictEquals: typeof import("../../assertions/equality/simple-equality.js").strictEquals;
|
|
28
|
+
notStrictEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
29
|
+
looseEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
30
|
+
notLooseEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
31
|
+
deepEquals: typeof import("../../assertions/equality/simple-equality.js").deepEquals;
|
|
32
|
+
notDeepEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
33
|
+
isArray: (actual: unknown, failureMessage?: string | undefined) => asserts actual is unknown[];
|
|
34
|
+
isBigInt: (actual: unknown, failureMessage?: string | undefined) => asserts actual is bigint;
|
|
35
|
+
isBoolean: (actual: unknown, failureMessage?: string | undefined) => asserts actual is boolean;
|
|
36
|
+
isFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").NarrowToActual<Actual, AnyFunction>;
|
|
37
|
+
isNull: (actual: unknown, failureMessage?: string | undefined) => asserts actual is null;
|
|
38
|
+
isNumber: (actual: unknown, failureMessage?: string | undefined) => asserts actual is number;
|
|
39
|
+
isObject: (actual: unknown, failureMessage?: string | undefined) => asserts actual is import("@augment-vir/core").UnknownObject;
|
|
40
|
+
isString: (actual: unknown, failureMessage?: string | undefined) => asserts actual is string;
|
|
41
|
+
isSymbol: (actual: unknown, failureMessage?: string | undefined) => asserts actual is symbol;
|
|
42
|
+
isUndefined: (actual: unknown, failureMessage?: string | undefined) => asserts actual is undefined;
|
|
43
|
+
isNotArray: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, ReadonlyArray<unknown>>;
|
|
44
|
+
isNotBigInt: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, bigint>;
|
|
45
|
+
isNotBoolean: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, boolean>;
|
|
46
|
+
isNotFunction: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, AnyFunction>;
|
|
47
|
+
isNotNumber: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, number>;
|
|
48
|
+
isNotObject: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, import("@augment-vir/core").UnknownObject>;
|
|
49
|
+
isNotString: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, string>;
|
|
50
|
+
isNotSymbol: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, symbol>;
|
|
51
|
+
isNotUndefined: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, undefined>;
|
|
52
|
+
isNotNull: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, null>;
|
|
53
|
+
matches: (actual: string, expected: RegExp, failureMessage?: string | undefined) => void;
|
|
54
|
+
mismatches: (actual: string, expected: RegExp, failureMessage?: string | undefined) => void;
|
|
55
|
+
isPromiseLike: (actual: unknown, failureMessage?: string | undefined) => asserts actual is PromiseLike<any>;
|
|
56
|
+
isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, PromiseLike<any>>;
|
|
57
|
+
isPromise: (actual: unknown, failureMessage?: string | undefined) => asserts actual is Promise<any>;
|
|
58
|
+
isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => asserts actual is Exclude<Actual, Promise<any>>;
|
|
59
|
+
isPropertyKey: (input: unknown, failureMessage?: string | undefined) => asserts input is PropertyKey;
|
|
60
|
+
isNotPropertyKey: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, PropertyKey>;
|
|
61
|
+
isPrimitive: (input: unknown, failureMessage?: string | undefined) => asserts input is import("type-fest").Primitive;
|
|
62
|
+
isNotPrimitive: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, import("type-fest").Primitive>;
|
|
63
|
+
isAbove: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
64
|
+
isAtLeast: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
65
|
+
isBelow: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
66
|
+
isAtMost: (actual: number, expected: number, failureMessage?: string | undefined) => void;
|
|
67
|
+
isNaN: (actual: number, failureMessage?: string | undefined) => void;
|
|
68
|
+
isFinite: (actual: number, failureMessage?: string | undefined) => void;
|
|
69
|
+
isInfinite: (actual: number, failureMessage?: string | undefined) => void;
|
|
70
|
+
isApproximately: (actual: number, expected: number, delta: number, failureMessage?: string | undefined) => void;
|
|
71
|
+
isNotApproximately: (actual: number, expected: number, delta: number, failureMessage?: string | undefined) => void;
|
|
72
|
+
isDefined: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is Exclude<Actual, undefined | null>;
|
|
73
|
+
isNullish: (input: unknown, failureMessage?: string | undefined) => asserts input is null | undefined;
|
|
74
|
+
isLengthAtLeast: {
|
|
75
|
+
<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is import("@augment-vir/core").AtLeastTuple<Element, Length>;
|
|
76
|
+
(actual: string | import("@augment-vir/core").AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
77
|
+
};
|
|
78
|
+
isLengthExactly: {
|
|
79
|
+
<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is import("@augment-vir/core").Tuple<Element, Length>;
|
|
80
|
+
(actual: string | import("@augment-vir/core").AnyObject, length: number, failureMessage?: string | undefined): void;
|
|
81
|
+
};
|
|
82
|
+
isKeyOf: <const Parent>(key: PropertyKey, parent: Parent, failureMessage?: string | undefined) => asserts key is keyof Parent;
|
|
83
|
+
isNotKeyOf: <const Key extends PropertyKey, const Parent>(key: Key, parent: Parent, failureMessage?: string | undefined) => asserts key is Exclude<Key, import("@augment-vir/core").RequiredKeysOf<Parent>>;
|
|
84
|
+
hasKey: <const Key extends PropertyKey, const Parent>(parent: Parent, key: Key, failureMessage?: string | undefined) => asserts parent is Parent & Record<Key, (Key extends keyof Parent ? import("@augment-vir/core").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("@augment-vir/core").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never) extends never ? unknown : Key extends keyof Parent ? import("@augment-vir/core").SetRequired<Parent, Key>[Key] : Key extends keyof Extract<Parent, Record<Key, any>> ? import("@augment-vir/core").SetRequired<Extract<Parent, Record<Key, any>>, Key>[Key] : never>;
|
|
85
|
+
lacksKey: <const Parent, const Key extends PropertyKey>(parent: Parent, key: Key, failureMessage?: string | undefined) => asserts parent is Exclude<Parent, Record<Key, any>>;
|
|
86
|
+
hasKeys: <const Keys extends PropertyKey, const Parent>(parent: Parent, keys: ReadonlyArray<Keys>, failureMessage?: string | undefined) => asserts parent is Parent & Record<Keys, (Keys extends keyof Parent ? import("@augment-vir/core").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("@augment-vir/core").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never) extends never ? unknown : Keys extends keyof Parent ? import("@augment-vir/core").SetRequired<Parent, Keys>[Keys] : Keys extends keyof Extract<Parent, Record<Keys, any>> ? import("@augment-vir/core").SetRequired<Extract<Parent, Record<Keys, any>>, Keys>[Keys] : never>;
|
|
87
|
+
lacksKeys: <const Parent, const Key extends PropertyKey>(parent: Parent, keys: ReadonlyArray<Key>, failureMessage?: string | undefined) => asserts parent is Exclude<Parent, Partial<Record<Key, any>>>;
|
|
88
|
+
jsonEquals: <const Actual, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => asserts actual is Expected;
|
|
89
|
+
notJsonEquals: (actual: unknown, expected: unknown, failureMessage?: string | undefined) => void;
|
|
90
|
+
instanceOf: <const Instance>(instance: unknown, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => asserts instance is Instance;
|
|
91
|
+
notInstanceOf: <const Actual, const Instance>(instance: Actual, constructor: import("type-fest").Constructor<Instance>, failureMessage?: string | undefined) => asserts instance is Exclude<Actual, Instance>;
|
|
92
|
+
isEnumValue: typeof import("../../assertions/enum.js").isEnumValue;
|
|
93
|
+
isNotEnumValue: <const Actual, const Expected extends import("@augment-vir/core").EnumBaseType>(child: Actual, checkEnum: Expected, failureMessage?: string | undefined) => asserts child is Exclude<Actual, Expected[keyof Expected] | `${Expected[keyof Expected]}`>;
|
|
94
|
+
entriesEqual: <const Actual extends object, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => asserts actual is Expected;
|
|
95
|
+
notEntriesEqual: (actual: object, expected: object, failureMessage?: string | undefined) => void;
|
|
96
|
+
endsWith: {
|
|
97
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
98
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
99
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
100
|
+
};
|
|
101
|
+
endsWithout: {
|
|
102
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
103
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
104
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
105
|
+
};
|
|
106
|
+
startsWith: {
|
|
107
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
108
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
109
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
110
|
+
};
|
|
111
|
+
startsWithout: {
|
|
112
|
+
<const ArrayElement>(parent: ReadonlyArray<ArrayElement>, child: ArrayElement, failureMessage?: string | undefined): void;
|
|
113
|
+
(parent: string, child: string, failureMessage?: string | undefined): void;
|
|
114
|
+
(parent: string | ReadonlyArray<string>, child: string, failureMessage?: string | undefined): void;
|
|
115
|
+
};
|
|
116
|
+
isFalsy: (input: unknown, failureMessage?: string | undefined) => asserts input is import("../assertion-exports.js").FalsyValue;
|
|
117
|
+
isTruthy: <const Actual>(input: Actual, failureMessage?: string | undefined) => asserts input is import("../assertion-exports.js").Truthy<Actual>;
|
|
118
|
+
isTrue: (input: unknown, failureMessage?: string | undefined) => asserts input is true;
|
|
119
|
+
isFalse: (input: unknown, failureMessage?: string | undefined) => asserts input is false;
|
|
120
|
+
tsType: {
|
|
121
|
+
<Actual>(input: Actual): {
|
|
122
|
+
equals: {
|
|
123
|
+
<Expected extends import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
124
|
+
<Expected extends import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
125
|
+
};
|
|
126
|
+
notEquals: {
|
|
127
|
+
<Expected>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
128
|
+
<Expected>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
129
|
+
};
|
|
130
|
+
matches: {
|
|
131
|
+
<Expected extends import("expect-type").Extends<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, true>): true;
|
|
132
|
+
<Expected extends import("expect-type").Extends<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, true>): true;
|
|
133
|
+
};
|
|
134
|
+
notMatches: {
|
|
135
|
+
<Expected>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, false>): true;
|
|
136
|
+
<Expected>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, false>): true;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
<Actual>(): {
|
|
140
|
+
equals: {
|
|
141
|
+
<Expected extends import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
142
|
+
<Expected extends import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
143
|
+
};
|
|
144
|
+
notEquals: {
|
|
145
|
+
<Expected>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
146
|
+
<Expected>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
147
|
+
};
|
|
148
|
+
matches: {
|
|
149
|
+
<Expected extends import("expect-type").Extends<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, true>): true;
|
|
150
|
+
<Expected extends import("expect-type").Extends<Actual, Expected> extends true ? unknown : import("expect-type").MismatchInfo<Actual, Expected>>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, true>): true;
|
|
151
|
+
};
|
|
152
|
+
notMatches: {
|
|
153
|
+
<Expected>(value: Expected & import("expect-type").AValue, ...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, false>): true;
|
|
154
|
+
<Expected>(...MISMATCH: import("expect-type").MismatchArgs<import("expect-type").Extends<Actual, Expected>, false>): true;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* A group of guard methods that assert their conditions and do nothing else.
|
|
161
|
+
*
|
|
162
|
+
* @category Assert
|
|
163
|
+
* @example
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* import {assert} from '@augment-vir/assert';
|
|
167
|
+
*
|
|
168
|
+
* const value: unknown = 'some value' as unknown;
|
|
169
|
+
* assert.isString(value);
|
|
170
|
+
* // `value` will now be typed as a `string`
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @throws {@link AssertionError} When the assertion fails.
|
|
174
|
+
* @package @augment-vir/assert
|
|
175
|
+
*/
|
|
176
|
+
export declare const assert: ((input: unknown, failureMessage?: string | undefined) => void) & typeof allAssertions & Record<keyof AnyFunction, never>;
|
|
177
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { tsTypeGuards } from '../../assertions/equality/ts-type-equality.js';
|
|
2
|
+
import { extendableAssertions } from '../../assertions/extendable-assertions.js';
|
|
3
|
+
import { AssertionError } from '../assertion.error.js';
|
|
4
|
+
const allAssertions = {
|
|
5
|
+
...tsTypeGuards.assertions,
|
|
6
|
+
...extendableAssertions,
|
|
7
|
+
fail(failureMessage) {
|
|
8
|
+
throw new AssertionError('Failure triggered.', failureMessage);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A group of guard methods that assert their conditions and do nothing else.
|
|
13
|
+
*
|
|
14
|
+
* @category Assert
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {assert} from '@augment-vir/assert';
|
|
19
|
+
*
|
|
20
|
+
* const value: unknown = 'some value' as unknown;
|
|
21
|
+
* assert.isString(value);
|
|
22
|
+
* // `value` will now be typed as a `string`
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @throws {@link AssertionError} When the assertion fails.
|
|
26
|
+
* @package @augment-vir/assert
|
|
27
|
+
*/
|
|
28
|
+
export const assert = Object.assign((input, failureMessage) => {
|
|
29
|
+
if (!input) {
|
|
30
|
+
throw new AssertionError('Assertion failed.', failureMessage);
|
|
31
|
+
}
|
|
32
|
+
}, allAssertions);
|