1.0.4 • Published 11 months ago

multi-json-to-ts v1.0.4

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
11 months ago

Multi-JSON-to-TS

Tests Linter

Takes multiple similar JSON objects, checks for structural differences and create TS interfaces. Useful for creating interfaces for the output of APIs that you don't know the structure of.

Installation

npm install multi-json-to-ts

Usage

import InterfaceGenerator from "multi-json-to-ts";

const variation1 = {
  name: "John",
  age: 30,
  birthplace: {
    city: "New York",
    state: "NY",
  },
  stats: [{ year: 2020, goals: 10 }],
};

const variation2 = {
  name: "Sarah",
  age: 20,
  birthplace: {
    city: "Toronto",
    country: "Canada",
  },
  stats: [{ year: 2020, assists: 5 }],
};

const interfaceGenerator = new InterfaceGenerator("IPerson", "./output", true);
// or const interfaceGenerator = new InterfaceGenerator("IPerson", "./output", true, [variation1, variation2]);

interfaceGenerator.addJsonVariation(variation1);
interfaceGenerator.addJsonVariation(variation2);

interfaceGenerator.generateInterfaces();

This will generate the following TypeScript interfaces:

// Generated by multi-json-to-ts

export interface IPerson_birthplace {
  city: string;
  state?: string;
  country?: string;
}

export interface IPerson_stats {
  year: number;
  goals?: number;
  assists?: number;
}

export interface IPerson {
  name: string;
  age: number;
  birthplace: IPerson_birthplace;
  stats: IPerson_stats[];
}
1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago