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

unplugin-ts-mock

v0.2.1

Published

Build-time TypeScript type → faker mock generator for Vite, Rollup, webpack, and esbuild

Readme

unplugin-ts-mock

A build-time bundler plugin that scans TypeScript types and auto-generates faker-based mock data.
Supports Vite, webpack, Rollup, and esbuild.


Demo

# Requires Node.js 20+
cd test-vite
npm install
npm run dev   # http://localhost:5173

Mock data generated by createMock<User>(), createMock<Post>(), etc. is displayed as cards.
Click Regenerate to produce new faker values.


Usage

Write createMock<T>() in your code — the plugin replaces it with an object literal at build time.
Type inference and autocomplete work as-is with zero runtime overhead.

Installation

npm install unplugin-ts-mock

Plugin setup

// vite.config.ts
import TsMock from 'unplugin-ts-mock/vite'

export default {
  plugins: [TsMock()]
}
// webpack.config.js
const TsMock = require('unplugin-ts-mock/webpack')

module.exports = {
  plugins: [TsMock()]
}
// rollup.config.js
import TsMock from 'unplugin-ts-mock/rollup'

export default {
  plugins: [TsMock()]
}
// esbuild
import TsMock from 'unplugin-ts-mock/esbuild'

await build({
  plugins: [TsMock()]
})

API

import { createMock, createMockList } from 'unplugin-ts-mock'
import type { User, Post } from './types'

const user  = createMock<User>()       // inferred as User
const post  = createMock<Post>()
const users = createMockList<User>(3)  // inferred as User[]

After build, the actual bundle contains:

const user = {
  id: "f3152fb1-...",
  name: "Lola Friesen",
  email: "[email protected]",
  role: Role.Admin,
  createdAt: "2024-01-15T09:23:00.000Z",
  ...
}

The createMock<T>() call is replaced entirely with an inlined object literal.

Options

TsMock({
  dir:     './src',        // directory to scan (default: project root)
  exclude: ['fixtures'],   // additional directory names to exclude
})

Supported types

| Feature | Support | |---|---| | interface, type alias, enum | ✓ | | union, intersection, tuple | ✓ | | Partial / Required / Readonly / Pick / Omit / Promise / Array<T> | ✓ | | interface extends inheritance | ✓ | | Auto-discovery of all project files | ✓ | | Types from node_modules | ✓ via TypeChecker | | Namespaced types (WebAssembly.Memory, etc.) | ✓ via TypeChecker | | Function types / method signatures | ✓ generates () => {} stub | | Circular references | ✓ auto-blocked (depth limit 6) | | Advanced utilities (Extract, Exclude, ReturnType, …) | △ generates {} |


Field name inference

Field names are matched to produce meaningful values.

| Pattern | Example fields | Generated value | |---|---|---| | Exact match | id | UUID | | Exact match | name, email, phone, company | faker equivalent | | Exact match | timezone, locale, slug, ip, mimeType | faker equivalent | | *Id suffix | userId, teamId | UUID | | *At suffix | createdAt, updatedAt | ISO date string | | *Date suffix | startDate, dueDate | ISO date string | | *Url suffix | avatarUrl, imageUrl | URL | | Other string | — | lorem ipsum word |


Caveats

Optional fields (?) are omitted ~30% of the time.
Results vary per run — override specific fields after generation if a fixed value is required.

Advanced utility types (Extract, Exclude, ReturnType, Parameters, etc.) generate {}.


How it works

Directory scan
  → collect .ts / .tsx files (test and story files excluded)
  → ts.createProgram()   build full program (auto-detects tsconfig.json)
  → TypeChecker          resolve TypeReferences in declaration context
  → faker                generate random data matching field types and names

[Plugin]
  → detect createMock<T>() patterns via regex
  → extract generic argument T and generate mock
  → replace call with inlined object literal
  → auto-inject missing enum imports