JacobWeisenburger / zod_utilz

Framework agnostic utilities for Zod
MIT License
164 stars 9 forks source link

Some additional utilities #2

Open jamesarosen opened 1 year ago

jamesarosen commented 1 year ago

There are some utilities I use locally for which I'm looking for a home. I'm happy to contribute them here or -- if you prefer -- create my own zod-contrib package.

The end result is something you can use to validate & type responses from a CMS:

const article = z.object({
  lastUpdated: zu.timestamp.ms(),
  title: z.string(),
  titleColor: zu.color().optional(),
})

const articleResponse = z.pipeline(
  zu.response({ status: 200 }).json(),
  zu.jsonString(),
  z.object({ article }),
)

const myArticle = await articleResponse.parseAsync(await fetch('/articles/123'))

Would any of this be a good fit here?

JacobWeisenburger commented 1 year ago

These all sound good. Please make PRs, so I can see more details.