@luolapeikko/standard-schema-result
v0.0.2
Published
Rust style result type for standard schema validation
Maintainers
Readme
@luolapeikko/standard-schema-result
Use standard schema validation with result types. This package provides utility functions to validate data against schemas and return results in a consistent format, making error handling easier and more predictable. Supports both synchronous and asynchronous validation, and is compatible with popular schema validation libraries like ArkType , Zod and Valibot.
Install
npm i @luolapeikko/standard-schema-result @standard-schema/spec @standard-schema/utils @luolapeikko/result-option --save
Usage
import { Std } from "@luolapeikko/standard-schema-result";
const email = Std.Result(zod.email(), "[email protected]"); // Ok('[email protected]')
const invalidEmail = Std.Result(zod.email(), "not-an-email"); // Err(SchemaError)import { Std } from "@luolapeikko/standard-schema-result";
const validateEmail = Std.ResultFn(zod.email());
const email = validateEmail("[email protected]"); // Ok('[email protected]')
const invalidEmail = validateEmail("not-an-email"); // Err(SchemaError)import { Std } from "@luolapeikko/standard-schema-result";
const email = await Std.ResultAsync(zod.email(), "[email protected]"); // Ok('[email protected]')
const invalidEmail = await Std.ResultAsync(zod.email(), "not-an-email"); // Err(SchemaError)import { Std } from "@luolapeikko/standard-schema-result";
const validateEmail = Std.ResultAsyncFn(zod.email());
const email = await validateEmail("[email protected]"); // Ok('[email protected]')
const invalidEmail = await validateEmail("not-an-email"); // Err(SchemaError)