ensure()
ensure<
T>(schema,input):Result<T,string>
Parses a value against a Kanon schema and returns a Zygos Result.
Bridge between Kanon validation and Zygos error handling:
instead of checking result.success, you get a chainable Result<T, string>.
Type Parameters
T: T
The expected output type of the schema.
Parameters
schema: Schema<T>
Kanon schema to validate against.
input: unknown
Value to validate.
Returns: Result<T, string>
Ok<T> if validation succeeds, Err<string> otherwise.
Since
2.1.0
Example
import { ensure } from "pithos/bridges/ensure";
import { object, string, number } from "pithos/kanon";
const schema = object({ name: string(), age: number() });
ensure(schema, data)
.map(user => user.name.toUpperCase())
.mapErr(error => `Validation failed: ${error}`);