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

typescript-mock-builder

v1.0.0

Published

Reads a TypeScript interface and generates a typed mock object — zero config CLI

Readme

typescript-mock-builder

Zero-config CLI and library that reads a TypeScript interface and instantly generates a typed mock object or factory function — no compiler plugins, no schemas, no setup.

Install

npm install -g typescript-mock-builder
# or run directly
npx typescript-mock-builder ./src/types/User.ts

Usage

Given a TypeScript file:

// src/types/User.ts
export interface User {
  id: number;
  email: string;
  name: string;
  createdAt: Date;
  isActive: boolean;
  phone?: string;
}

Generate a plain mock object

npx typescript-mock-builder ./src/types/User.ts

Output:

const mockUser: User = {
  id: 1,
  email: '[email protected]',
  name: 'mock-name',
  createdAt: new Date(),
  isActive: false,
};

Generate a factory function

npx typescript-mock-builder ./src/types/User.ts --factory

Output:

function createUser(overrides: Partial<User> = {}): User {
  return {
    id: 1,
    email: '[email protected]',
    name: 'mock-name',
    createdAt: new Date(),
    isActive: false,
    ...overrides,
  };
}

Options

| Flag | Description | |------|-------------| | --interface <name> | Generate mock for a specific interface only | | --factory | Generate a factory function instead of a plain object | | --export | Add export keyword to the generated mock | | --var <name> | Custom variable or function name |

Examples

# Specific interface
npx typescript-mock-builder ./src/types.ts --interface Product

# With export + custom name
npx typescript-mock-builder ./src/types.ts --export --var testUser

# Factory with export
npx typescript-mock-builder ./src/types.ts --factory --export

How mock values are chosen

The generator uses name-based heuristics first, then type-based fallbacks:

| Property name pattern | Value | |-----------------------|-------| | id, *Id | 1 | | email, *Email | '[email protected]' | | url, *Url, *Uri | 'https://example.com' | | name, *Name | 'mock-<propName>' | | token, *Token | 'mock-token' | | phone, *Phone | '+1234567890' | | createdAt, updatedAt, *Date, *At | new Date() |

| Type | Value | |------|-------| | string | 'mock-<propName>' | | number | 0 | | boolean | false | | Date | new Date() | | string[], number[], T[] | [] | | Union (A \| B \| null) | picks first non-null option | | anything else | {} |

Optional properties are skipped by default.

Use as a library

import { readInterfaces, generateMock, generateMockFactory } from 'typescript-mock-builder';

const interfaces = readInterfaces('./src/types/User.ts');
const code = generateMock(interfaces[0]);
const factory = generateMockFactory(interfaces[0], { exportMock: true });

Works with type aliases too

export type Product = {
  id: number;
  name: string;
};

Type aliases that are object types are parsed the same way as interfaces.

License

MIT