1.0.9 • Published 7 months ago

data-model-generator v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Data Model Generator

A library and CLI tool to generate TypeScript interfaces from various data sources like JSON, API responses and xml. Designed to improve code maintainability and reduce development time.

Features

  • Supports input types: JSON, XML, API responses.
  • CLI and programmatic usage.
  • Custom TypeScript mappings for field types.
  • Lightweight and flexible.

Installation

Node version used 16.10.0 npm version used 7.24.0

Using NPM

npm install -g <your-package-name>

How to Use

Using with JSON or Static Data
import { generateModelFromSource } from 'data-model-generator';

const jsonData = `{
  "name": "John",
  "age": 30,
  "isActive": true
}`;

const interfaceCode = generateModelFromSource(jsonData, 'json', { interfaceName: 'User' });
console.log(interfaceCode);

Using with API Responses
const getUserProfile = async () => {
  const response = await axios.get('https://api.example.com/user');
  const interfaceCode = generateModelFromSource(JSON.stringify(response.data), 'api', { interfaceName: 'UserProfile' });
  console.log(interfaceCode);
}

CLI Usage

Example Command
data-model-generator --type json --interfaceName User --inputFile data.json --outputFile userInterface.ts
or
npx data-model-generator --type json --interfaceName User --inputFile data.json --outputFile userInterface.ts
1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago