Skip to content

Repository files navigation

TSMocker

Type-safe mock data generator CLI. Parses TypeScript interfaces with ts-morph (TypeScript Compiler API) and synthesizes realistic Faker.js objects for API prototyping and test-data seeding.

TypeDoc API documentation is generated into the docs/ folder (npm run docs).

Quick Start

npm install
npm run build
npm start

Usage

Interactive Mode (Recommended)

npm start
  • Auto-discovers TypeScript files
  • Auto-detects interfaces
  • Guided prompts for type, count, and export format
  • JSON or CSV output, with optional file save

Command Line Mode

npm start -- --schema <file> --interface <name> [options]

Options:

  • --schema, -s - Path to TypeScript file
  • --interface, -i - Interface name to mock
  • --count, -c - Number of objects (default: 1)
  • --output, -o - Format: json or csv (default: json)
  • --out-file, -f - Save to file

Examples:

# Generate 5 users as JSON
npm start -- --schema examples/User.ts --interface User --count 5

# Generate CSV and save to file
npm start -- --schema examples/User.ts --interface User --output csv --out-file users.csv

# Generate 10,000 entries for test-data seeding
npm start -- --schema examples/User.ts --interface User --count 10000 --out-file users.json

Features

  • Interactive CLI with auto-discovery
  • Context-aware field generation (firstName / lastName / username, street, birthDate, email, and more)
  • Multiple output formats (JSON, CSV)
  • Full TypeScript support (unions, string-literal unions, arrays, nested objects, dates)
  • Optional properties and nested interfaces
  • 90%+ Jest coverage on the parser and generator modules (CLI I/O excluded from the threshold)
  • TypeDoc-generated API docs in docs/

Supported Types

  • Primitives: string, number, boolean, Date
  • Collections: array[], object
  • Advanced: union types, string-literal unions, optional properties, nested interfaces

Example

interface User {
  id: number;
  firstName: string;
  lastName: string;
  username: string;
  email: string;
  birthDate: Date;
  address?: {
    street: string;
    city: string;
  };
}

Generates realistic data like:

{
  "id": 1234,
  "firstName": "Maureen",
  "lastName": "Rohan",
  "username": "Lindsey.Bogan",
  "email": "maureen.rohan@example.com",
  "birthDate": "1991-04-12T16:22:09.000Z",
  "address": {
    "street": "123 Main Street",
    "city": "Springfield"
  }
}

Development

npm test              # Run Jest (enforces 90%+ coverage on parser + generator)
npm run test:coverage # Same, with explicit coverage output
npm run docs          # Generate TypeDoc documentation into docs/
npm run build         # Compile TypeScript to dist/

About

typescipt project for data mocking

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages