is-kit 1.1.13 → 1.2.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/README.md +1 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +9 -0
- package/dist/index.mjs +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,7 +162,7 @@ isInfiniteNumber(1); // false
|
|
|
162
162
|
- **Define once**: `define<T>(fn)` turns a plain function into a type guard.
|
|
163
163
|
- **Upgrade predicates**: `predicateToRefine(fn)` adds narrowing.
|
|
164
164
|
- **Compose freely**: `and`, `or`, `not`, `oneOf`, `arrayOf`, `struct` …
|
|
165
|
-
- **Stay ergonomic**: helpers like `nullable`, `optional`, `equals`, `safeParse`, `hasKey`, `narrowKeyTo`.
|
|
165
|
+
- **Stay ergonomic**: helpers like `nullable`, `optional`, `equals`, `safeParse`, `assert`, `hasKey`, `narrowKeyTo`.
|
|
166
166
|
|
|
167
167
|
### Key Helpers
|
|
168
168
|
|
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,17 @@ declare function define<T>(fn: (value: unknown) => boolean): Predicate<T>;
|
|
|
40
40
|
*/
|
|
41
41
|
declare const predicateToRefine: <A>(fn: (value: A) => boolean) => Refine<A, A>;
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Asserts that a value satisfies a guard or refinement, otherwise throws.
|
|
45
|
+
*
|
|
46
|
+
* @param guard Guard/refinement to evaluate.
|
|
47
|
+
* @param value Value to assert.
|
|
48
|
+
* @param message Optional error message when assertion fails.
|
|
49
|
+
* @returns Nothing when assertion passes; throws an `Error` on failure.
|
|
50
|
+
*/
|
|
51
|
+
declare function assert<T>(guard: Guard<T>, value: unknown, message?: string): asserts value is T;
|
|
52
|
+
declare function assert<A, B extends A>(refine: Refine<A, B>, value: A, message?: string): asserts value is B;
|
|
53
|
+
|
|
43
54
|
/**
|
|
44
55
|
* Combines a precondition guard with an additional refinement to narrow the type.
|
|
45
56
|
*
|
|
@@ -480,4 +491,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
480
491
|
*/
|
|
481
492
|
declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
|
|
482
493
|
|
|
483
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
|
494
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,17 @@ declare function define<T>(fn: (value: unknown) => boolean): Predicate<T>;
|
|
|
40
40
|
*/
|
|
41
41
|
declare const predicateToRefine: <A>(fn: (value: A) => boolean) => Refine<A, A>;
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Asserts that a value satisfies a guard or refinement, otherwise throws.
|
|
45
|
+
*
|
|
46
|
+
* @param guard Guard/refinement to evaluate.
|
|
47
|
+
* @param value Value to assert.
|
|
48
|
+
* @param message Optional error message when assertion fails.
|
|
49
|
+
* @returns Nothing when assertion passes; throws an `Error` on failure.
|
|
50
|
+
*/
|
|
51
|
+
declare function assert<T>(guard: Guard<T>, value: unknown, message?: string): asserts value is T;
|
|
52
|
+
declare function assert<A, B extends A>(refine: Refine<A, B>, value: A, message?: string): asserts value is B;
|
|
53
|
+
|
|
43
54
|
/**
|
|
44
55
|
* Combines a precondition guard with an additional refinement to narrow the type.
|
|
45
56
|
*
|
|
@@ -480,4 +491,4 @@ declare function narrowKeyTo<A, K extends keyof A>(guard: Guard<A>, key: K): <co
|
|
|
480
491
|
*/
|
|
481
492
|
declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
|
|
482
493
|
|
|
483
|
-
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
|
494
|
+
export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, guardIn, hasKey, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, struct, toBooleanPredicates, tupleOf };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
and: () => and,
|
|
24
24
|
andAll: () => andAll,
|
|
25
25
|
arrayOf: () => arrayOf,
|
|
26
|
+
assert: () => assert,
|
|
26
27
|
define: () => define,
|
|
27
28
|
equals: () => equals,
|
|
28
29
|
equalsBy: () => equalsBy,
|
|
@@ -93,6 +94,13 @@ function define(fn) {
|
|
|
93
94
|
// src/core/predicate.ts
|
|
94
95
|
var predicateToRefine = (fn) => (value) => fn(value);
|
|
95
96
|
|
|
97
|
+
// src/core/assert.ts
|
|
98
|
+
var DEFAULT_ASSERT_MESSAGE = "Assertion failed";
|
|
99
|
+
function assert(fn, value, message) {
|
|
100
|
+
if (fn(value)) return;
|
|
101
|
+
throw new Error(message ?? DEFAULT_ASSERT_MESSAGE);
|
|
102
|
+
}
|
|
103
|
+
|
|
96
104
|
// src/utils/to-boolean-predicates.ts
|
|
97
105
|
var toBooleanPredicates = (predicates) => predicates;
|
|
98
106
|
|
|
@@ -394,6 +402,7 @@ function narrowKeyTo(guard, key) {
|
|
|
394
402
|
and,
|
|
395
403
|
andAll,
|
|
396
404
|
arrayOf,
|
|
405
|
+
assert,
|
|
397
406
|
define,
|
|
398
407
|
equals,
|
|
399
408
|
equalsBy,
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,13 @@ function define(fn) {
|
|
|
6
6
|
// src/core/predicate.ts
|
|
7
7
|
var predicateToRefine = (fn) => (value) => fn(value);
|
|
8
8
|
|
|
9
|
+
// src/core/assert.ts
|
|
10
|
+
var DEFAULT_ASSERT_MESSAGE = "Assertion failed";
|
|
11
|
+
function assert(fn, value, message) {
|
|
12
|
+
if (fn(value)) return;
|
|
13
|
+
throw new Error(message ?? DEFAULT_ASSERT_MESSAGE);
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
// src/utils/to-boolean-predicates.ts
|
|
10
17
|
var toBooleanPredicates = (predicates) => predicates;
|
|
11
18
|
|
|
@@ -306,6 +313,7 @@ export {
|
|
|
306
313
|
and,
|
|
307
314
|
andAll,
|
|
308
315
|
arrayOf,
|
|
316
|
+
assert,
|
|
309
317
|
define,
|
|
310
318
|
equals,
|
|
311
319
|
equalsBy,
|