1.0.0 • Published 2 years ago

@xdoer/json-ts v1.0.0

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

JSON Types Generator

A Json Types Generator For TypeScript

Install

npm install @xdoer/json-ts

Usage

import jsonTypesGenerator from '@xdoer/json-ts'

const jsonStr = `
{
  "date": "2021-08-28",
  "season": "ordinary",
  "season_week": 21,
  "celebrations": [
    {
      "title": "Saint Augustine of Hippo, bishop and doctor of the Church",
      "colour": "white",
      "rank": "memorial",
      "rank_num": 3.1
    }
  ],
  "weekday": "saturday"
}
`

// input
console.log(jsonTypesGenerator(JSON.parse(jsonStr), 'Result'))

// output
export interface Data {
  title: string

  author: any

  content: string
}

export interface Result {
  state: boolean

  time: string

  data: Data[][]
}

Test

You can add json file to test/data folder, and run npm test command, then observe whether the output of test/output meets expectations