You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
z.encode(dateToString, "2024-01-15T00:00:00.000Z"); // => Date
2574
+
```
2575
+
2567
2576
Refer to the dedicated [Codecs](/codecs) page for more information. That page contains implementations for commonly-needed codecs that you can copy/paste into your project:
Copy file name to clipboardExpand all lines: packages/docs/content/codecs.mdx
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,37 @@ This is particularly useful when parsing data at a network boundary. You can sha
92
92
alt="Codecs encoding and decoding data across a network boundary"
93
93
/>
94
94
95
+
### Inverting codecs
96
+
97
+
Use `z.invertCodec()` to derive the reverse codec from an existing one. The returned codec swaps the input and output schemas, then swaps the `decode` and `encode` transforms.
`z.invertCodec()` only inverts the codec you pass to it. It does not recursively invert codecs nested inside another schema; invert those codecs where you define the reversed schema.
125
+
95
126
### Composability
96
127
97
128
> **Note** — You can use `z.encode()` and `z.decode()` with any schema. It doesn't have to be a ZodCodec.
0 commit comments