npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zod-matcher

v1.0.4

Published

Rust inspired pattern matching for Zod schemas

Readme

Zod Matcher

Rust inspired pattern matching for Zod schemas

Installation

yarn add zod-matcher
npm install zod-matcher

Basic usage

Example match in Rust

let x = 1;

match x {
    1 => println!("one"),
    2 => println!("two"),
    3 => println!("three"),
    _ => println!("anything"),
}

Equivalent with zod-matcher

declare const x : number

match(x)
    .case(z.literal(1), () => console.log('one'))
    .case(z.literal(2), () => console.log('two'))
    .case(z.literal(3), () => console.log('three'))
    .default(() => console.log('anything'))
    .parse()

Why use zod-matcher

Type safety

Unhandled cases won't allow you to parse. You must handle every case or fallback to a default.

const x = 'A' as 'A' | 'B'

// Error "Unhandled cases"
match(x)
    .case(z.literal('A'), console.log)
    .parse()

// Resolve by adding case
match(x)
    .case(z.literal('A'), console.log)
    .case(z.literal('B'), console.log)
    .parse()

// Or by adding default
match(x)
    .case(z.literal('A'), console.log)
    .default(console.log)
    .parse()

Type narrowing

The .default() method passes the input value as an argument typed excluding any previously handled cases.

const x = 'A' as 'A' | 'B' | 'C';

match(x)
  .case(z.literal('A'), console.log)
  .case(z.literal('B'), console.log)
  .default(x => x) // <== Type of x is "C"
  .parse();

Union return

The return type is a union of all the return types of each case.

const x = 'A' as 'A' | 'B' | 'C';

// Type of result is "A1" | "B2" | "C3"
const result = match(x)
  .case(z.literal('A'), x => `${x}1` as const)
  .case(z.literal('B'), x => `${x}2` as const)
  .case(z.literal('C'), x => `${x}3` as const)
  .parse();

Safe parsing

You can throw on failed matches using .parse() or return a result union with .safeParse().

// Throws error if no match
const result = match(x)
    .case(z.string(), console.log)
    .parse()

// Returns result of union type
// | { success: true, data: x }
// | { success: false, error: MatcherError }
const result = match(x)
    .case(z.string(), console.log)
    .safeParse()