Skip to content

Commit

Permalink
Further improve migrate from Zod guide on website
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Oct 28, 2024
1 parent 9179133 commit b2911b3
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const value = z.string().parse('foo');
const value = v.parse(v.string(), 'foo');
```

We recommend that you read our <Link href="../mental-model/">mental model</Link> guide to understand how the individual functions of Valibot's modular API work together.

## Change names

Most of the names are the same as in Zod. However, there are some exceptions. The following table shows all names that have changed.
Expand Down Expand Up @@ -92,6 +94,7 @@ Most of the names are the same as in Zod. However, there are some exceptions. Th
| `shape` | `entries` |
| `strict` | <Link href="/api/strictObject/">`strictObject`</Link> |
| `strip` | <Link href="/api/object/">`object`</Link> |
| `superRefine` | <Link href="/api/rawCheck/">`rawCheck`</Link>, <Link href="/api/rawTransform/">`rawTransform`</Link> |

## Other details

Expand Down Expand Up @@ -138,6 +141,12 @@ const NumberSchema = z.coerce.number();
const NumberSchema = v.pipe(v.unknown(), v.transform(Number));
```

Instead of <Link href="/api/unknown/">`unknown`</Link> as in the previous example, we usually recommend using a specific schema such as <Link href="/api/string/">`string`</Link> to improve type safety. This allows you, for example, to validate the formatting of the string with <Link href="/api/decimal/">`decimal`</Link> before transforming it to a number.

```ts
const NumberSchema = v.pipe(v.string(), v.decimal(), v.transform(Number));
```

### Async validation

Similar to Zod, Valibot supports synchronous and asynchronous validation. However, the API is a little bit different. See the <Link href="../async-validation/">async guide</Link> for more details.

0 comments on commit b2911b3

Please sign in to comment.