type-flash 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -20
- package/bin/{type-gen.js → type-flash.js} +17 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
# type-
|
|
3
|
+
# type-flash
|
|
4
4
|
|
|
5
5
|
**JSON 智能生成 TypeScript 类型定义**
|
|
6
6
|
|
|
7
|
-
[](https://www.npmjs.com/package/type-flash)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
10
|
> **One line of code, types generated instantly.**
|
|
@@ -50,19 +50,19 @@
|
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
52
|
# npm
|
|
53
|
-
npm install type-
|
|
53
|
+
npm install type-flash --save-dev
|
|
54
54
|
|
|
55
55
|
# yarn
|
|
56
|
-
yarn add type-
|
|
56
|
+
yarn add type-flash -D
|
|
57
57
|
|
|
58
58
|
# pnpm
|
|
59
|
-
pnpm add type-
|
|
59
|
+
pnpm add type-flash -D
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
### 一行代码上手
|
|
63
63
|
|
|
64
64
|
```typescript
|
|
65
|
-
import { generate } from 'type-
|
|
65
|
+
import { generate } from 'type-flash';
|
|
66
66
|
|
|
67
67
|
const jsonData = {
|
|
68
68
|
id: 1,
|
|
@@ -83,7 +83,7 @@ console.log(result.code);
|
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
85
|
/**
|
|
86
|
-
* Generated by type-
|
|
86
|
+
* Generated by type-flash
|
|
87
87
|
* Root type: User
|
|
88
88
|
*/
|
|
89
89
|
|
|
@@ -110,7 +110,7 @@ export interface UserProfile {
|
|
|
110
110
|
#### 基础用法
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
import { generate, generateFromString } from 'type-
|
|
113
|
+
import { generate, generateFromString } from 'type-flash';
|
|
114
114
|
|
|
115
115
|
// 从 JS 对象生成
|
|
116
116
|
const result1 = generate({ name: 'foo', age: 25 }, { rootName: 'User' });
|
|
@@ -128,7 +128,7 @@ console.log(result1.types);
|
|
|
128
128
|
#### 分页接口示例
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
|
-
import { generate } from 'type-
|
|
131
|
+
import { generate } from 'type-flash';
|
|
132
132
|
|
|
133
133
|
const apiResponse = {
|
|
134
134
|
code: 0,
|
|
@@ -187,35 +187,35 @@ export enum StatusEnum {
|
|
|
187
187
|
|
|
188
188
|
```bash
|
|
189
189
|
# 从文件生成,输出到控制台
|
|
190
|
-
type-
|
|
190
|
+
type-flash user.json
|
|
191
191
|
|
|
192
192
|
# 指定输出文件
|
|
193
|
-
type-
|
|
193
|
+
type-flash user.json -o user.types.ts
|
|
194
194
|
|
|
195
195
|
# 自定义根类型名
|
|
196
|
-
type-
|
|
196
|
+
type-flash user.json -n User
|
|
197
197
|
|
|
198
198
|
# 使用 type 风格输出
|
|
199
|
-
type-
|
|
199
|
+
type-flash data.json --style type
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
#### 高级用法
|
|
203
203
|
|
|
204
204
|
```bash
|
|
205
205
|
# 从标准输入读取(管道)
|
|
206
|
-
curl https://api.example.com/users | type-
|
|
206
|
+
curl https://api.example.com/users | type-flash -n UserList
|
|
207
207
|
|
|
208
208
|
# 生成带注释的类型定义
|
|
209
|
-
type-
|
|
209
|
+
type-flash api.json --comments -o api-types.ts
|
|
210
210
|
|
|
211
211
|
# 严格空值模式
|
|
212
|
-
type-
|
|
212
|
+
type-flash data.json --strict-null
|
|
213
213
|
|
|
214
214
|
# 添加类型前缀
|
|
215
|
-
type-
|
|
215
|
+
type-flash response.json --prefix I -o interfaces.ts
|
|
216
216
|
|
|
217
217
|
# 不生成 export
|
|
218
|
-
type-
|
|
218
|
+
type-flash types.json --no-export
|
|
219
219
|
```
|
|
220
220
|
|
|
221
221
|
#### 所有 CLI 选项
|
|
@@ -301,7 +301,7 @@ interface GenerateOptions {
|
|
|
301
301
|
#### 企业级 DTO 配置
|
|
302
302
|
|
|
303
303
|
```typescript
|
|
304
|
-
import { generate } from 'type-
|
|
304
|
+
import { generate } from 'type-flash';
|
|
305
305
|
|
|
306
306
|
const result = generate(jsonData, {
|
|
307
307
|
rootName: 'UserDTO',
|
|
@@ -338,7 +338,7 @@ const result = generate(jsonData, {
|
|
|
338
338
|
|
|
339
339
|
### 与其他方案对比
|
|
340
340
|
|
|
341
|
-
| 特性 | type-
|
|
341
|
+
| 特性 | type-flash | json-schema-to-typescript | 在线转换工具 | quicktype |
|
|
342
342
|
|------|--------|---------------------------|--------------|-----------|
|
|
343
343
|
| **直接输入 JSON** | ✅ | ❌ 需要 JSON Schema | ✅ | ✅ |
|
|
344
344
|
| **嵌套对象自动命名** | ✅ 智能命名 | ✅ | ⚠️ 简单命名 | ✅ |
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* type-
|
|
3
|
+
* type-flash CLI - 命令行工具
|
|
4
4
|
*
|
|
5
5
|
* 用法:
|
|
6
|
-
* type-
|
|
7
|
-
* type-
|
|
8
|
-
* cat data.json | type-
|
|
6
|
+
* type-flash <input.json> [options]
|
|
7
|
+
* type-flash -i input.json -o output.ts
|
|
8
|
+
* cat data.json | type-flash
|
|
9
9
|
*
|
|
10
10
|
* 示例:
|
|
11
|
-
* type-
|
|
12
|
-
* type-
|
|
13
|
-
* curl https://api.example.com/users | type-
|
|
11
|
+
* type-flash user.json -n User
|
|
12
|
+
* type-flash api.json --style type --no-export
|
|
13
|
+
* curl https://api.example.com/users | type-flash -n UserList
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
@@ -142,12 +142,12 @@ function parseArgs(argv) {
|
|
|
142
142
|
// 显示帮助信息
|
|
143
143
|
function showHelp() {
|
|
144
144
|
console.log(`
|
|
145
|
-
type-
|
|
145
|
+
type-flash - JSON 智能生成 TypeScript 类型定义
|
|
146
146
|
|
|
147
147
|
用法:
|
|
148
|
-
type-
|
|
149
|
-
type-
|
|
150
|
-
cat data.json | type-
|
|
148
|
+
type-flash <input.json> [options]
|
|
149
|
+
type-flash -i input.json -o output.ts
|
|
150
|
+
cat data.json | type-flash
|
|
151
151
|
|
|
152
152
|
选项:
|
|
153
153
|
-i, --input <file> 输入 JSON 文件路径
|
|
@@ -171,16 +171,16 @@ type-gen - JSON 智能生成 TypeScript 类型定义
|
|
|
171
171
|
|
|
172
172
|
示例:
|
|
173
173
|
# 从文件生成
|
|
174
|
-
type-
|
|
174
|
+
type-flash user.json -n User -o user.ts
|
|
175
175
|
|
|
176
176
|
# 使用 type 风格输出
|
|
177
|
-
type-
|
|
177
|
+
type-flash data.json --style type
|
|
178
178
|
|
|
179
179
|
# 从标准输入读取
|
|
180
|
-
curl https://api.example.com/data | type-
|
|
180
|
+
curl https://api.example.com/data | type-flash -n ApiResponse
|
|
181
181
|
|
|
182
182
|
# 带前缀和注释
|
|
183
|
-
type-
|
|
183
|
+
type-flash api.json --prefix Api --comments -o api-types.ts
|
|
184
184
|
`);
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -189,9 +189,9 @@ function showVersion() {
|
|
|
189
189
|
try {
|
|
190
190
|
const pkgPath = path.join(__dirname, '..', 'package.json');
|
|
191
191
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
192
|
-
console.log(`type-
|
|
192
|
+
console.log(`type-flash v${pkg.version}`);
|
|
193
193
|
} catch (e) {
|
|
194
|
-
console.log('type-
|
|
194
|
+
console.log('type-flash (unknown version)');
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-flash",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "JSON 智能生成 TypeScript 类型定义 - 一键从 JSON 数据生成 Interface / Type 定义",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
9
|
"type-flash": "bin/type-flash.js"
|