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

0.0.6 • Public • Published

介绍

json2type

通过一套 json 协议自动生成 ts 类型

功能

支持以下 ts 类型的转换

  • String
  • Number
  • Boolean
  • Any
  • Never
  • Undefined
  • Null
  • Void
  • Object
  • Array
  • Intersection
  • Union
  • Tuple
  • Enum

快速开始

tnpm install json2type
// 简单的例子
const json2type= require('json2type')
json2type({
      type: 'Number',
      description: '测试number',
      name: 'b',
      required: true,
      children: []
})

// res ->

// 测试number
export type B = number;

复杂的示例

API

  • json2type
declare const json2type: (json: Json2type) => string;
  • genSplitTypes
declare const genSplitTypes: (json: Json2type) => string;

json 协议

export interface Json2type{
  // 类型
  type: 'String' | 'Number' | 'Boolean' | 'Any' | 'Never' | 'Undefined' | 'Null' | 'Void' | 'Object' | 'Array' | 'Intersection' | 'Union' | 'Tuple' | 'Enum';
  // 注释
  description?: string;
  // key
  name: string;
  // 是否一直存在
  required?: boolean;
  // 子节点
  children: Json2type[];
  // 值
  value?: string | number
}

Package Sidebar

Install

npm i json2type

Weekly Downloads

5

Version

0.0.6

License

ISC

Unpacked Size

91.8 kB

Total Files

27

Last publish

Collaborators

  • asyalas