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

zod4-mock

v0.5.0

Published

Deterministic, schema-driven mock data generator for Zod v4

Downloads

1,097

Readme

zod4-mock

Deterministic, schema-driven mock data for Zod v4.

Same seed → same data, always. Field names like email, firstName, and createdAt automatically produce realistic values. Schemas can declare relations so IDs stay consistent across multiple API shapes — without any manual wiring.

Quick start

import { z } from "zod";
import { generate } from "zod4-mock";

const user = generate(
  z.object({
    id: z.uuid(),
    firstName: z.string(),
    email: z.email(),
    role: z.enum(["admin", "user"]),
    createdAt: z.date(),
  }),
);
// → { id: "3f2d…", firstName: "Jan", email: "j.bakker@…", role: "user", createdAt: Date }

No setup, no seed, no configuration. Field names drive the values — firstName gets a first name, email gets a valid email address, id gets a UUID.

Installation

npm install zod4-mock zod@^4

Seeded worlds

For tests, pin a seed so every run produces identical data:

import { createWorld } from "zod4-mock";

const world = createWorld({ seed: 42 });

const users = world.generate(z.array(UserSchema).min(5).max(20));
// Byte-identical output every run, every machine

Custom field values

Register matchers to control specific fields. ctx.gen gives you the full generator library with the PRNG already applied — no need to pass prng anywhere:

const world = createWorld({ seed: 42 }).withSchema(ProductSchema, {
  matchers: {
    name: (ctx) => ctx.gen.commerce.productName(),
    sku: (ctx) => `SKU-${ctx.gen.string.alphanumeric(6)}`,
    price: (ctx) => ctx.prng.int(100, 50_000), // cents, custom range
  },
});

const products = world.generate(z.array(ProductSchema).min(10));

Any field without a matcher falls through automatically: key-name heuristics first, then Zod type introspection.

Related schemas

Declare relations between schemas to keep foreign keys coherent across different API shapes:

const world = createWorld({ seed: 42 })
  .withSchema(PersonSchema)
  .withSchema(DocumentSchema, {
    relations: { author: PersonSchema },
    matchers: {
      authorId: (ctx) => ctx.related("author").personId,
      title: (ctx) => ctx.gen.word.sentence(),
    },
  });

const people = world.generate(z.array(PersonSchema).min(3));
const documents = world.generate(z.array(DocumentSchema).min(10));

// documents[*].authorId ∈ people[*].personId — guaranteed

Derived schemas

When two API shapes represent the same underlying entity, bind the second to the first with from. The source entity's data is available as ctx.source:

const world = createWorld({ seed: 42 })
  .withSchema(PersonSchema)
  .withSchema(PersonSummarySchema, {
    from: PersonSchema,
    matchers: {
      id: (ctx) => ctx.source.personId,
      displayName: (ctx) => `${ctx.source.firstName} ${ctx.source.lastName}`,
      initials: (ctx) => `${ctx.source.firstName[0]}${ctx.source.lastName[0]}`,
    },
  });

const people = world.generate(z.array(PersonSchema).min(5));
const summaries = world.generate(z.array(PersonSummarySchema));

// people[0].personId === summaries[0].id — always

Nested schemas compose

Register matchers for a schema once — they apply automatically wherever that schema appears, including nested inside other schemas:

const world = createWorld({ seed: 42 })
  .withSchema(AddressSchema, {
    matchers: {
      street: (ctx) => ctx.gen.location.street(),
      city: (ctx) => ctx.gen.location.city(),
      country: (ctx) => ctx.gen.location.countryCode(),
    },
  })
  .withSchema(PersonSchema); // has address: AddressSchema

// PersonSchema's address field uses AddressSchema's matchers automatically
const person = world.generate(PersonSchema);

Features

  • Zero-configgenerate(schema) works with no setup, no imports beyond the schema
  • Deterministic — same seed → identical output on every run and every machine
  • Field-name heuristicsemail, firstName, createdAt, userId, street, iban, vin, and 150+ more auto-generate realistic values
  • Schema-driven — respects .min(), .max(), .email(), .uuid(), z.enum(), z.union(), z.optional(), z.discriminatedUnion(), and more
  • Composable — nested schemas automatically use their registered matchers
  • Relational — cross-schema ID consistency without any manual wiring
  • ctx.gen — full generator library (person, internet, location, finance, commerce, …) pre-wired to the PRNG inside matchers
  • Per-field seeding — adding or removing schema fields never disturbs values of other fields
  • Zod v4 native — built against zod@^4

Documentation

License

MIT