UCD.js Docs

Codegen

AI-powered TypeScript field generation

Codegen

AI-powered TypeScript field generation for Unicode data files.

Installation

npm install @ucdjs/codegen

Overview

The @ucdjs/codegen package provides tools to automatically generate TypeScript interfaces and field definitions from raw Unicode data files using AI models.

Usage

The primary function is runCodegen, which processes a list of files and generates TypeScript code.

generate.ts
import { runCodegen } from "@ucdjs/codegen";

const results = await runCodegen({
  files: [
    {
      filePath: "./data/UnicodeData.txt",
      version: "15.1.0"
    }
  ],
  openaiKey: process.env.OPENAI_API_KEY,
  // Alternatively, provide a custom AI model
  // model: myCustomModel
});

for (const result of results) {
  console.log(`Generated code for ${result.fileName}:`);
  console.log(result.code);
}

You must provide either an openaiKey or a custom model (from the AI SDK) to use the code generator.

On this page