Skip to content

Function: toStandardValidator()

ts
function toStandardValidator<T>(schema): FusionValidator<T>;

Defined in: packages/core/src/core/StandardSchema.ts:125

Create a FusionValidator from a Standard Schema v1 compatible schema.

This is the primary entry point for non-Zod validators. Any schema library implementing the Standard Schema spec can be used directly.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
schemaStandardSchemaV1<unknown, T>A Standard Schema v1 compatible schema

Returns

FusionValidator<T>

A FusionValidator wrapping the schema

Example

typescript
import * as v from 'valibot'; // ~1kb tree-shaken

const schema = v.object({ name: v.string() });
const validator = toStandardValidator(schema);

const ok = validator.validate({ name: 'Alice' });
// { success: true, data: { name: 'Alice' } }

const err = validator.validate({ name: 42 });
// { success: false, issues: [{ message: 'Expected string', path: ['name'] }] }