bupkis 0.2.0 → 0.4.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/CHANGELOG.md +27 -0
- package/README.md +35 -11
- package/dist/commonjs/assertion/assertion-async.d.ts +2 -1
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-async.js +84 -2
- package/dist/commonjs/assertion/assertion-async.js.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.js +5 -1
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
- package/dist/commonjs/assertion/assertion-types.d.ts +6 -2
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.d.ts +1 -1
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.js +1 -14
- package/dist/commonjs/assertion/assertion.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +122 -21
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +118 -90
- package/dist/commonjs/assertion/impl/async.js.map +1 -1
- package/dist/commonjs/assertion/impl/callback.d.ts +104 -0
- package/dist/commonjs/assertion/impl/callback.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/callback.js +694 -0
- package/dist/commonjs/assertion/impl/callback.js.map +1 -0
- package/dist/commonjs/assertion/impl/index.d.ts +1 -1
- package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/index.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.js +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.d.ts +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.js +3 -3
- package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +22 -28
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +35 -50
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +68 -30
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync.js +4 -1
- package/dist/commonjs/assertion/impl/sync.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +147 -52
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +2 -3
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/constant.d.ts +1 -1
- package/dist/commonjs/constant.d.ts.map +1 -1
- package/dist/commonjs/constant.js +8 -1
- package/dist/commonjs/constant.js.map +1 -1
- package/dist/commonjs/error.d.ts +22 -2
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +44 -4
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +1 -1
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +96 -5
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +104 -25
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +146 -51
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/schema.d.ts +84 -18
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +107 -22
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/types.d.ts +171 -9
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/use.d.ts.map +1 -1
- package/dist/commonjs/use.js +15 -1
- package/dist/commonjs/use.js.map +1 -1
- package/dist/commonjs/util.d.ts +66 -50
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +169 -156
- package/dist/commonjs/util.js.map +1 -1
- package/dist/commonjs/value-to-schema.d.ts +122 -0
- package/dist/commonjs/value-to-schema.d.ts.map +1 -0
- package/dist/commonjs/value-to-schema.js +329 -0
- package/dist/commonjs/value-to-schema.js.map +1 -0
- package/dist/esm/assertion/assertion-async.d.ts +2 -1
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-async.js +85 -3
- package/dist/esm/assertion/assertion-async.js.map +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-sync.js +6 -2
- package/dist/esm/assertion/assertion-sync.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +6 -2
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +1 -1
- package/dist/esm/assertion/assertion.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.js +1 -14
- package/dist/esm/assertion/assertion.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +122 -21
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +118 -90
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/callback.d.ts +104 -0
- package/dist/esm/assertion/impl/callback.d.ts.map +1 -0
- package/dist/esm/assertion/impl/callback.js +691 -0
- package/dist/esm/assertion/impl/callback.js.map +1 -0
- package/dist/esm/assertion/impl/index.d.ts +1 -1
- package/dist/esm/assertion/impl/index.d.ts.map +1 -1
- package/dist/esm/assertion/impl/index.js +1 -1
- package/dist/esm/assertion/impl/index.js.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.js +2 -2
- package/dist/esm/assertion/impl/sync-basic.js.map +1 -1
- package/dist/esm/assertion/impl/sync-collection.d.ts +1 -1
- package/dist/esm/assertion/impl/sync-collection.js +3 -3
- package/dist/esm/assertion/impl/sync-collection.js.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.js +2 -2
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +22 -28
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +36 -51
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +68 -30
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync.js +3 -1
- package/dist/esm/assertion/impl/sync.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +147 -52
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +1 -2
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/constant.d.ts +1 -1
- package/dist/esm/constant.d.ts.map +1 -1
- package/dist/esm/constant.js +7 -0
- package/dist/esm/constant.js.map +1 -1
- package/dist/esm/error.d.ts +22 -2
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +43 -4
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +2 -2
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +96 -5
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +98 -21
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +146 -51
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schema.d.ts +84 -18
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +107 -22
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/types.d.ts +171 -9
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/use.d.ts.map +1 -1
- package/dist/esm/use.js +15 -1
- package/dist/esm/use.js.map +1 -1
- package/dist/esm/util.d.ts +66 -50
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +153 -154
- package/dist/esm/util.js.map +1 -1
- package/dist/esm/value-to-schema.d.ts +122 -0
- package/dist/esm/value-to-schema.d.ts.map +1 -0
- package/dist/esm/value-to-schema.js +325 -0
- package/dist/esm/value-to-schema.js.map +1 -0
- package/package.json +16 -13
- package/src/assertion/assertion-async.ts +113 -3
- package/src/assertion/assertion-sync.ts +5 -2
- package/src/assertion/assertion-types.ts +14 -4
- package/src/assertion/assertion.ts +2 -17
- package/src/assertion/impl/async.ts +137 -93
- package/src/assertion/impl/callback.ts +882 -0
- package/src/assertion/impl/index.ts +1 -1
- package/src/assertion/impl/sync-basic.ts +5 -2
- package/src/assertion/impl/sync-collection.ts +3 -3
- package/src/assertion/impl/sync-esoteric.ts +2 -2
- package/src/assertion/impl/sync-parametric.ts +47 -54
- package/src/assertion/impl/sync.ts +3 -0
- package/src/bootstrap.ts +1 -2
- package/src/constant.ts +10 -0
- package/src/error.ts +57 -3
- package/src/expect.ts +6 -2
- package/src/guards.ts +125 -18
- package/src/index.ts +3 -0
- package/src/schema.ts +121 -23
- package/src/types.ts +205 -10
- package/src/use.ts +22 -0
- package/src/util.ts +168 -223
- package/src/value-to-schema.ts +489 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EASvB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KA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AAC,EAAE,CAAC,CAAC,CAAC;AAC9E,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,EAC5B,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
package/dist/commonjs/expect.js
CHANGED
|
@@ -311,7 +311,7 @@ const detectNegation = (phrase) => {
|
|
|
311
311
|
};
|
|
312
312
|
};
|
|
313
313
|
const fail = (reason) => {
|
|
314
|
-
throw new error_js_1.
|
|
314
|
+
throw new error_js_1.FailAssertionError({ message: reason });
|
|
315
315
|
};
|
|
316
316
|
function createBaseExpect(syncAssertions, asyncAssertions, type) {
|
|
317
317
|
return type === 'sync'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;AA4KA,8DAgDC;AAgID,4DA+CC;AA4MD,4CAmBC;AA1mBD,kDAA0B;AAC1B,+BAA+B;AAgB/B,qDAA8E;AAC9E,yCAIoB;AACpB,2CAA2D;AAY3D,qCAAqC;AAErC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,eAAe,CAAC,CAAC;AAyErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,SAAgB,yBAAyB,CAGvC,UAAa,EAAE,MAAU;IACzB,KAAK,CACH,kDAAkD,EAClD,UAAU,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,CAAC,CAAC,CACrD,CAAC;IACF,MAAM,mBAAmB,GAAG,KAAK,EAAE,GAAG,IAAwB,EAAE,EAAE;QAChE,MAAM,OAAO,CAAC,OAAO,E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,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD;QACH,CAAC,CAAC;YACE,UAAU,EAAE,eAAe;YAC3B,eAAe,EAAf,2BAAe;YACf,oBAAoB,EAApB,gCAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD,CAAC;AACR,CAAC"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { type Primitive } from 'type-fest';
|
|
19
19
|
import { z } from 'zod/v4';
|
|
20
|
-
import type { Constructor } from './types.js';
|
|
20
|
+
import type { Constructor, ExpectItExecutor, ZodTypeMap } from './types.js';
|
|
21
21
|
/**
|
|
22
22
|
* Returns `true` if the given value looks like a Zod v4 schema, determined by
|
|
23
23
|
* the presence of an internal {@link z.core.$ZodTypeDef} field.
|
|
@@ -25,13 +25,31 @@ import type { Constructor } from './types.js';
|
|
|
25
25
|
* Note: This relies on Zod's internal shape and is intended for runtime
|
|
26
26
|
* discrimination within this library.
|
|
27
27
|
*
|
|
28
|
-
* @template T
|
|
28
|
+
* @template T - The specific ZodType to check for (based on def.type)
|
|
29
29
|
* @param value - Value to test
|
|
30
30
|
* @returns Whether the value is `ZodType`-like
|
|
31
31
|
*/
|
|
32
|
-
export declare
|
|
32
|
+
export declare function isZodType<T extends keyof ZodTypeMap>(value: unknown, type: T): value is ZodTypeMap[T];
|
|
33
33
|
/**
|
|
34
|
-
* Returns true if the given value
|
|
34
|
+
* Returns `true` if the given value looks like a Zod v4 schema, determined by
|
|
35
|
+
* the presence of an internal {@link z.core.$ZodTypeDef} field.
|
|
36
|
+
*
|
|
37
|
+
* Note: This relies on Zod's internal shape and is intended for runtime
|
|
38
|
+
* discrimination within this library.
|
|
39
|
+
*
|
|
40
|
+
* @param value - Value to test
|
|
41
|
+
* @returns Whether the value is `ZodType`-like
|
|
42
|
+
*/
|
|
43
|
+
export declare function isZodType(value: unknown): value is z.ZodType;
|
|
44
|
+
/**
|
|
45
|
+
* Type guard for a plain object.
|
|
46
|
+
*
|
|
47
|
+
* @param value Value to test
|
|
48
|
+
* @returns `true` if the value is a plain object, `false` otherwise
|
|
49
|
+
*/
|
|
50
|
+
export declare const isObject: (value: unknown) => value is NonNullable<object>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
35
53
|
*
|
|
36
54
|
* @param value - Value to test
|
|
37
55
|
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
@@ -59,7 +77,7 @@ export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unk
|
|
|
59
77
|
* @param fn - Function to test
|
|
60
78
|
* @returns Whether the function is constructable
|
|
61
79
|
*/
|
|
62
|
-
export declare const
|
|
80
|
+
export declare const isConstructible: (fn: unknown) => fn is Constructor;
|
|
63
81
|
/**
|
|
64
82
|
* Type guard for a boolean value
|
|
65
83
|
*
|
|
@@ -95,6 +113,79 @@ export declare const isNonNullObject: (value: unknown) => value is object;
|
|
|
95
113
|
* @returns `true` if the value is null or not an object, `false` otherwise
|
|
96
114
|
*/
|
|
97
115
|
export declare const isNullOrNonObject: (value: unknown) => value is null | Primitive;
|
|
116
|
+
/**
|
|
117
|
+
* Generic type guard for instanceof checks.
|
|
118
|
+
*
|
|
119
|
+
* This function provides a type-safe way to check if a value is an instance of
|
|
120
|
+
* a given constructor, with proper type narrowing for TypeScript. It combines
|
|
121
|
+
* the null/object check with instanceof to ensure the value is a valid object
|
|
122
|
+
* before performing the instance check.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const obj = new Date();
|
|
128
|
+
* if (isA(obj, Date)) {
|
|
129
|
+
* // obj is now typed as Date
|
|
130
|
+
* console.log(obj.getTime());
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @template T - The constructor type to check against
|
|
135
|
+
* @param value - Value to test
|
|
136
|
+
* @param ctor - Constructor function to check instanceof
|
|
137
|
+
* @returns `true` if the value is an instance of the constructor, `false`
|
|
138
|
+
* otherwise
|
|
139
|
+
*/
|
|
98
140
|
export declare const isA: <T extends Constructor>(value: unknown, ctor: T) => value is InstanceType<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Type guard for Error instances.
|
|
143
|
+
*
|
|
144
|
+
* This function checks if a value is an instance of the Error class or any of
|
|
145
|
+
* its subclasses. It's useful for error handling and type narrowing when
|
|
146
|
+
* working with unknown values that might be errors.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
*
|
|
150
|
+
* ```typescript
|
|
151
|
+
* try {
|
|
152
|
+
* throw new TypeError('Something went wrong');
|
|
153
|
+
* } catch (err) {
|
|
154
|
+
* if (isError(err)) {
|
|
155
|
+
* // err is now typed as Error
|
|
156
|
+
* console.log(err.message);
|
|
157
|
+
* }
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @param value - Value to test
|
|
162
|
+
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
163
|
+
*/
|
|
99
164
|
export declare const isError: (value: unknown) => value is Error;
|
|
165
|
+
/**
|
|
166
|
+
* Type guard for {@link ExpectItExecutor} functions.
|
|
167
|
+
*
|
|
168
|
+
* This function checks if a value is an {@link ExpectItExecutor} function
|
|
169
|
+
* created by {@link bupkis!expect.it | expect.it()}. {@link ExpectItExecutor}
|
|
170
|
+
* functions are special functions that contain assertion logic and are marked
|
|
171
|
+
* with an internal symbol for identification. They are used in nested
|
|
172
|
+
* assertions within "to satisfy" patterns and other complex assertion
|
|
173
|
+
* scenarios.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
*
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const executor = expect.it('to be a string');
|
|
179
|
+
* if (isExpectItExecutor(executor)) {
|
|
180
|
+
* // executor is now typed as ExpectItExecutor
|
|
181
|
+
* // Can be used in satisfaction patterns
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @template Subject - The subject type that the executor function operates on
|
|
186
|
+
* @param value - Value to test
|
|
187
|
+
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
188
|
+
* otherwise
|
|
189
|
+
*/
|
|
190
|
+
export declare const isExpectItExecutor: <Subject extends z.ZodType = z.ZodUnknown>(value: unknown) => value is ExpectItExecutor<Subject>;
|
|
100
191
|
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAO3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAO3B,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI5E;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,UAAU,EAClD,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,CAAC,GACN,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAC1B;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC;AAkB9D;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO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AC,CAAC,OAAO,GAAG,CAAC,CAAC,UAAU,EACzE,OAAO,OAAO,KACb,KAAK,IAAI,gBAAgB,CAAC,OAAO,CAEnC,CAAC"}
|
package/dist/commonjs/guards.js
CHANGED
|
@@ -17,33 +17,39 @@
|
|
|
17
17
|
* @packageDocumentation
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.isError = exports.isA = exports.isPhraseLiteral = exports.isPhraseLiteralChoice = exports.isNullOrNonObject = exports.isNonNullObject = exports.isString = exports.isAssertionFailure = exports.isFunction = exports.isBoolean = exports.
|
|
20
|
+
exports.isExpectItExecutor = exports.isError = exports.isA = exports.isPhraseLiteral = exports.isPhraseLiteralChoice = exports.isNullOrNonObject = exports.isNonNullObject = exports.isString = exports.isAssertionFailure = exports.isFunction = exports.isBoolean = exports.isConstructible = exports.isPromiseLike = exports.isZodPromise = exports.isObject = void 0;
|
|
21
|
+
exports.isZodType = isZodType;
|
|
21
22
|
const v4_1 = require("zod/v4");
|
|
23
|
+
const constant_js_1 = require("./constant.js");
|
|
24
|
+
function isZodType(value, type) {
|
|
25
|
+
const isValid = (0, exports.isObject)(value) &&
|
|
26
|
+
'def' in value &&
|
|
27
|
+
!!value.def &&
|
|
28
|
+
typeof value.def === 'object' &&
|
|
29
|
+
'type' in value.def;
|
|
30
|
+
if (!isValid)
|
|
31
|
+
return false;
|
|
32
|
+
if (type === undefined)
|
|
33
|
+
return true;
|
|
34
|
+
return value.def.type === type;
|
|
35
|
+
}
|
|
22
36
|
/**
|
|
23
|
-
*
|
|
24
|
-
* the presence of an internal {@link z.core.$ZodTypeDef} field.
|
|
37
|
+
* Type guard for a plain object.
|
|
25
38
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const isZodType = (value) => !!(value &&
|
|
34
|
-
typeof value === 'object' &&
|
|
35
|
-
'def' in value &&
|
|
36
|
-
value.def &&
|
|
37
|
-
typeof value.def === 'object' &&
|
|
38
|
-
'type' in value.def);
|
|
39
|
-
exports.isZodType = isZodType;
|
|
39
|
+
* @param value Value to test
|
|
40
|
+
* @returns `true` if the value is a plain object, `false` otherwise
|
|
41
|
+
*/
|
|
42
|
+
const isObject = (value) => {
|
|
43
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
44
|
+
};
|
|
45
|
+
exports.isObject = isObject;
|
|
40
46
|
/**
|
|
41
|
-
* Returns true if the given value is a {@link z.ZodPromise} schema.
|
|
47
|
+
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
42
48
|
*
|
|
43
49
|
* @param value - Value to test
|
|
44
50
|
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
45
51
|
*/
|
|
46
|
-
const isZodPromise = (value) =>
|
|
52
|
+
const isZodPromise = (value) => isZodType(value, 'promise');
|
|
47
53
|
exports.isZodPromise = isZodPromise;
|
|
48
54
|
/**
|
|
49
55
|
* Checks if a value is "promise-like", meaning it is a "thenable" object.
|
|
@@ -51,10 +57,7 @@ exports.isZodPromise = isZodPromise;
|
|
|
51
57
|
* @param value - Value to test
|
|
52
58
|
* @returns `true` if the value is promise-like, `false` otherwise
|
|
53
59
|
*/
|
|
54
|
-
const isPromiseLike = (value) =>
|
|
55
|
-
typeof value === 'object' &&
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
57
|
-
typeof value.then === 'function');
|
|
60
|
+
const isPromiseLike = (value) => (0, exports.isObject)(value) && 'then' in value && (0, exports.isFunction)(value.then);
|
|
58
61
|
exports.isPromiseLike = isPromiseLike;
|
|
59
62
|
/**
|
|
60
63
|
* Returns `true` if the given value is a constructable function (i.e., a
|
|
@@ -71,7 +74,7 @@ exports.isPromiseLike = isPromiseLike;
|
|
|
71
74
|
* @param fn - Function to test
|
|
72
75
|
* @returns Whether the function is constructable
|
|
73
76
|
*/
|
|
74
|
-
const
|
|
77
|
+
const isConstructible = (fn) => {
|
|
75
78
|
if (fn === Symbol || fn === BigInt) {
|
|
76
79
|
return false;
|
|
77
80
|
}
|
|
@@ -85,7 +88,7 @@ const isConstructable = (fn) => {
|
|
|
85
88
|
return false;
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
|
-
exports.
|
|
91
|
+
exports.isConstructible = isConstructible;
|
|
89
92
|
/**
|
|
90
93
|
* Type guard for a boolean value
|
|
91
94
|
*
|
|
@@ -168,10 +171,86 @@ exports.isPhraseLiteralChoice = isPhraseLiteralChoice;
|
|
|
168
171
|
*/
|
|
169
172
|
const isPhraseLiteral = (value) => (0, exports.isString)(value) && !value.startsWith('not ');
|
|
170
173
|
exports.isPhraseLiteral = isPhraseLiteral;
|
|
174
|
+
/**
|
|
175
|
+
* Generic type guard for instanceof checks.
|
|
176
|
+
*
|
|
177
|
+
* This function provides a type-safe way to check if a value is an instance of
|
|
178
|
+
* a given constructor, with proper type narrowing for TypeScript. It combines
|
|
179
|
+
* the null/object check with instanceof to ensure the value is a valid object
|
|
180
|
+
* before performing the instance check.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
*
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const obj = new Date();
|
|
186
|
+
* if (isA(obj, Date)) {
|
|
187
|
+
* // obj is now typed as Date
|
|
188
|
+
* console.log(obj.getTime());
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @template T - The constructor type to check against
|
|
193
|
+
* @param value - Value to test
|
|
194
|
+
* @param ctor - Constructor function to check instanceof
|
|
195
|
+
* @returns `true` if the value is an instance of the constructor, `false`
|
|
196
|
+
* otherwise
|
|
197
|
+
*/
|
|
171
198
|
const isA = (value, ctor) => {
|
|
172
199
|
return (0, exports.isNonNullObject)(value) && value instanceof ctor;
|
|
173
200
|
};
|
|
174
201
|
exports.isA = isA;
|
|
202
|
+
/**
|
|
203
|
+
* Type guard for Error instances.
|
|
204
|
+
*
|
|
205
|
+
* This function checks if a value is an instance of the Error class or any of
|
|
206
|
+
* its subclasses. It's useful for error handling and type narrowing when
|
|
207
|
+
* working with unknown values that might be errors.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
*
|
|
211
|
+
* ```typescript
|
|
212
|
+
* try {
|
|
213
|
+
* throw new TypeError('Something went wrong');
|
|
214
|
+
* } catch (err) {
|
|
215
|
+
* if (isError(err)) {
|
|
216
|
+
* // err is now typed as Error
|
|
217
|
+
* console.log(err.message);
|
|
218
|
+
* }
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @param value - Value to test
|
|
223
|
+
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
224
|
+
*/
|
|
175
225
|
const isError = (value) => (0, exports.isA)(value, Error);
|
|
176
226
|
exports.isError = isError;
|
|
227
|
+
/**
|
|
228
|
+
* Type guard for {@link ExpectItExecutor} functions.
|
|
229
|
+
*
|
|
230
|
+
* This function checks if a value is an {@link ExpectItExecutor} function
|
|
231
|
+
* created by {@link bupkis!expect.it | expect.it()}. {@link ExpectItExecutor}
|
|
232
|
+
* functions are special functions that contain assertion logic and are marked
|
|
233
|
+
* with an internal symbol for identification. They are used in nested
|
|
234
|
+
* assertions within "to satisfy" patterns and other complex assertion
|
|
235
|
+
* scenarios.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
*
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const executor = expect.it('to be a string');
|
|
241
|
+
* if (isExpectItExecutor(executor)) {
|
|
242
|
+
* // executor is now typed as ExpectItExecutor
|
|
243
|
+
* // Can be used in satisfaction patterns
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @template Subject - The subject type that the executor function operates on
|
|
248
|
+
* @param value - Value to test
|
|
249
|
+
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
250
|
+
* otherwise
|
|
251
|
+
*/
|
|
252
|
+
const isExpectItExecutor = (value) => {
|
|
253
|
+
return (0, exports.isFunction)(value) && constant_js_1.kExpectIt in value && value[constant_js_1.kExpectIt] === true;
|
|
254
|
+
};
|
|
255
|
+
exports.isExpectItExecutor = isExpectItExecutor;
|
|
177
256
|
//# sourceMappingURL=guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAwCH,8BAeC;AApDD,+BAA2B;AAS3B,+CAA0C;AA4B1C,SAAgB,SAAS,CACvB,KAAc,EACd,IAAQ;IAER,MAAM,OAAO,GACX,IAAA,gBAAQ,EAAC,KAAK,CAAC;QACf,KAAK,IAAI,KAAK;QACd,CAAC,CAAC,KAAK,CAAC,GAAG;QACX,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;QAC7B,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC;IAEtB,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEpC,OAAQ,KAAmB,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAgC,EAAE;IACvE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB;AAEF;;;;;GAKG;AACI,MAAM,YAAY,GAAG,CAAC,KAAc,EAAyB,EAAE,CACpE,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AADjB,QAAA,YA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