zod-match
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

zod-match

Adds a resultify method to ZodTypes so you can match Without Exceptions™️!

Because exceptions are not flow control...

This little library brings zod and @swan-io/boxed together to give you a nifty way to turn a zod parse into a boxed Result.

Of course, it is TypeScript too.

import z from "zod";
import "zod-match";

const NewCarRequest = z.object({
    wheels: z.number().min(3).max(4),
    engine: z.object({
        size: z.number().optional(),
        fuel: z.enum(["petrol", "diesel", "electric"]),
    }),
});

const iffyRequest = {
    make: "homosapien",
    model: "northern",
    legs: 2,
    engine: {
        fuel: "potatoes",
        size: "12st"
    }
}

NewCarRequest.resultify(iffyRequest).match({
    Ok: (car) => shipTheMotor(car),
    Error: (error) => logBadThing(error),
});

Readme

Keywords

none

Package Sidebar

Install

npm i zod-match

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

148 kB

Total Files

14

Last publish

Collaborators

  • benbenbenbenbenben