forge-type
v1.0.6
Published
Automatically generates TypeScript interfaces and types from JSON data, with enum detection.
Downloads
748
Maintainers
Readme
ForgeType
ForgeType is a TypeScript utility library that automatically generates types/interfaces from backend JSON data.
It also supports enum detection for short string fields and helps speed up frontend development by reducing boilerplate code.
Features
- Automatically generate TypeScript interfaces from any JSON data
- Detects enums for fields like
gender,role,status, and more - Handles nested objects and arrays
- Optional modification of existing types
- Clean, maintainable code generation for frontend teams
Installation
# Scoped package (public)
npm install forge-type
import { createTypeFromData } from 'forge-type'
const userData = {
id: 1,
name: 'John Doe',
gender: 'male',
role: 'admin',
status: 'active',
friends: [
{
id: 2,
name: 'Jane Smith',
age: '24',
gender: 'female',
city: 'many'
}
],
profile: {
bio: 'I love art',
website: 'https://example.com'
}
}
// Generate or update a TypeScript interface
const result = createTypeFromData('User', userData, { modify: true })
console.log('--- Generated Type ---')
console.log(result.type)
console.log('--- File Path ---')
console.log(result.filePath)
export interface User {
id: number;
name: string;
gender: "male" | "female";
role: "admin" | "user";
status: "active" | "inactive";
friends: Friend[];
profile: { bio: string; website: string };
}
export interface Friend {
id: number;
name: string;
age: string;
gender: "male" | "female";
city: string;
}