ts2interface
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

ts2interface

Convert arbitrary formats to Typescript Interface(including json, toml, yaml, etc.)

Installation

Run the following command under your project:

npm i ts2install

Feature

  • [x] Object to interface
  • [x] JSON to interface
  • [x] YAML to interface
  • [ ] TOML to interface

Quick Start

Object to interface

import { object2interface } from "../src/json"

const obj = {
    name: "nice",
    age: 12,
}

const result = object2interface(obj, {
    indent: 4,
    rootName: "Example",
    semi: false,
    useTab: true,
})

console.log(result)

print:

interface Example {
    name: string
    age: number
}

JSON to interface

import { json2interface } from "../src/json"

const jsonStr = `
{
    "name": "nice",
    "age": 12
}
`

const result = json2interface(jsonStr, {
    indent: 4,
    rootName: "Example",
    semi: false,
    useTab: true,
})

console.log(result)

print:

interface Example {
    name: string
    age: number
}

YAML to interface

import { yaml2interface } from "../src/json"

const yamlStr = `
name: nice
age: 12
`

const result = yaml2interface(yamlStr, {
    indent: 4,
    rootName: "Example",
    semi: false,
    useTab: true,
})

console.log(result)

print:

interface Example {
    name: string
    age: number
}

/ts2interface/

    Package Sidebar

    Install

    npm i ts2interface

    Weekly Downloads

    4

    Version

    1.0.8

    License

    Apache

    Unpacked Size

    20.2 kB

    Total Files

    13

    Last publish

    Collaborators

    • afly