Skip to content

Generate type-safe mock JSON data from TypeScript interfaces — perfect for testing and development.

Notifications You must be signed in to change notification settings

drealdumore/falso-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Falso

A utility that parses TypeScript interfaces and generates realistic mock data based on the interface structure.

Features

  • 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
    • null and undefined
  • Context-aware values (e.g. names, emails, prices)

Installation

npm install @faker-js/faker

Usage

import { 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);

Example Output

[
  {
    "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"
  }
]

Notes

  • Doesn't support generics or complex unions/intersections
  • Best for simple, structured interfaces

About

Generate type-safe mock JSON data from TypeScript interfaces — perfect for testing and development.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published