validation
constvalidation: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>โ ASafeParseResultwithsuccessflag 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 aSafeParseResult.
Sinceโ
2.0.0
Throwsโ
When validation fails.