Standard Schema
Give any truefit schema the Standard Schema interface with standard() or standardAsync(), so it plugs into every library that accepts a validator through that interface.
Standard Schema is the interface a library uses to accept any
validator: one ~standard property with a validate function. Libraries such as tRPC and TanStack Form,
which once took only a zod schema, take any schema that has it.
import { number, object, string } from 'truefit';
import { standard } from 'truefit/standard';
const User = standard(object({ name: string(), age: number() }));
console.log(User['~standard'].version, User['~standard'].vendor);
console.log(User['~standard'].validate({ name: 'Ada', age: 36 }));
console.log(JSON.stringify(User['~standard'].validate({ name: 'Ada' }), null, 2));1 validator
{ value: { name: 'Ada', age: 36 } }
{
"issues": [
{
"message": "expected a value, got undefined. fix: add \"age\"",
"path": [
"age"
]
}
]
}validate runs parse in one pass, so defaults, coercion and transforms apply, and its issues carry
the path as an array of keys, as the interface specifies. standardAsync is the same for a schema
with awaited rules or maps.
standardJson, on truefit/json-schema, adds the Standard JSON Schema interface beside it. See
JSON Schema.
Compiled validators
Three ways to run one truefit schema: interpreted with no eval, compiled at run time with truefit/jit, or emitted ahead of time as JavaScript or TypeScript source with truefit/emit, and how to choose between them.
Why truefit
truefit against zod, valibot, ArkType, TypeBox and ajv: a 154-feature matrix decided by runnable probes, the things none of them does (JSON Pointer paths, a fix line on every issue, cross-field rules that always run), and what it leaves out on purpose.