1.0.3 • Published 2 years ago

@jamielhf/jsontots v1.0.3

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

@jamielhf/jsontots

NPM version NPM download

一个 json 字符串转 ts 的工具,支持注释的转换

安装

npm install @jamielhf/jsontots --save
// or
yarn add @jamielhf/jsontots

怎么使用

import jsontots from "@jamielhf/jsontots";

const json = `{
  button: {
    description: "按钮组件",
    props: [
      {
        name: "htmlType",
        type: '"button" | "submit" | "reset"',
        default: "",
        description: "Button 类型",
        required: false,
      },
    ],
  },
}`;
const ts = json2ts(json);

// ts
export namespace namespace {
  export interface Props {
    name: string;
    type: string;
    default: string;
    description: string;
    required: boolean;
  }
  export interface Button {
    description: string;
    props: Props[];
  }
  export interface RootObject {
    Button: Button;
  }
}

options

namespace

string 自定义 namespace

const ts = json2ts(json, {
  namespace: "test",
});

其他

工具 https://astexplorer.net/