0.0.12 • Published 9 months ago

validation-adapter v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Status: Experimental

validation-adapter is a universal validation adapter that integrates different validators like Zod, Valibot, Yup, and more.

  • Universal Integration: Combine multiple validation libraries seamlessly
  • Flexible: Easily append and extend validation rules
  • Typesafe: Build with TypeScript for strong type safety

🌟 Motivation

Create a universal validation adapter that generalizes different validation libraries like Zod, Valibot, etc. for use in libraries & applications requiring diverse validation strategies like feature-form.

📖 Usage

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);
0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

9 months ago

0.0.9

10 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago