A utility that parses TypeScript interfaces and generates realistic mock data based on the interface structure.
- Parses TypeScript interfaces to schema
- Generates mock data based on schema
- Supports:
- Primitives (
string,number,boolean,Date) - Arrays and nested objects
- Optional and union types
nullandundefined
- Primitives (
- Context-aware values (e.g. names, emails, prices)
npm install @faker-js/fakerimport { parseInterface, generateMockData } from './your-file';
const iface = \`
interface User {
id: string;
name: string;
email: string;
age?: number;
roles: 'admin' | 'user' | 'guest';
address: { street: string; city: string; zipCode: string };
createdAt: Date;
}
\`;
const schema = parseInterface(iface);
const mockData = generateMockData(schema, 5);
console.log(mockData);[
{
"id": "uuid",
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"roles": "admin",
"address": {
"street": "123 Main St",
"city": "New York",
"zipCode": "10001"
},
"createdAt": "2023-05-15T14:32:10.000Z"
}
]- Doesn't support generics or complex unions/intersections
- Best for simple, structured interfaces