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

mock-craft

v3.0.0

Published

Zero-dependency CLI (v3): deterministic seed (Mulberry32), nullChance, _collections + ref, TS types export, HTTP mock server — plus v2 nested schema features.

Readme

mock-craft v3

mcraft is a zero-dependency Node.js CLI for deterministic mock data and a tiny HTTP mock API. No npm runtime dependencies — only Node.js built-ins (http, crypto, fs, util, …).

Repository: github.com/harankin92/mock-craft

Requirements

  • Node.js 18+

Install

npm install -g mock-craft
npm install mock-craft
npx mcraft generate -s schema.json

Commands

generate — file or stdout

mcraft generate -s <schema.json> [options]

| Option | Description | |--------|-------------| | -s, --schema <path> | Schema JSON (required) | | -f, --format <type> | json (default), csv, sql | | -c, --count <n> | Rows (default 10; per collection when using _collections) | | -o, --output <path> | Write to file instead of stdout | | -t, --table <name> | SQL table name for flat schemas (default mock_data) | | --seed <string> | Deterministic output (same seed → same JSON/SQL rows) | | --types <path> | Emit TypeScript interfaces inferred from the schema |

Note: Schemas with _collections support JSON and SQL only (not CSV — single-table CSV does not fit multiple entity sets).

serve — in-memory HTTP API

mcraft serve -s <schema.json> [options]

| Option | Description | |--------|-------------| | -s, --schema <path> | Schema (required) | | -c, --count <n> | Rows loaded into memory at startup (default 10) | | --port <n> | Port (default 3000) | | --seed <string> | Same reproducibility as generate |

Data is generated once at startup and kept in memory.

Endpoints

| Method | Path | Behaviour | |--------|------|-----------| | GET | /api/data | Full payload: flat schemas wrap rows as { "records": [...] }; _collections returns { "users": [...], ... }. | | GET | /api/<collection>?limit=N | Only when _collections exists — returns one array; optional limit truncates. |

Each request logs a line such as: [GET] /api/users - 200 OK (2ms).


Deterministic seed (--seed)

Math.random() is not seedable. mock-craft v3 uses a Mulberry32 PRNG fed by SHA-256 of your seed string. Identical schema + count + seed ⇒ identical output (including UUID-shaped ids).

Dates use a fixed reference instant (not Date.now()), so date fields are reproducible under the same seed.


Nullability (nullChance)

Any field config may set nullChance[0, 1]. Before generating a value, the PRNG may short-circuit and return null for that field (including object / array roots).


Multi-schema (_collections + ref)

If the schema root contains _collections, each key is a named collection (table-like). Collections are generated in declaration order; ref picks a random row from an earlier collection and reads a field value.

Example (schema.collections.example.json):

{
  "_collections": {
    "users": { "id": "uuid", "name": "name", "email": "email" },
    "posts": {
      "id": "uuid",
      "title": { "type": "text", "words": 5 },
      "authorId": {
        "type": "ref",
        "collection": "users",
        "field": "id",
        "nullChance": 0.05
      }
    }
  }
}

Rules:

  • ref.collection must appear before the current collection in _collections key order.
  • SQL export emits INSERT statements into tables named after collection keys.

Flat schema (v2 features preserved)

Shorthand still works:

{
  "id": "uuid",
  "fullName": "name",
  "contactEmail": "email",
  "age": { "type": "number", "min": 1, "max": 120 },
  "createdAt": "date",
  "deliveryAddress": "address"
}

Rich configs support object, array, template ({{uuid}}, {{number}}, …), enum, float, boolean, phone, text, number bounds, nesting depth limit 5.

See schema.advanced.example.json.


TypeScript export (--types)

Pass --types ./path/to/file.ts. The CLI walks the schema and writes interfaces:

| Schema kind | TS mapping | |-------------|------------| | uuid, name, email, phone, text, template, date, address | string | | number, float | number | | boolean | boolean | | enum | union of literal values | | object | inline { ... } | | array | T[] | | ref | resolved from referenced collection field | | nullChance > 0 | \| null |

Collections emit one export interface …Row per collection.


CSV / SQL / nested JSON cells

Nested objects or arrays in a cell are exported as JSON.stringify strings with proper quoting (CSV ", SQL '…').


Examples

mcraft generate -s schema.example.json --seed demo -c 5 -f json
mcraft generate -s schema.collections.example.json -f sql -c 20 -o seed.sql
mcraft generate -s schema.example.json --types ./src/mock-types.ts
mcraft serve -s schema.collections.example.json --port 3000 --seed local

Development

git clone https://github.com/harankin92/mock-craft.git
cd mock-craft
node bin/index.js generate -s schema.collections.example.json --seed x -f json -c 2

License

MIT