npm.io
0.0.9 • Published 7 years agoCLI

@l-l/2dts

Licence
MIT
Version
0.0.9
Deps
3
Size
24 kB
Vulns
0
Weekly
0

2dts

api.json转为typescript的类型定义文件

api.json => typing.d.ts

用法

npm install @l-l/2dts
  1. 命令行使用
2dts <path> <output>

例如:

2dts ./api.json ./typing.d.ts
  1. 引入包使用
const todts = require('@l-l/2dts')
const fs = require('fs');

// 读取api.json
const apiJson = JSON.parse(fs.readFileSync('xx/api.json').toString());

// 转换
const dts = todts(apiJson,{
  format: true, // 格式化
  utilType: true // 生成工具类型 
});

// 写
fs.writeFileSync('xx/typing.d.ts',  dts);