Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 94003c4

Browse filesBrowse files
committed
Improve web url docs
1 parent 7080d97 commit 94003c4
Copy full SHA for 94003c4

File tree

Expand file treeCollapse file tree

1 file changed

+7
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-7
lines changed
Open diff view settings
Collapse file

‎packages/docs/content/api.mdx‎

Copy file name to clipboardExpand all lines: packages/docs/content/api.mdx
+7-7Lines changed: 7 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ schema.parse("http://example.com"); // ❌
329329
```
330330

331331
<Callout>
332-
**Web URLs**A common use case is validating Web (`http`/`https`) URLs. Here's the recommended schema for doing so:
332+
**Web URLs**In many cases, you'll want to validate Web URLs specifically. Here's the recommended schema for doing so:
333333

334334
```ts
335335
const httpUrl = z.url({
@@ -338,7 +338,7 @@ schema.parse("http://example.com"); // ❌
338338
});
339339
```
340340

341-
This restricts the protocol to `http`/`https` and ensures the hostname is a valid domain name with the regex:
341+
This restricts the protocol to `http`/`https` and ensures the hostname is a valid domain name with the `z.regexes.domain` regular expression:
342342

343343
```ts
344344
/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/
@@ -947,7 +947,7 @@ Dog.parse({ name: "Yeller", extraKey: true });
947947

948948
### `.catchall()`
949949

950-
To defina a *catchall schema* that will be used to validate any unrecognized keys:
950+
To define a *catchall schema* that will be used to validate any unrecognized keys:
951951

952952
```
953953
const DogWithStrings = z.object({
@@ -1034,11 +1034,11 @@ Starting from this initial schema:
10341034

10351035
```ts z.object
10361036
const Recipe = z.object({
1037-
name: z.string(),
1037+
title: z.string(),
10381038
description: z.string().optional(),
10391039
ingredients: z.array(z.string()),
10401040
});
1041-
// { id: string; name: string; ingredients: string[] }
1041+
// { title: string; description?: string | undefined; ingredients: string[] }
10421042
```
10431043
To pick certain keys:
10441044

@@ -2495,8 +2495,8 @@ const computeTrimmedLength = MyFunction.implement((input) => {
24952495
return input.trim().length;
24962496
});
24972497

2498-
trimmedLength("sandwich"); // => 8
2499-
trimmedLength(" asdf "); // => 4
2498+
computeTrimmedLength("sandwich"); // => 8
2499+
computeTrimmedLength(" asdf "); // => 4
25002500
```
25012501

25022502
This function will throw a `ZodError` if the input is invalid:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.