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}`);