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 🙏

© 2025 – Pkg Stats / Ryan Hefner

schema-demo-factory

v1.0.3

Published

Generate realistic mock data from schema definitions using Faker.js

Readme

Schema Demo Factory

npm version License: MIT TypeScript

Generate realistic mock data from schema definitions with full TypeScript support using Faker.js.

🚀 Installation

npm install schema-demo-factory

🎯 Quick Start

import SchemaDemoFactory, { TypeSchema } from 'schema-demo-factory';

const userSchema = {
  type: "object",
  properties: {
    id: { type: "uuid" },
    email: { type: "email" },
    username: { type: "string", pattern: "name" },
    age: { type: "number", min: 18, max: 80 },
    isActive: { type: "boolean" },
    nickname: { type: "string", optional: true },
    lastLogin: { type: "date", nullable: true },
  },
} as const satisfies TypeSchema;

const mockUser = SchemaDemoFactory.create(userSchema);
 Type: {
   id: string;
   email: string;
   username: string;
   age: number;
   isActive: boolean;
   nickname: string | undefined;
   lastLogin: Date | null;
 }

const mockUsers = SchemaDemoFactory.createMultiple(userSchema, 5);
 Type: Array<{
   id: string;
   email: string;
   username: string;
   age: number;
   isActive: boolean;
   nickname: string | undefined;
   lastLogin: Date | null;
 }>

🌟 Features

  • 🎨 Full TypeScript Support - Complete type inference and autocomplete
  • 🎭 Realistic Data - Powered by Faker.js for production-quality mock data
  • 📦 Type-Safe Schema - Compile-time type checking and IntelliSense
  • 🔄 Nested Objects - Support for deeply nested structures
  • 📋 Arrays - Configurable array generation with min/max lengths
  • 🎲 Optional Fields - Randomly include/exclude fields
  • 🕳️ Nullable Fields - Support for null values
  • 🌐 Locale Support - Generate data in different languages
  • 🔧 Extensible - Easy to customize and extend

📚 Schema Types

Basic Types

// String with patterns
{ type: "string", pattern: "email" }     // [email protected]
{ type: "string", pattern: "uuid" }      // 123e4567-e89b-12d3-a456-426614174000
{ type: "string", pattern: "url" }       // https://example.com
{ type: "string", pattern: "phone" }     // +1-555-123-4567
{ type: "string", pattern: "name" }      // John Doe
{ type: "string", options: ["A", "B"] }  // Random from options

// Numbers with ranges
{ type: "number", min: 18, max: 80 }     // Random number between 18-80

// Booleans
{ type: "boolean" }                      // true or false

// Dates
{ type: "date" }                         // Recent date

Advanced String Patterns

{ type: "string", pattern: "paragraph" }    // Lorem ipsum...
{ type: "string", pattern: "image" }        // Avatar URL
{ type: "string", pattern: "ipv4" }         // 192.168.1.1
{ type: "string", pattern: "mac" }          // 00:11:22:33:44:55
{ type: "string", pattern: "hexColor" }     // #ff5733
{ type: "string", pattern: "currency" }     // USD
{ type: "string", pattern: "creditCard" }   // 4532-1234-5678-9012
{ type: "string", pattern: "jobTitle" }     // Software Engineer
{ type: "string", pattern: "company" }      // Acme Corporation
{ type: "string", pattern: "productName" }  // Awesome Widget
{ type: "string", pattern: "price" }        // $99.99

Complex Types

// Objects
{
  type: "object",
  properties: {
    name: { type: "string", pattern: "name" },
    age: { type: "number", min: 18, max: 80 }
  }
}

// Arrays
{
  type: "array",
  min: 2,
  max: 5,
  items: { type: "string", pattern: "email" }
}

// Nested structures
{
  type: "object",
  properties: {
    users: {
      type: "array",
      items: {
        type: "object",
        properties: {
          id: { type: "uuid" },
          email: { type: "email" }
        }
      }
    }
  }
}

⚙️ Schema Options

Optional Fields

{
  type: "string",
  pattern: "name",
  optional: true  // Field may be undefined (30% chance)
}

Nullable Fields

{
  type: "date",
  nullable: true  // Field may be null (10% chance)
}

Locale Support

{
  type: "string",
  pattern: "name",
  locale: "de"  // Generate German names
}

🛠️ API Reference

SchemaDemoFactory.create(schema)

Generate a single instance from schema.

const user = SchemaDemoFactory.create(userSchema);

SchemaDemoFactory.createMultiple(schema, count)

Generate multiple instances from schema.

const users = SchemaDemoFactory.createMultiple(userSchema, 10);

🎯 TypeScript Benefits

Full Type Inference

const userSchema = {
  type: "object",
  properties: {
    id: { type: "uuid" },
    email: { type: "email" },
    profile: {
      type: "object",
      properties: {
        firstName: { type: "string", pattern: "name" },
        lastName: { type: "string", pattern: "name" }
      }
    }
  }
} as const satisfies TypeSchema;

const user = SchemaDemoFactory.create(userSchema);
// TypeScript knows:
// user.id is string
// user.email is string  
// user.profile.firstName is string
// user.profile.lastName is string

Autocomplete Support

When defining schemas, you get full autocomplete for:

  • type field values
  • pattern field values
  • All available options

📦 Dependencies

🤝 Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🙏 Acknowledgments

  • Thanks to Faker.js for providing excellent mock data generation
  • Inspired by JSON Schema and OpenAPI specifications

Made with ❤️ for developers who need realistic mock data!