Valibot
byfabian-hiller

Valibot/Migrate To V0.31.0

/icons/calendar.svg

Last update

Jul 24, 2024

Migrate to v0.31.0

You can use Codemod to automatically update your code to the new API. See the migration guide for more details on the changes.

Examples

Before

import * as v from 'valibot';
v.object({
email: v.string([v.email(), v.endsWith('@gmail.com')]),
password: v.string([v.minLength(8)]),
other: v.union([v.string([v.decimal()]), v.number()]),
});

After

import * as v from 'valibot';
v.object({
email: v.pipe(v.string(), v.email(), v.endsWith('@gmail.com')),
password: v.pipe(v.string(), v.minLength(8)),
other: v.union([v.pipe(v.string(), v.decimal()), v.number()]),
});

Before

import * as v from 'valibot';
import { object, tuple } from 'valibot';
const ObjectSchema = object({ key: v.string() }, v.null_());
const TupleSchema = tuple([v.string()], v.null_());

After

import * as v from 'valibot';
import { objectWithRest, tupleWithRest } from 'valibot';
const ObjectSchema = objectWithRest({ key: v.string() }, v.null_());
const TupleSchema = tupleWithRest([v.string()], v.null_());

Before

import * as v from 'valibot';
const ObjectSchema1 = v.object({ foo: v.string() });
const ObjectSchema2 = v.object({ bar: v.number() });
const MergedObject = v.merge([ObjectSchema1, ObjectSchema2]);

After

import * as v from 'valibot';
const ObjectSchema1 = v.object({ foo: v.string() });
const ObjectSchema2 = v.object({ bar: v.number() });
const MergedObject = v.object({
...ObjectSchema1.entries,
...ObjectSchema2.entries,
});

Before

import * as v from 'valibot';
const BrandedSchema = v.brand(v.string(), 'foo');
const TransformedSchema = v.transform(v.string(), (input) => input.length);

After

import * as v from 'valibot';
const BrandedSchema = v.pipe(v.string(), v.brand('foo'));
const TransformedSchema = v.pipe(
v.string(),
v.transform((input) => input.length)
);

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now