bupkis 0.18.0 → 0.18.2
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 +14 -0
- package/package.json +1 -4
- package/src/assertion/assertion-types.ts +4 -4
- package/src/assertion/impl/async-parametric.ts +4 -21
- package/src/assertion/impl/sync-parametric.ts +5 -17
- package/src/expect.ts +0 -4
- package/src/guards.ts +24 -24
- package/src/internal-schema.ts +16 -32
- package/src/value-to-schema.ts +1 -1
- package/dist/assertion/assertion-async.cjs +0 -268
- package/dist/assertion/assertion-async.cjs.map +0 -1
- package/dist/assertion/assertion-async.d.cts +0 -40
- package/dist/assertion/assertion-async.d.cts.map +0 -1
- package/dist/assertion/assertion-async.d.ts +0 -40
- package/dist/assertion/assertion-async.d.ts.map +0 -1
- package/dist/assertion/assertion-async.js +0 -259
- package/dist/assertion/assertion-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
- package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.js +0 -128
- package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
- package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.js +0 -137
- package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
- package/dist/assertion/assertion-sync.cjs +0 -284
- package/dist/assertion/assertion-sync.cjs.map +0 -1
- package/dist/assertion/assertion-sync.d.cts +0 -60
- package/dist/assertion/assertion-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-sync.d.ts +0 -60
- package/dist/assertion/assertion-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-sync.js +0 -275
- package/dist/assertion/assertion-sync.js.map +0 -1
- package/dist/assertion/assertion-types.cjs +0 -20
- package/dist/assertion/assertion-types.cjs.map +0 -1
- package/dist/assertion/assertion-types.d.cts +0 -1086
- package/dist/assertion/assertion-types.d.cts.map +0 -1
- package/dist/assertion/assertion-types.d.ts +0 -1086
- package/dist/assertion/assertion-types.d.ts.map +0 -1
- package/dist/assertion/assertion-types.js +0 -19
- package/dist/assertion/assertion-types.js.map +0 -1
- package/dist/assertion/assertion.cjs +0 -382
- package/dist/assertion/assertion.cjs.map +0 -1
- package/dist/assertion/assertion.d.cts +0 -109
- package/dist/assertion/assertion.d.cts.map +0 -1
- package/dist/assertion/assertion.d.ts +0 -109
- package/dist/assertion/assertion.d.ts.map +0 -1
- package/dist/assertion/assertion.js +0 -375
- package/dist/assertion/assertion.js.map +0 -1
- package/dist/assertion/create.cjs +0 -148
- package/dist/assertion/create.cjs.map +0 -1
- package/dist/assertion/create.d.cts +0 -85
- package/dist/assertion/create.d.cts.map +0 -1
- package/dist/assertion/create.d.ts +0 -85
- package/dist/assertion/create.d.ts.map +0 -1
- package/dist/assertion/create.js +0 -143
- package/dist/assertion/create.js.map +0 -1
- package/dist/assertion/format-assertion-failure.cjs +0 -63
- package/dist/assertion/format-assertion-failure.cjs.map +0 -1
- package/dist/assertion/format-assertion-failure.d.cts +0 -21
- package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
- package/dist/assertion/format-assertion-failure.d.ts +0 -21
- package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
- package/dist/assertion/format-assertion-failure.js +0 -59
- package/dist/assertion/format-assertion-failure.js.map +0 -1
- package/dist/assertion/impl/assertion-util.cjs +0 -68
- package/dist/assertion/impl/assertion-util.cjs.map +0 -1
- package/dist/assertion/impl/assertion-util.d.cts +0 -36
- package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
- package/dist/assertion/impl/assertion-util.d.ts +0 -36
- package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
- package/dist/assertion/impl/assertion-util.js +0 -62
- package/dist/assertion/impl/assertion-util.js.map +0 -1
- package/dist/assertion/impl/async-iterable.cjs +0 -627
- package/dist/assertion/impl/async-iterable.cjs.map +0 -1
- package/dist/assertion/impl/async-iterable.d.cts +0 -406
- package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/async-iterable.d.ts +0 -406
- package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/async-iterable.js +0 -624
- package/dist/assertion/impl/async-iterable.js.map +0 -1
- package/dist/assertion/impl/async-parametric.cjs +0 -423
- package/dist/assertion/impl/async-parametric.cjs.map +0 -1
- package/dist/assertion/impl/async-parametric.d.cts +0 -278
- package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/async-parametric.d.ts +0 -278
- package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/async-parametric.js +0 -420
- package/dist/assertion/impl/async-parametric.js.map +0 -1
- package/dist/assertion/impl/async.cjs +0 -56
- package/dist/assertion/impl/async.cjs.map +0 -1
- package/dist/assertion/impl/async.d.cts +0 -179
- package/dist/assertion/impl/async.d.cts.map +0 -1
- package/dist/assertion/impl/async.d.ts +0 -179
- package/dist/assertion/impl/async.d.ts.map +0 -1
- package/dist/assertion/impl/async.js +0 -39
- package/dist/assertion/impl/async.js.map +0 -1
- package/dist/assertion/impl/index.cjs +0 -37
- package/dist/assertion/impl/index.cjs.map +0 -1
- package/dist/assertion/impl/index.d.cts +0 -21
- package/dist/assertion/impl/index.d.cts.map +0 -1
- package/dist/assertion/impl/index.d.ts +0 -21
- package/dist/assertion/impl/index.d.ts.map +0 -1
- package/dist/assertion/impl/index.js +0 -21
- package/dist/assertion/impl/index.js.map +0 -1
- package/dist/assertion/impl/iteration-util.cjs +0 -297
- package/dist/assertion/impl/iteration-util.cjs.map +0 -1
- package/dist/assertion/impl/iteration-util.d.cts +0 -12
- package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
- package/dist/assertion/impl/iteration-util.d.ts +0 -12
- package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
- package/dist/assertion/impl/iteration-util.js +0 -282
- package/dist/assertion/impl/iteration-util.js.map +0 -1
- package/dist/assertion/impl/snapshot.cjs +0 -276
- package/dist/assertion/impl/snapshot.cjs.map +0 -1
- package/dist/assertion/impl/snapshot.d.cts +0 -278
- package/dist/assertion/impl/snapshot.d.cts.map +0 -1
- package/dist/assertion/impl/snapshot.d.ts +0 -278
- package/dist/assertion/impl/snapshot.d.ts.map +0 -1
- package/dist/assertion/impl/snapshot.js +0 -273
- package/dist/assertion/impl/snapshot.js.map +0 -1
- package/dist/assertion/impl/sync-basic.cjs +0 -553
- package/dist/assertion/impl/sync-basic.cjs.map +0 -1
- package/dist/assertion/impl/sync-basic.d.cts +0 -528
- package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
- package/dist/assertion/impl/sync-basic.d.ts +0 -528
- package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
- package/dist/assertion/impl/sync-basic.js +0 -550
- package/dist/assertion/impl/sync-basic.js.map +0 -1
- package/dist/assertion/impl/sync-collection.cjs +0 -856
- package/dist/assertion/impl/sync-collection.cjs.map +0 -1
- package/dist/assertion/impl/sync-collection.d.cts +0 -607
- package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
- package/dist/assertion/impl/sync-collection.d.ts +0 -607
- package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
- package/dist/assertion/impl/sync-collection.js +0 -850
- package/dist/assertion/impl/sync-collection.js.map +0 -1
- package/dist/assertion/impl/sync-date.cjs +0 -341
- package/dist/assertion/impl/sync-date.cjs.map +0 -1
- package/dist/assertion/impl/sync-date.d.cts +0 -209
- package/dist/assertion/impl/sync-date.d.cts.map +0 -1
- package/dist/assertion/impl/sync-date.d.ts +0 -209
- package/dist/assertion/impl/sync-date.d.ts.map +0 -1
- package/dist/assertion/impl/sync-date.js +0 -338
- package/dist/assertion/impl/sync-date.js.map +0 -1
- package/dist/assertion/impl/sync-esoteric.cjs +0 -214
- package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.js +0 -211
- package/dist/assertion/impl/sync-esoteric.js.map +0 -1
- package/dist/assertion/impl/sync-iterable.cjs +0 -512
- package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.cts +0 -334
- package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.ts +0 -334
- package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/sync-iterable.js +0 -509
- package/dist/assertion/impl/sync-iterable.js.map +0 -1
- package/dist/assertion/impl/sync-parametric.cjs +0 -812
- package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.cts +0 -560
- package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.ts +0 -560
- package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-parametric.js +0 -809
- package/dist/assertion/impl/sync-parametric.js.map +0 -1
- package/dist/assertion/impl/sync.cjs +0 -214
- package/dist/assertion/impl/sync.cjs.map +0 -1
- package/dist/assertion/impl/sync.d.cts +0 -512
- package/dist/assertion/impl/sync.d.cts.map +0 -1
- package/dist/assertion/impl/sync.d.ts +0 -512
- package/dist/assertion/impl/sync.d.ts.map +0 -1
- package/dist/assertion/impl/sync.js +0 -197
- package/dist/assertion/impl/sync.js.map +0 -1
- package/dist/assertion/index.cjs +0 -38
- package/dist/assertion/index.cjs.map +0 -1
- package/dist/assertion/index.d.cts +0 -18
- package/dist/assertion/index.d.cts.map +0 -1
- package/dist/assertion/index.d.ts +0 -18
- package/dist/assertion/index.d.ts.map +0 -1
- package/dist/assertion/index.js +0 -17
- package/dist/assertion/index.js.map +0 -1
- package/dist/assertion/slotify.cjs +0 -165
- package/dist/assertion/slotify.cjs.map +0 -1
- package/dist/assertion/slotify.d.cts +0 -11
- package/dist/assertion/slotify.d.cts.map +0 -1
- package/dist/assertion/slotify.d.ts +0 -11
- package/dist/assertion/slotify.d.ts.map +0 -1
- package/dist/assertion/slotify.js +0 -161
- package/dist/assertion/slotify.js.map +0 -1
- package/dist/bootstrap.cjs +0 -43
- package/dist/bootstrap.cjs.map +0 -1
- package/dist/bootstrap.d.cts +0 -27
- package/dist/bootstrap.d.cts.map +0 -1
- package/dist/bootstrap.d.ts +0 -27
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -40
- package/dist/bootstrap.js.map +0 -1
- package/dist/constant.cjs +0 -82
- package/dist/constant.cjs.map +0 -1
- package/dist/constant.d.cts +0 -69
- package/dist/constant.d.cts.map +0 -1
- package/dist/constant.d.ts +0 -69
- package/dist/constant.d.ts.map +0 -1
- package/dist/constant.js +0 -79
- package/dist/constant.js.map +0 -1
- package/dist/diff.cjs +0 -340
- package/dist/diff.cjs.map +0 -1
- package/dist/diff.d.cts +0 -51
- package/dist/diff.d.cts.map +0 -1
- package/dist/diff.d.ts +0 -51
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js +0 -334
- package/dist/diff.js.map +0 -1
- package/dist/error.cjs +0 -204
- package/dist/error.cjs.map +0 -1
- package/dist/error.d.cts +0 -212
- package/dist/error.d.cts.map +0 -1
- package/dist/error.d.ts +0 -212
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -191
- package/dist/error.js.map +0 -1
- package/dist/expect.cjs +0 -590
- package/dist/expect.cjs.map +0 -1
- package/dist/expect.d.cts +0 -138
- package/dist/expect.d.cts.map +0 -1
- package/dist/expect.d.ts +0 -138
- package/dist/expect.d.ts.map +0 -1
- package/dist/expect.js +0 -582
- package/dist/expect.js.map +0 -1
- package/dist/guards.cjs +0 -297
- package/dist/guards.cjs.map +0 -1
- package/dist/guards.d.cts +0 -231
- package/dist/guards.d.cts.map +0 -1
- package/dist/guards.d.ts +0 -231
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -277
- package/dist/guards.js.map +0 -1
- package/dist/index.cjs +0 -111
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -448
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts +0 -448
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +0 -1
- package/dist/internal-schema.cjs +0 -253
- package/dist/internal-schema.cjs.map +0 -1
- package/dist/internal-schema.d.cts +0 -8
- package/dist/internal-schema.d.cts.map +0 -1
- package/dist/internal-schema.d.ts +0 -8
- package/dist/internal-schema.d.ts.map +0 -1
- package/dist/internal-schema.js +0 -248
- package/dist/internal-schema.js.map +0 -1
- package/dist/metadata.cjs +0 -57
- package/dist/metadata.cjs.map +0 -1
- package/dist/metadata.d.cts +0 -27
- package/dist/metadata.d.cts.map +0 -1
- package/dist/metadata.d.ts +0 -27
- package/dist/metadata.d.ts.map +0 -1
- package/dist/metadata.js +0 -54
- package/dist/metadata.js.map +0 -1
- package/dist/schema.cjs +0 -1522
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -1196
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -1196
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -1516
- package/dist/schema.js.map +0 -1
- package/dist/snapshot/adapter.cjs +0 -31
- package/dist/snapshot/adapter.cjs.map +0 -1
- package/dist/snapshot/adapter.d.cts +0 -258
- package/dist/snapshot/adapter.d.cts.map +0 -1
- package/dist/snapshot/adapter.d.ts +0 -258
- package/dist/snapshot/adapter.d.ts.map +0 -1
- package/dist/snapshot/adapter.js +0 -27
- package/dist/snapshot/adapter.js.map +0 -1
- package/dist/snapshot/adapters/fallback.cjs +0 -453
- package/dist/snapshot/adapters/fallback.cjs.map +0 -1
- package/dist/snapshot/adapters/fallback.d.cts +0 -185
- package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
- package/dist/snapshot/adapters/fallback.d.ts +0 -185
- package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
- package/dist/snapshot/adapters/fallback.js +0 -446
- package/dist/snapshot/adapters/fallback.js.map +0 -1
- package/dist/snapshot/adapters/node-test.cjs +0 -301
- package/dist/snapshot/adapters/node-test.cjs.map +0 -1
- package/dist/snapshot/adapters/node-test.d.cts +0 -131
- package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
- package/dist/snapshot/adapters/node-test.d.ts +0 -131
- package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
- package/dist/snapshot/adapters/node-test.js +0 -297
- package/dist/snapshot/adapters/node-test.js.map +0 -1
- package/dist/snapshot/index.cjs +0 -61
- package/dist/snapshot/index.cjs.map +0 -1
- package/dist/snapshot/index.d.cts +0 -40
- package/dist/snapshot/index.d.cts.map +0 -1
- package/dist/snapshot/index.d.ts +0 -40
- package/dist/snapshot/index.d.ts.map +0 -1
- package/dist/snapshot/index.js +0 -44
- package/dist/snapshot/index.js.map +0 -1
- package/dist/snapshot/node-version.cjs +0 -49
- package/dist/snapshot/node-version.cjs.map +0 -1
- package/dist/snapshot/node-version.d.cts +0 -34
- package/dist/snapshot/node-version.d.cts.map +0 -1
- package/dist/snapshot/node-version.d.ts +0 -34
- package/dist/snapshot/node-version.d.ts.map +0 -1
- package/dist/snapshot/node-version.js +0 -44
- package/dist/snapshot/node-version.js.map +0 -1
- package/dist/snapshot/select-adapter.cjs +0 -170
- package/dist/snapshot/select-adapter.cjs.map +0 -1
- package/dist/snapshot/select-adapter.d.cts +0 -128
- package/dist/snapshot/select-adapter.d.cts.map +0 -1
- package/dist/snapshot/select-adapter.d.ts +0 -128
- package/dist/snapshot/select-adapter.d.ts.map +0 -1
- package/dist/snapshot/select-adapter.js +0 -164
- package/dist/snapshot/select-adapter.js.map +0 -1
- package/dist/snapshot/serializer.cjs +0 -246
- package/dist/snapshot/serializer.cjs.map +0 -1
- package/dist/snapshot/serializer.d.cts +0 -126
- package/dist/snapshot/serializer.d.cts.map +0 -1
- package/dist/snapshot/serializer.d.ts +0 -126
- package/dist/snapshot/serializer.d.ts.map +0 -1
- package/dist/snapshot/serializer.js +0 -238
- package/dist/snapshot/serializer.js.map +0 -1
- package/dist/standard-schema.cjs +0 -13
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.d.cts +0 -192
- package/dist/standard-schema.d.cts.map +0 -1
- package/dist/standard-schema.d.ts +0 -192
- package/dist/standard-schema.d.ts.map +0 -1
- package/dist/standard-schema.js +0 -12
- package/dist/standard-schema.js.map +0 -1
- package/dist/types.cjs +0 -22
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -905
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -905
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -21
- package/dist/types.js.map +0 -1
- package/dist/use.cjs +0 -240
- package/dist/use.cjs.map +0 -1
- package/dist/use.d.cts +0 -8
- package/dist/use.d.cts.map +0 -1
- package/dist/use.d.ts +0 -8
- package/dist/use.d.ts.map +0 -1
- package/dist/use.js +0 -236
- package/dist/use.js.map +0 -1
- package/dist/util.cjs +0 -255
- package/dist/util.cjs.map +0 -1
- package/dist/util.d.cts +0 -141
- package/dist/util.d.cts.map +0 -1
- package/dist/util.d.ts +0 -141
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -234
- package/dist/util.js.map +0 -1
- package/dist/value-to-schema.cjs +0 -537
- package/dist/value-to-schema.cjs.map +0 -1
- package/dist/value-to-schema.d.cts +0 -144
- package/dist/value-to-schema.d.cts.map +0 -1
- package/dist/value-to-schema.d.ts +0 -144
- package/dist/value-to-schema.d.ts.map +0 -1
- package/dist/value-to-schema.js +0 -533
- package/dist/value-to-schema.js.map +0 -1
package/dist/guards.cjs
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Type guard functions and runtime type checking utilities.
|
|
4
|
-
*
|
|
5
|
-
* This module provides various type guard functions for runtime type checking,
|
|
6
|
-
* including guards for Zod schemas, constructors, {@link PromiseLike} objects,
|
|
7
|
-
* and assertion parts. These are used throughout the library for safe type
|
|
8
|
-
* narrowing and validation.
|
|
9
|
-
*
|
|
10
|
-
* @module guards
|
|
11
|
-
* @category API
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import * as guards from 'bupkis/guards';
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.isExpectItExecutor = exports.isError = exports.isA = exports.isPhrase = exports.isPhraseLiteralChoice = exports.isPhraseLiteral = exports.isWeakKey = exports.isNonNullObject = exports.isString = exports.isFunction = exports.isBoolean = exports.isConstructible = exports.isPromiseLike = exports.isZodPromise = exports.isObject = exports.isStandardSchema = void 0;
|
|
20
|
-
exports.isZodType = isZodType;
|
|
21
|
-
const constant_js_1 = require("./constant.cjs");
|
|
22
|
-
const { isArray } = Array;
|
|
23
|
-
function isZodType(value, type) {
|
|
24
|
-
const isValid = (0, exports.isObject)(value) &&
|
|
25
|
-
'def' in value &&
|
|
26
|
-
!!value.def &&
|
|
27
|
-
typeof value.def === 'object' &&
|
|
28
|
-
'type' in value.def;
|
|
29
|
-
if (!isValid) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (type === undefined) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
return value.def.type === type;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns `true` if the given value implements the Standard Schema v1
|
|
39
|
-
* interface.
|
|
40
|
-
*
|
|
41
|
-
* This guard checks for the presence of the `~standard` property with the
|
|
42
|
-
* required shape (version 1, vendor, validate function). It can detect any
|
|
43
|
-
* Standard Schema compliant library including Zod v4 (which implements the
|
|
44
|
-
* spec).
|
|
45
|
-
*
|
|
46
|
-
* @function
|
|
47
|
-
* @param value - Value to test
|
|
48
|
-
* @returns Whether the value is a Standard Schema v1 instance
|
|
49
|
-
* @see {@link https://standardschema.dev | Standard Schema Specification}
|
|
50
|
-
*/
|
|
51
|
-
const isStandardSchema = (value) => {
|
|
52
|
-
return ((0, exports.isObject)(value) &&
|
|
53
|
-
'~standard' in value &&
|
|
54
|
-
(0, exports.isObject)(value['~standard']) &&
|
|
55
|
-
'version' in value['~standard'] &&
|
|
56
|
-
value['~standard'].version === 1 &&
|
|
57
|
-
'vendor' in value['~standard'] &&
|
|
58
|
-
typeof value['~standard'].vendor === 'string' &&
|
|
59
|
-
'validate' in value['~standard'] &&
|
|
60
|
-
typeof value['~standard'].validate === 'function');
|
|
61
|
-
};
|
|
62
|
-
exports.isStandardSchema = isStandardSchema;
|
|
63
|
-
/**
|
|
64
|
-
* Type guard for a plain object.
|
|
65
|
-
*
|
|
66
|
-
* @function
|
|
67
|
-
* @param value Value to test
|
|
68
|
-
* @returns `true` if the value is a plain object, `false` otherwise
|
|
69
|
-
*/
|
|
70
|
-
const isObject = (value) => {
|
|
71
|
-
return typeof value === 'object' && value !== null && !isArray(value);
|
|
72
|
-
};
|
|
73
|
-
exports.isObject = isObject;
|
|
74
|
-
/**
|
|
75
|
-
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
76
|
-
*
|
|
77
|
-
* @function
|
|
78
|
-
* @param value - Value to test
|
|
79
|
-
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
80
|
-
*/
|
|
81
|
-
const isZodPromise = (value) => isZodType(value, 'promise');
|
|
82
|
-
exports.isZodPromise = isZodPromise;
|
|
83
|
-
/**
|
|
84
|
-
* Checks if a value is "promise-like", meaning it is a "thenable" object.
|
|
85
|
-
*
|
|
86
|
-
* @function
|
|
87
|
-
* @param value - Value to test
|
|
88
|
-
* @returns `true` if the value is promise-like, `false` otherwise
|
|
89
|
-
*/
|
|
90
|
-
const isPromiseLike = (value) => (0, exports.isObject)(value) &&
|
|
91
|
-
'then' in value &&
|
|
92
|
-
(0, exports.isFunction)(value.then) &&
|
|
93
|
-
value.then.length > 0;
|
|
94
|
-
exports.isPromiseLike = isPromiseLike;
|
|
95
|
-
/**
|
|
96
|
-
* Returns `true` if the given value is a constructable function (i.e., a
|
|
97
|
-
* class).
|
|
98
|
-
*
|
|
99
|
-
* This works by wrapping `fn` in a {@link Proxy}, attaching a no-op
|
|
100
|
-
* {@link ProxyHandler.construct} trap to it, then attempting to construct the
|
|
101
|
-
* proxy via `new`.
|
|
102
|
-
*
|
|
103
|
-
* @privateRemarks
|
|
104
|
-
* This may be the only way we can determine, at runtime, if a function is a
|
|
105
|
-
* constructor without actually calling it. I am unsure if this only works for
|
|
106
|
-
* classes.
|
|
107
|
-
* @function
|
|
108
|
-
* @param fn - Function to test
|
|
109
|
-
* @returns Whether the function is constructable
|
|
110
|
-
*/
|
|
111
|
-
const isConstructible = (fn) => {
|
|
112
|
-
if (fn === Symbol || fn === BigInt) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
// this will throw if there is no `[[construct]]` slot.. or so I've heard.
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, custom/require-function-tag-in-arrow-functions
|
|
118
|
-
new new Proxy(fn, { construct: () => ({}) })();
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
exports.isConstructible = isConstructible;
|
|
126
|
-
/**
|
|
127
|
-
* Type guard for a boolean value
|
|
128
|
-
*
|
|
129
|
-
* @function
|
|
130
|
-
* @param value Value to check
|
|
131
|
-
* @returns `true` if the value is a boolean, `false` otherwise
|
|
132
|
-
*/
|
|
133
|
-
const isBoolean = (value) => typeof value === 'boolean';
|
|
134
|
-
exports.isBoolean = isBoolean;
|
|
135
|
-
/**
|
|
136
|
-
* Type guard for a function value
|
|
137
|
-
*
|
|
138
|
-
* @function
|
|
139
|
-
* @param value Value to check
|
|
140
|
-
* @returns `true` if the value is a function, `false` otherwise
|
|
141
|
-
*/
|
|
142
|
-
const isFunction = (value) => typeof value === 'function';
|
|
143
|
-
exports.isFunction = isFunction;
|
|
144
|
-
/**
|
|
145
|
-
* Type guard for a string value
|
|
146
|
-
*
|
|
147
|
-
* @function
|
|
148
|
-
* @param value Value to check
|
|
149
|
-
* @returns `true` if the value is a string, `false` otherwise
|
|
150
|
-
*/
|
|
151
|
-
const isString = (value) => typeof value === 'string';
|
|
152
|
-
exports.isString = isString;
|
|
153
|
-
/**
|
|
154
|
-
* Type guard for a non-null object value
|
|
155
|
-
*
|
|
156
|
-
* @function
|
|
157
|
-
* @param value Value to check
|
|
158
|
-
* @returns `true` if the value is an object and not null, `false` otherwise
|
|
159
|
-
*/
|
|
160
|
-
const isNonNullObject = (value) => typeof value === 'object' && value !== null;
|
|
161
|
-
exports.isNonNullObject = isNonNullObject;
|
|
162
|
-
/**
|
|
163
|
-
* Type guard for a valid WeakKey (object, function, or symbol).
|
|
164
|
-
*
|
|
165
|
-
* WeakMaps and WeakSets can only use objects (including functions) or symbols
|
|
166
|
-
* as keys, not primitives like strings, numbers, booleans, null, or undefined.
|
|
167
|
-
*
|
|
168
|
-
* @function
|
|
169
|
-
* @param value Value to check
|
|
170
|
-
* @returns `true` if the value is a valid WeakKey (object, function, or
|
|
171
|
-
* symbol), `false` otherwise
|
|
172
|
-
*/
|
|
173
|
-
const isWeakKey = (value) => (typeof value === 'object' && value !== null) ||
|
|
174
|
-
typeof value === 'function' ||
|
|
175
|
-
typeof value === 'symbol';
|
|
176
|
-
exports.isWeakKey = isWeakKey;
|
|
177
|
-
/**
|
|
178
|
-
* Type guard for a {@link PhraseLiteral}, which is just a string that does not
|
|
179
|
-
* begin with `not `.
|
|
180
|
-
*
|
|
181
|
-
* @function
|
|
182
|
-
* @param value Value to check
|
|
183
|
-
* @returns `true` if the value is a `PhraseLiteral`, `false` otherwise
|
|
184
|
-
* @internal
|
|
185
|
-
*/
|
|
186
|
-
const isPhraseLiteral = (value) => (0, exports.isString)(value) && value !== 'and';
|
|
187
|
-
exports.isPhraseLiteral = isPhraseLiteral;
|
|
188
|
-
/**
|
|
189
|
-
* Type guard for a {@link PhraseLiteralChoice}, which is a tuple of strings.
|
|
190
|
-
*
|
|
191
|
-
* @function
|
|
192
|
-
* @param value Value to check
|
|
193
|
-
* @returns `true` if the value is a `PhraseLiteralChoice`, `false` otherwise
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
const isPhraseLiteralChoice = (value) => isArray(value) &&
|
|
197
|
-
value.length >= 1 &&
|
|
198
|
-
value.every((item) => (0, exports.isPhraseLiteral)(item));
|
|
199
|
-
exports.isPhraseLiteralChoice = isPhraseLiteralChoice;
|
|
200
|
-
/**
|
|
201
|
-
* Type guard for a {@link PhraseLiteral} or {@link PhraseLiteralChoice}.
|
|
202
|
-
*
|
|
203
|
-
* @function
|
|
204
|
-
* @param value Value to check
|
|
205
|
-
* @returns `true` if the value is a `PhraseLiteral` or `PhraseLiteralChoice`,
|
|
206
|
-
* `false` otherwise
|
|
207
|
-
*/
|
|
208
|
-
const isPhrase = (value) => (0, exports.isPhraseLiteral)(value) || (0, exports.isPhraseLiteralChoice)(value);
|
|
209
|
-
exports.isPhrase = isPhrase;
|
|
210
|
-
/**
|
|
211
|
-
* Generic type guard for instanceof checks.
|
|
212
|
-
*
|
|
213
|
-
* This function provides a type-safe way to check if a value is an instance of
|
|
214
|
-
* a given constructor, with proper type narrowing for TypeScript. It combines
|
|
215
|
-
* the null/object check with instanceof to ensure the value is a valid object
|
|
216
|
-
* before performing the instance check.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
*
|
|
220
|
-
* ```typescript
|
|
221
|
-
* const obj = new Date();
|
|
222
|
-
* if (isA(obj, Date)) {
|
|
223
|
-
* // obj is now typed as Date
|
|
224
|
-
* console.log(obj.getTime());
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* @template T - The constructor type to check against
|
|
229
|
-
* @function
|
|
230
|
-
* @param value - Value to test
|
|
231
|
-
* @param ctor - Constructor function to check instanceof
|
|
232
|
-
* @returns `true` if the value is an instance of the constructor, `false`
|
|
233
|
-
* otherwise
|
|
234
|
-
*/
|
|
235
|
-
const isA = (value, ctor) => {
|
|
236
|
-
return (0, exports.isNonNullObject)(value) && value instanceof ctor;
|
|
237
|
-
};
|
|
238
|
-
exports.isA = isA;
|
|
239
|
-
/**
|
|
240
|
-
* Type guard for Error instances.
|
|
241
|
-
*
|
|
242
|
-
* This function checks if a value is an instance of the Error class or any of
|
|
243
|
-
* its subclasses. It's useful for error handling and type narrowing when
|
|
244
|
-
* working with unknown values that might be errors.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
*
|
|
248
|
-
* ```typescript
|
|
249
|
-
* try {
|
|
250
|
-
* throw new TypeError('Something went wrong');
|
|
251
|
-
* } catch (err) {
|
|
252
|
-
* if (isError(err)) {
|
|
253
|
-
* // err is now typed as Error
|
|
254
|
-
* console.log(err.message);
|
|
255
|
-
* }
|
|
256
|
-
* }
|
|
257
|
-
* ```
|
|
258
|
-
*
|
|
259
|
-
* @function
|
|
260
|
-
* @param value - Value to test
|
|
261
|
-
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
262
|
-
*/
|
|
263
|
-
const isError = (value) => (0, exports.isA)(value, Error);
|
|
264
|
-
exports.isError = isError;
|
|
265
|
-
/**
|
|
266
|
-
* Type guard for {@link ExpectItExecutor} functions.
|
|
267
|
-
*
|
|
268
|
-
* This function checks if a value is an {@link ExpectItExecutor} function
|
|
269
|
-
* created by {@link bupkis!expect.it | expect.it()}. {@link ExpectItExecutor}
|
|
270
|
-
* functions are special functions that contain assertion logic and are marked
|
|
271
|
-
* with an internal symbol for identification. They are used in nested
|
|
272
|
-
* assertions within "to satisfy" patterns and other complex assertion
|
|
273
|
-
* scenarios.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
*
|
|
277
|
-
* ```typescript
|
|
278
|
-
* const executor = expect.it('to be a string');
|
|
279
|
-
* if (isExpectItExecutor(executor)) {
|
|
280
|
-
* // executor is now typed as ExpectItExecutor
|
|
281
|
-
* // Can be used in satisfaction patterns
|
|
282
|
-
* }
|
|
283
|
-
* ```
|
|
284
|
-
*
|
|
285
|
-
* @template Subject - The subject type that the executor function operates on
|
|
286
|
-
* @function
|
|
287
|
-
* @param value - Value to test
|
|
288
|
-
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
289
|
-
* otherwise
|
|
290
|
-
*/
|
|
291
|
-
const isExpectItExecutor = (value) => {
|
|
292
|
-
return ((0, exports.isFunction)(value) &&
|
|
293
|
-
constant_js_1.kExpectIt in value &&
|
|
294
|
-
value[constant_js_1.kExpectIt] === true);
|
|
295
|
-
};
|
|
296
|
-
exports.isExpectItExecutor = isExpectItExecutor;
|
|
297
|
-
//# sourceMappingURL=guards.js.map
|
package/dist/guards.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA4CH,8BAmBC;AAlDD,gDAA0C;AAE1C,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AA6B1B,SAAgB,SAAS,CACvB,KAAc,EACd,IAAQ;IAER,MAAM,OAAO,GACX,IAAA,gBAAQ,EAAC,K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C,KAAc,EAAkB,EAAE,CAAC,IAAA,WAAG,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAAhE,QAAA,OAAO,WAAyD;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,MAAM,kBAAkB,GAAG,CAChC,KAAc,EACsB,EAAE;IACtC,OAAO,CACL,IAAA,kBAAU,EAAC,KAAK,CAAC;QACjB,uBAAS,IAAI,KAAK;QACjB,KAA4C,CAAC,uBAAS,CAAC,KAAK,IAAI,CAClE,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B"}
|
package/dist/guards.d.cts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard functions and runtime type checking utilities.
|
|
3
|
-
*
|
|
4
|
-
* This module provides various type guard functions for runtime type checking,
|
|
5
|
-
* including guards for Zod schemas, constructors, {@link PromiseLike} objects,
|
|
6
|
-
* and assertion parts. These are used throughout the library for safe type
|
|
7
|
-
* narrowing and validation.
|
|
8
|
-
*
|
|
9
|
-
* @module guards
|
|
10
|
-
* @category API
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import * as guards from 'bupkis/guards';
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
import { type z } from 'zod';
|
|
18
|
-
import type { PhraseLiteralChoice } from "./assertion/assertion-types.cjs";
|
|
19
|
-
import type { StandardSchemaV1 } from "./standard-schema.cjs";
|
|
20
|
-
import type { Constructor, ExpectItExecutor, PhraseLiteral, ZodTypeMap } from "./types.cjs";
|
|
21
|
-
/**
|
|
22
|
-
* Returns `true` if the given value looks like a Zod v4 schema, determined by
|
|
23
|
-
* the presence of an internal {@link z.core.$ZodTypeDef} field.
|
|
24
|
-
*
|
|
25
|
-
* Note: This relies on Zod's internal shape and is intended for runtime
|
|
26
|
-
* discrimination within this library.
|
|
27
|
-
*
|
|
28
|
-
* @template T - The specific ZodType to check for (based on def.type)
|
|
29
|
-
* @param value - Value to test
|
|
30
|
-
* @returns Whether the value is `ZodType`-like
|
|
31
|
-
*/
|
|
32
|
-
export declare function isZodType<T extends keyof ZodTypeMap>(value: unknown, type: T): value is ZodTypeMap[T];
|
|
33
|
-
/**
|
|
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
|
-
* Returns `true` if the given value implements the Standard Schema v1
|
|
46
|
-
* interface.
|
|
47
|
-
*
|
|
48
|
-
* This guard checks for the presence of the `~standard` property with the
|
|
49
|
-
* required shape (version 1, vendor, validate function). It can detect any
|
|
50
|
-
* Standard Schema compliant library including Zod v4 (which implements the
|
|
51
|
-
* spec).
|
|
52
|
-
*
|
|
53
|
-
* @function
|
|
54
|
-
* @param value - Value to test
|
|
55
|
-
* @returns Whether the value is a Standard Schema v1 instance
|
|
56
|
-
* @see {@link https://standardschema.dev | Standard Schema Specification}
|
|
57
|
-
*/
|
|
58
|
-
export declare const isStandardSchema: (value: unknown) => value is StandardSchemaV1;
|
|
59
|
-
/**
|
|
60
|
-
* Type guard for a plain object.
|
|
61
|
-
*
|
|
62
|
-
* @function
|
|
63
|
-
* @param value Value to test
|
|
64
|
-
* @returns `true` if the value is a plain object, `false` otherwise
|
|
65
|
-
*/
|
|
66
|
-
export declare const isObject: (value: unknown) => value is NonNullable<object>;
|
|
67
|
-
/**
|
|
68
|
-
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
69
|
-
*
|
|
70
|
-
* @function
|
|
71
|
-
* @param value - Value to test
|
|
72
|
-
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
73
|
-
*/
|
|
74
|
-
export declare const isZodPromise: (value: unknown) => value is z.ZodPromise;
|
|
75
|
-
/**
|
|
76
|
-
* Checks if a value is "promise-like", meaning it is a "thenable" object.
|
|
77
|
-
*
|
|
78
|
-
* @function
|
|
79
|
-
* @param value - Value to test
|
|
80
|
-
* @returns `true` if the value is promise-like, `false` otherwise
|
|
81
|
-
*/
|
|
82
|
-
export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unknown>;
|
|
83
|
-
/**
|
|
84
|
-
* Returns `true` if the given value is a constructable function (i.e., a
|
|
85
|
-
* class).
|
|
86
|
-
*
|
|
87
|
-
* This works by wrapping `fn` in a {@link Proxy}, attaching a no-op
|
|
88
|
-
* {@link ProxyHandler.construct} trap to it, then attempting to construct the
|
|
89
|
-
* proxy via `new`.
|
|
90
|
-
*
|
|
91
|
-
* @privateRemarks
|
|
92
|
-
* This may be the only way we can determine, at runtime, if a function is a
|
|
93
|
-
* constructor without actually calling it. I am unsure if this only works for
|
|
94
|
-
* classes.
|
|
95
|
-
* @function
|
|
96
|
-
* @param fn - Function to test
|
|
97
|
-
* @returns Whether the function is constructable
|
|
98
|
-
*/
|
|
99
|
-
export declare const isConstructible: (fn: unknown) => fn is Constructor;
|
|
100
|
-
/**
|
|
101
|
-
* Type guard for a boolean value
|
|
102
|
-
*
|
|
103
|
-
* @function
|
|
104
|
-
* @param value Value to check
|
|
105
|
-
* @returns `true` if the value is a boolean, `false` otherwise
|
|
106
|
-
*/
|
|
107
|
-
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Type guard for a function value
|
|
110
|
-
*
|
|
111
|
-
* @function
|
|
112
|
-
* @param value Value to check
|
|
113
|
-
* @returns `true` if the value is a function, `false` otherwise
|
|
114
|
-
*/
|
|
115
|
-
export declare const isFunction: (value: unknown) => value is (...args: any[]) => any;
|
|
116
|
-
/**
|
|
117
|
-
* Type guard for a string value
|
|
118
|
-
*
|
|
119
|
-
* @function
|
|
120
|
-
* @param value Value to check
|
|
121
|
-
* @returns `true` if the value is a string, `false` otherwise
|
|
122
|
-
*/
|
|
123
|
-
export declare const isString: (value: unknown) => value is string;
|
|
124
|
-
/**
|
|
125
|
-
* Type guard for a non-null object value
|
|
126
|
-
*
|
|
127
|
-
* @function
|
|
128
|
-
* @param value Value to check
|
|
129
|
-
* @returns `true` if the value is an object and not null, `false` otherwise
|
|
130
|
-
*/
|
|
131
|
-
export declare const isNonNullObject: (value: unknown) => value is object;
|
|
132
|
-
/**
|
|
133
|
-
* Type guard for a valid WeakKey (object, function, or symbol).
|
|
134
|
-
*
|
|
135
|
-
* WeakMaps and WeakSets can only use objects (including functions) or symbols
|
|
136
|
-
* as keys, not primitives like strings, numbers, booleans, null, or undefined.
|
|
137
|
-
*
|
|
138
|
-
* @function
|
|
139
|
-
* @param value Value to check
|
|
140
|
-
* @returns `true` if the value is a valid WeakKey (object, function, or
|
|
141
|
-
* symbol), `false` otherwise
|
|
142
|
-
*/
|
|
143
|
-
export declare const isWeakKey: (value: unknown) => value is WeakKey;
|
|
144
|
-
/**
|
|
145
|
-
* Type guard for a {@link PhraseLiteral} or {@link PhraseLiteralChoice}.
|
|
146
|
-
*
|
|
147
|
-
* @function
|
|
148
|
-
* @param value Value to check
|
|
149
|
-
* @returns `true` if the value is a `PhraseLiteral` or `PhraseLiteralChoice`,
|
|
150
|
-
* `false` otherwise
|
|
151
|
-
*/
|
|
152
|
-
export declare const isPhrase: (value: unknown) => value is PhraseLiteral | PhraseLiteralChoice;
|
|
153
|
-
/**
|
|
154
|
-
* Generic type guard for instanceof checks.
|
|
155
|
-
*
|
|
156
|
-
* This function provides a type-safe way to check if a value is an instance of
|
|
157
|
-
* a given constructor, with proper type narrowing for TypeScript. It combines
|
|
158
|
-
* the null/object check with instanceof to ensure the value is a valid object
|
|
159
|
-
* before performing the instance check.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
*
|
|
163
|
-
* ```typescript
|
|
164
|
-
* const obj = new Date();
|
|
165
|
-
* if (isA(obj, Date)) {
|
|
166
|
-
* // obj is now typed as Date
|
|
167
|
-
* console.log(obj.getTime());
|
|
168
|
-
* }
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
* @template T - The constructor type to check against
|
|
172
|
-
* @function
|
|
173
|
-
* @param value - Value to test
|
|
174
|
-
* @param ctor - Constructor function to check instanceof
|
|
175
|
-
* @returns `true` if the value is an instance of the constructor, `false`
|
|
176
|
-
* otherwise
|
|
177
|
-
*/
|
|
178
|
-
export declare const isA: <T extends Constructor>(value: unknown, ctor: T) => value is InstanceType<T>;
|
|
179
|
-
/**
|
|
180
|
-
* Type guard for Error instances.
|
|
181
|
-
*
|
|
182
|
-
* This function checks if a value is an instance of the Error class or any of
|
|
183
|
-
* its subclasses. It's useful for error handling and type narrowing when
|
|
184
|
-
* working with unknown values that might be errors.
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
*
|
|
188
|
-
* ```typescript
|
|
189
|
-
* try {
|
|
190
|
-
* throw new TypeError('Something went wrong');
|
|
191
|
-
* } catch (err) {
|
|
192
|
-
* if (isError(err)) {
|
|
193
|
-
* // err is now typed as Error
|
|
194
|
-
* console.log(err.message);
|
|
195
|
-
* }
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*
|
|
199
|
-
* @function
|
|
200
|
-
* @param value - Value to test
|
|
201
|
-
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
202
|
-
*/
|
|
203
|
-
export declare const isError: (value: unknown) => value is Error;
|
|
204
|
-
/**
|
|
205
|
-
* Type guard for {@link ExpectItExecutor} functions.
|
|
206
|
-
*
|
|
207
|
-
* This function checks if a value is an {@link ExpectItExecutor} function
|
|
208
|
-
* created by {@link bupkis!expect.it | expect.it()}. {@link ExpectItExecutor}
|
|
209
|
-
* functions are special functions that contain assertion logic and are marked
|
|
210
|
-
* with an internal symbol for identification. They are used in nested
|
|
211
|
-
* assertions within "to satisfy" patterns and other complex assertion
|
|
212
|
-
* scenarios.
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
*
|
|
216
|
-
* ```typescript
|
|
217
|
-
* const executor = expect.it('to be a string');
|
|
218
|
-
* if (isExpectItExecutor(executor)) {
|
|
219
|
-
* // executor is now typed as ExpectItExecutor
|
|
220
|
-
* // Can be used in satisfaction patterns
|
|
221
|
-
* }
|
|
222
|
-
* ```
|
|
223
|
-
*
|
|
224
|
-
* @template Subject - The subject type that the executor function operates on
|
|
225
|
-
* @function
|
|
226
|
-
* @param value - Value to test
|
|
227
|
-
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
228
|
-
* otherwise
|
|
229
|
-
*/
|
|
230
|
-
export declare const isExpectItExecutor: <Subject extends z.ZodType = z.ZodUnknown>(value: unknown) => value is ExpectItExecutor<Subject>;
|
|
231
|
-
//# sourceMappingURL=guards.d.ts.map
|
package/dist/guards.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,wCAAuC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,8BAA6B;AAC7D,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,UAAU,EACX,oBAAmB;AAMpB;;;;;;;;;;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;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,OAAO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