diff --git a/README.md b/README.md index d0f69587f1..2d05348155 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@

- ## Table of contents > These docs have been translated into [Chinese](./README_ZH.md) and [Korean](./README_KO.md). @@ -88,6 +87,7 @@ - [Times](#times) - [IP addresses](#ip-addresses) - [IP ranges](#ip-ranges-cidr) + - [JWTs](#jwts) - [Numbers](#numbers) - [BigInts](#bigints) - [NaNs](#nans) @@ -216,7 +216,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod CodeRabbit logo -
+
Cut code review time & bugs in half
coderabbit.ai @@ -241,7 +241,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod Courier logo -
+
The API platform for sending notifications
courier.com @@ -257,7 +257,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod LibLab -
+
Generate better SDKs for your APIs
liblab.com @@ -275,7 +275,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod Neon -
+
Serverless Postgres — Ship faster
neon.tech @@ -291,7 +291,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod stainless -
+
Build AI apps and workflows with Retool AI
retool.com @@ -309,7 +309,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod stainless -
+
Generate best-in-class SDKs
stainlessapi.com @@ -325,7 +325,7 @@ Sponsorship at any level is appreciated and encouraged. If you built a paid prod speakeasy -
+
SDKs & Terraform providers for your API
speakeasy.com @@ -843,6 +843,9 @@ z.string().date(); // ISO date format (YYYY-MM-DD) z.string().time(); // ISO time format (HH:mm:ss[.SSSSSS]) z.string().duration(); // ISO 8601 duration z.string().base64(); + +// added in Zod 3.24 +z.string().jwt(); ``` > Check out [validator.js](https://github.com/validatorjs/validator.js) for a bunch of other useful string validation functions that can be used in conjunction with [Refinements](#refine). @@ -1006,6 +1009,20 @@ const ipv6Cidr = z.string().cidr({ version: "v6" }); ipv6Cidr.parse("192.168.1.1"); // fail ``` +### JWTs + +> Added in Zod 3.24 + +The `z.string().jwt()` method validates the string is a valid 3-part JWT. The JWT must contain type claim in the protected header. + +> This does not verify your JWT cryptographically! It merely ensures its in the proper format. Use a library like [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) to verify the JWT signature, parse the token, and read the claims. + +To constrain the JWT to a specific algorithm: + +```ts +z.string().jwt({ alg: "RS256" }); +``` +
## Numbers