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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@demokit-ai/codegen

v0.2.0

Published

Demo data generation and validation for DemoKit

Readme

@demokit-ai/codegen

Tests Coverage

Demo data generation and validation for DemoKit - create realistic fixtures from schemas.

Installation

npm install @demokit-ai/codegen @demokit-ai/schema

Features

  • Data Generation - Generate realistic demo data from schemas
  • ID Generation - UUID, CUID, ULID, and custom ID formats
  • Value Generators - Smart generators for emails, names, addresses, dates, etc.
  • Validation - Validate generated data against schemas
  • Output Formatters - Export to TypeScript, JSON, SQL, or CSV
  • Full TypeScript support

Usage

Generate Demo Data

import { generateDemoData } from '@demokit-ai/codegen'

const schema = {
  models: {
    User: {
      properties: {
        id: { type: 'string', format: 'uuid' },
        name: { type: 'string' },
        email: { type: 'string', format: 'email' },
        createdAt: { type: 'string', format: 'date-time' },
      },
    },
    Order: {
      properties: {
        id: { type: 'string', format: 'uuid' },
        userId: { type: 'string', relationshipTo: { model: 'User', field: 'id' } },
        total: { type: 'number', minimum: 0 },
        status: { type: 'string', enum: ['pending', 'completed', 'cancelled'] },
      },
    },
  },
}

const data = generateDemoData(schema, {
  recordCounts: { User: 5, Order: 10 },
  seed: 42, // For reproducible output
})

ID Generation

import {
  generateUUID,
  generateSeededUUID,
  generateCuid,
  generateUlid,
  generatePrefixedId,
} from '@demokit-ai/codegen'

// Random UUID v4
const uuid = generateUUID()
// '550e8400-e29b-41d4-a716-446655440000'

// Deterministic UUID from seed
const seededUuid = generateSeededUUID(12345)

// CUID-like ID
const cuid = generateCuid()
// 'clxxxxxxxxxxxxxxxx'

// ULID
const ulid = generateUlid()
// '01ARZ3NDEKTSV4RRFFQ69G5FAV'

// Prefixed ID
const userId = generatePrefixedId('user', 1)
// 'user_001'

Value Generation

import { generateValue } from '@demokit-ai/codegen'

// Email
const email = generateValue({ type: 'string', name: 'email' }, 0)
// '[email protected]'

// Person name
const name = generateValue({ type: 'string', name: 'name' }, 0)
// 'Emma Smith'

// Price
const price = generateValue({ type: 'number', name: 'price' }, 0)
// 19.99

// Status from enum
const status = generateValue({
  type: 'string',
  name: 'status',
  enum: ['active', 'pending', 'inactive']
}, 0)
// 'active'

Data Validation

import { validateData } from '@demokit-ai/codegen'

const result = validateData(generatedData, { schema })

if (!result.valid) {
  console.log('Validation errors:', result.errors)
  // [{ type: 'type_mismatch', model: 'User', field: 'age', ... }]
}

console.log('Stats:', result.stats)
// { totalRecords: 15, recordsByModel: { User: 5, Order: 10 }, durationMs: 12 }

Output Formatting

TypeScript

import { formatAsTypeScript } from '@demokit-ai/codegen'

const tsCode = formatAsTypeScript(data, {
  asConst: true,
  includeHeader: true,
  narrative: {
    scenario: 'E-commerce demo',
    keyPoints: ['5 users', '10 orders'],
  },
})

// Output:
// /**
//  * Auto-generated demo fixtures
//  * Scenario: E-commerce demo
//  */
// export const DEMO_USER = [...] as const
// export const DEMO_ORDER = [...] as const
// export const DEMO_DATA = { User: DEMO_USER, Order: DEMO_ORDER } as const

JSON

import { formatAsJSON } from '@demokit-ai/codegen'

const json = formatAsJSON(data, { includeMetadata: true })
// { "_metadata": { "generatedAt": "...", "recordCount": 15 }, "data": {...} }

SQL

import { formatAsSQL } from '@demokit-ai/codegen'

const sql = formatAsSQL(data, {
  tableName: (model) => `demo_${model.toLowerCase()}`,
})
// INSERT INTO demo_user (id, name, email) VALUES ('1', 'Alice', '[email protected]');

CSV

import { formatAsCSV } from '@demokit-ai/codegen'

const userCsv = formatAsCSV(data, 'User')
// id,name,email
// 1,Alice,[email protected]

API Reference

Generation

generateDemoData(schema, options)

Generate demo data from a schema.

Options:

  • recordCounts - Number of records per model
  • seed - Random seed for reproducibility
  • baseTimestamp - Base timestamp for date generation

ID Generation

  • generateUUID() - Random UUID v4
  • generateSeededUUID(seed) - Deterministic UUID from seed
  • generateCuid() - CUID-like ID
  • generateUlid() - ULID
  • generatePrefixedId(prefix, index) - Prefixed ID (e.g., 'user_001')
  • generateIdForModel(model, index, format?) - Model-specific ID

Validation

validateData(data, options)

Validate data against a schema.

Options:

  • schema - Schema to validate against
  • failFast - Stop on first error
  • maxErrors - Maximum errors to collect
  • collectWarnings - Include warnings in result

Returns:

  • valid - Whether data is valid
  • errors - Array of validation errors
  • warnings - Array of warnings
  • stats - Validation statistics

Formatters

  • formatAsTypeScript(data, options) - TypeScript module
  • formatAsJSON(data, options) - JSON with optional metadata
  • formatAsSQL(data, options) - SQL INSERT statements
  • formatAsCSV(data, modelName) - CSV for a single model

License

MIT