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

@hesam_mhm/zod-rules

v1.0.0

Published

Enterprise-grade declarative conditional validation framework on top of Zod. Eliminates most direct usage of superRefine().

Readme

@hesam_mhm/zod-rules

Enterprise-grade declarative conditional validation framework on top of Zod v4. Eliminates most direct usage of superRefine().

TypeScript Zod License: MIT

Why?

Zod's superRefine() is powerful but ergonomic poison: cross-field rules drift into ad-hoc callbacks, error messages are inlined, and conditional logic disappears into lambdas. zod-rules replaces that pattern with declarative, composable, fully-typed rules that read like requirements and behave like code.

import { z } from "zod";
import {
  withRules,
  requiredIf,
  equalTo,
  atLeastOne,
  dateAfter,
} from "@hesam_mhm/zod-rules";

const UserSchema = withRules(
  z.object({
    hasCompany: z.boolean(),
    companyName: z.string().optional(),
    password: z.string(),
    confirmPassword: z.string(),
    email: z.string().optional(),
    phone: z.string().optional(),
    startDate: z.coerce.date(),
    endDate: z.coerce.date(),
  }),
  [
    requiredIf("hasCompany", true, "companyName"),
    equalTo("password", "confirmPassword"),
    atLeastOne(["email", "phone"]),
    dateAfter("endDate", "startDate"),
  ],
);

Field names are checked at compile time. Rules compose with and, or, not, when. Async rules (uniqueAsync, existsAsync) work transparently with safeParseAsync. React Hook Form and i18n plugins ship out of the box.

Features

  • 70+ declarative rules across 11 categories: presence, comparison, conditional, dependency, collection, aggregate, string, number, date, object, array-item, async, enterprise.
  • Full TypeScript inference — typos in field names fail at compile time. Nested paths like "user.address.city" and "items.0.price" are typed.
  • Functional architecture — no classes, no this, no mutation. Rules are plain objects with an apply method.
  • Composableand, or, not, when combine rules into higher-level ones.
  • Async-readyparseAsync / safeParseAsync work natively; uniqueAsync, existsAsync, validateAsync for server-side checks.
  • React Hook Form compatible — drop-in zodRulesResolver replaces @hookform/resolvers/zod.
  • i18n plugin — install a translator and every message can be a {messageKey, params} descriptor resolved through your dictionary.
  • Tree-shakable ESM — only the rules you import are bundled.
  • Zero runtime dependencies except zod (and optional react-hook-form).

Installation

npm install @hesam_mhm/zod-rules zod
# peer deps (optional)
npm install react-hook-form

Quick start

import { z } from "zod";
import { withRules, required, equalTo, when } from "@hesam_mhm/zod-rules";

const SignupSchema = withRules(
  z.object({
    country: z.string(),
    nationalCode: z.string().optional(),
    password: z.string(),
    confirmPassword: z.string(),
  }),
  [
    // Conditional requirement
    when((d) => d.country === "IR", required("nationalCode")),
    // Cross-field equality
    equalTo("password", "confirmPassword"),
  ],
);

// Sync parse if all rules are sync:
const r1 = SignupSchema.safeParse({
  country: "US",
  password: "x",
  confirmPassword: "x",
});
// => { success: true, data: ... }

// Async parse for async rules (or just to be safe):
const r2 = await SignupSchema.safeParseAsync({
  country: "IR",
  nationalCode: "123",
  password: "x",
  confirmPassword: "y",
});
// => { success: false, error: ZodError }

Documentation

React Hook Form

import { useForm } from "react-hook-form";
import { z } from "zod";
import { withRules, required, equalTo } from "@hesam_mhm/zod-rules";
import { zodRulesResolver } from "@hesam_mhm/zod-rules/react-hook-form";

const schema = withRules(
  z.object({
    email: z.string(),
    password: z.string(),
    confirmPassword: z.string(),
  }),
  [required("email"), equalTo("password", "confirmPassword")],
);

function SignupForm() {
  const {
    register,
    handleSubmit,
    formState: { errors },
  } = useForm({
    resolver: zodRulesResolver(schema),
  });
  // ...
}

See examples/ for FieldArray and multi-step form examples.

i18n

import i18next from "i18next";
import { installI18n, i18n } from "@hesam_mhm/zod-rules/i18n";

installI18n((key, params) => i18next.t(key, params));

const schema = withRules(z.object({ email: z.string() }), [
  required("email", { message: i18n("errors.required", { field: "email" }) }),
]);

License

MIT © Hesam