Loading docs…
Loading docs…
Wrap an existing guard for tools that accept the Standard Schema v1 specification. This common interface lets those tools validate values and infer input and output types without knowing about is-kit guards.
import { isString, toStandardSchema } from 'is-kit';const schema = toStandardSchema(isString);const success = schema['~standard'].validate('hello');// { value: 'hello' }const failure = schema['~standard'].validate(42);// { issues: [{ message: 'Invalid value' }] }type SchemaTypes = NonNullable<typeof schema['~standard']['types']>;type Input = SchemaTypes['input']; // stringtype Output = SchemaTypes['output']; // string
Validation is synchronous and returns the original value on success. A false result produces a generic issue without a field path. As with safeParse, exceptions thrown by the guard propagate unchanged.
Pass the adapter to a Standard Schema validator. The original guard remains available for ordinary narrowing, filtering, and composition; use the adapter at the interoperability boundary.
import { useForm } from '@tanstack/react-form';import { isString, struct, toStandardSchema } from 'is-kit';const isUser = struct({ name: isString });const userSchema = toStandardSchema(isUser);function useUserForm() {return useForm({defaultValues: { name: '' },validators: { onChange: userSchema },onSubmit: async ({ value }) => console.log(value),});}