Skip to main content

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.