ts-mock-factory
v1.0.0
Published
Zero-dependency mock data generator that parses TypeScript interfaces and type signatures to generate type-safe mock JSON data.
Maintainers
Readme
ts-mock-factory
TypeScript Mock Data Generator: A zero-dependency parser that scans TS interface and type declarations to dynamically generate structured mock JSON datasets.
⚡ Features
- Zero Runtime Dependencies: Ultra lightweight and fast.
- TypeScript Signatures Parser: Parses basic interface and type properties (
string,number,boolean, and primitive arrays). - Customizable Seeds: Define custom overrides or dynamic generator functions for string, numeric, and boolean fields.
📦 Installation
npm install ts-mock-factory🚀 Usage
1. CLI Usage
Generate mock JSON from a typescript file:
npx ts-mock-factory interface.ts2. Programmatic API
import { generateMockFromType } from 'ts-mock-factory';
const tsInterface = `
interface User {
username: string;
id: number;
isAdmin: boolean;
roles: string[];
}
`;
const mock = generateMockFromType(tsInterface, {
stringMock: () => "user_" + Math.random().toString(36).substring(7),
numberMock: 100
});
console.log(mock);
/*
{
username: "user_a3d21",
id: 100,
isAdmin: true,
roles: ["user_b2a12"]
}
*/📄 License
MIT License.
