Socket
Book a DemoInstallSign in
Socket

zod-match

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-match

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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),
});

FAQs

Package last updated on 03 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts