Status: Experimental
validation-adapters
is a collection of pre-made adapters for popular validation libraries like Zod and Valibot, allowing for easy integration with the validation-adapter
library.
import * as v from 'valibot';
import { createValidator } from 'validation-adapter';
import { vValidator } from 'validation-adapters/valibot';
import { zValidator } from 'validation-adapters/zod';
import * as z from 'zod';
const zodNameValidator = zValidator(
z
.string()
.min(2)
.max(10)
.regex(/^([^0-9]*)$/)
);
const valibotNameValidator = vValidator(
v.pipe(v.string(), v.minLength(2), v.maxLength(10), v.regex(/^([^0-9]*)$/))
);
const customValidator = createValidator([
{
key: 'custom',
validate: (cx) => {
if (cx.value !== 'CustomValue') {
cx.registerError({
code: 'custom-error',
message: 'Value must be CustomValue.'
});
}
}
}
]);
const combinedValidator = valibotNameValidator.clone().append(customValidator);
import { zValidator } from 'validation-adapters/zod';
import * as z from 'zod';
const zodNameValidator = zValidator(
z
.string()
.min(2)
.max(10)
.regex(/^([^0-9]*)$/)
);
import * as v from 'valibot';
import { vValidator } from 'validation-adapters/valibot';
const valibotNameValidator = vValidator(
v.pipe(v.string(), v.minLength(2), v.maxLength(10), v.regex(/^([^0-9]*)$/))
);