1.0.8 • Published 2 years ago

ts2interface v1.0.8

Weekly downloads
-
License
Apache
Repository
github
Last release
2 years ago

ts2interface

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

Installation

Run the following command under your project:

npm i ts2install

Feature

  • Object to interface
  • JSON to interface
  • 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
}
1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago