Aller au contenu principal

validation

const validation: object

Kanon V3 lightweight validation helpers (Zod-like ergonomics, minimal surface).

Type Declaration

parse()

Parses a value and throws on failure.


Type Parameters

T: T

The expected output type.

schema: Schema<T> — The Kanon schema to validate against.
value: unknown — The value to validate.
Returns: T — The validated and possibly coerced value.

Since

2.0.0

safeParse()

Parses a value and returns a discriminated result.

Type Parameters

T: T

The expected output type.

schema: Schema<T> — The Kanon schema to validate against.
value: unknown — The value to validate.
Returns: SafeParseResult<T> — A SafeParseResult with success flag and data or error.

Since

2.0.0

parseAsync()

Async variant of parse, kept for API parity (logic stays sync).

Type Parameters

T: T

The expected output type.

schema: Schema<T> — The Kanon schema to validate against.
value: unknown — The value to validate.
Returns: Promise<T> — Promise resolving to the validated value.

Throws

When validation fails.

Since

2.0.0

safeParseAsync()

Async variant of safeParse, kept for API parity (logic stays sync).

Type Parameters

T: T

The expected output type.

schema: Schema<T> — The Kanon schema to validate against.
value: unknown — The value to validate.
Returns: Promise<SafeParseResult<T>> — Promise resolving to a SafeParseResult.

Since

2.0.0


Throws

When validation fails.