type-flash 1.0.6 → 1.0.7
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 +0 -18
- package/bin/type-flash.js +0 -14
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
|
|
30
30
|
### ⚡ 增强功能
|
|
31
31
|
|
|
32
|
-
- **📑 枚举自动提取** - 字符串字段取值有限时,自动提取为 `enum` 枚举类型
|
|
33
32
|
- **🧬 泛型模式识别** - 智能识别分页结构 `{ list: T[], total: number }`,提取为 `PageResult<T>`
|
|
34
33
|
- **📝 JSDoc 注释生成** - 根据字段名猜测含义,自动生成文档注释
|
|
35
34
|
- **🎨 多种输出风格** - 支持 `interface` 和 `type alias` 两种输出风格
|
|
@@ -146,7 +145,6 @@ const apiResponse = {
|
|
|
146
145
|
|
|
147
146
|
const result = generate(apiResponse, {
|
|
148
147
|
rootName: 'ApiResponse',
|
|
149
|
-
extractEnums: true,
|
|
150
148
|
extractGenerics: true,
|
|
151
149
|
});
|
|
152
150
|
|
|
@@ -172,12 +170,6 @@ export interface ApiResponseData {
|
|
|
172
170
|
export interface ListItem {
|
|
173
171
|
id: number;
|
|
174
172
|
name: string;
|
|
175
|
-
status: StatusEnum;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export enum StatusEnum {
|
|
179
|
-
ACTIVE = 'active',
|
|
180
|
-
INACTIVE = 'inactive',
|
|
181
173
|
}
|
|
182
174
|
```
|
|
183
175
|
|
|
@@ -232,8 +224,6 @@ type-flash types.json --no-export
|
|
|
232
224
|
| `--comments` | 生成 JSDoc 注释 | - |
|
|
233
225
|
| `--strict-null` | 严格空值模式 | - |
|
|
234
226
|
| `--no-optional` | 不标记可选属性 | - |
|
|
235
|
-
| `--no-enums` | 不提取枚举类型 | - |
|
|
236
|
-
| `--enum-threshold <n>` | 枚举提取阈值 | `5` |
|
|
237
227
|
| `--no-generics` | 不提取泛型类型 | - |
|
|
238
228
|
| `--indent <n>` | 缩进空格数 | `2` |
|
|
239
229
|
| `--prefix <prefix>` | 类型名前缀 | - |
|
|
@@ -273,12 +263,6 @@ interface GenerateOptions {
|
|
|
273
263
|
/** 是否标记可选属性,默认 true */
|
|
274
264
|
markOptional?: boolean;
|
|
275
265
|
|
|
276
|
-
/** 是否提取枚举类型,默认 true */
|
|
277
|
-
extractEnums?: boolean;
|
|
278
|
-
|
|
279
|
-
/** 枚举提取阈值,默认 5 */
|
|
280
|
-
enumThreshold?: number;
|
|
281
|
-
|
|
282
266
|
/** 是否提取泛型,默认 true */
|
|
283
267
|
extractGenerics?: boolean;
|
|
284
268
|
|
|
@@ -312,8 +296,6 @@ const result = generate(jsonData, {
|
|
|
312
296
|
addExport: true,
|
|
313
297
|
addComments: true,
|
|
314
298
|
sortProperties: 'alpha',
|
|
315
|
-
extractEnums: true,
|
|
316
|
-
enumThreshold: 8,
|
|
317
299
|
extractGenerics: true,
|
|
318
300
|
strictNullChecks: true,
|
|
319
301
|
indentSize: 2,
|
package/bin/type-flash.js
CHANGED
|
@@ -31,8 +31,6 @@ function parseArgs(argv) {
|
|
|
31
31
|
addComments: false,
|
|
32
32
|
strictNullChecks: false,
|
|
33
33
|
markOptional: true,
|
|
34
|
-
extractEnums: true,
|
|
35
|
-
enumThreshold: 5,
|
|
36
34
|
extractGenerics: true,
|
|
37
35
|
indentSize: 2,
|
|
38
36
|
typePrefix: '',
|
|
@@ -101,14 +99,6 @@ function parseArgs(argv) {
|
|
|
101
99
|
args.markOptional = false;
|
|
102
100
|
break;
|
|
103
101
|
|
|
104
|
-
case '--no-enums':
|
|
105
|
-
args.extractEnums = false;
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case '--enum-threshold':
|
|
109
|
-
args.enumThreshold = parseInt(argv[++i], 10);
|
|
110
|
-
break;
|
|
111
|
-
|
|
112
102
|
case '--no-generics':
|
|
113
103
|
args.extractGenerics = false;
|
|
114
104
|
break;
|
|
@@ -160,8 +150,6 @@ type-flash - JSON 智能生成 TypeScript 类型定义
|
|
|
160
150
|
--comments 生成 JSDoc 注释
|
|
161
151
|
--strict-null 严格空值模式(保留 null 类型)
|
|
162
152
|
--no-optional 不标记可选属性
|
|
163
|
-
--no-enums 不提取枚举类型
|
|
164
|
-
--enum-threshold <n> 枚举提取阈值(默认: 5)
|
|
165
153
|
--no-generics 不提取泛型类型
|
|
166
154
|
--indent <n> 缩进空格数(默认: 2)
|
|
167
155
|
--prefix <prefix> 类型名前缀
|
|
@@ -273,8 +261,6 @@ async function main() {
|
|
|
273
261
|
addComments: args.addComments,
|
|
274
262
|
strictNullChecks: args.strictNullChecks,
|
|
275
263
|
markOptional: args.markOptional,
|
|
276
|
-
extractEnums: args.extractEnums,
|
|
277
|
-
enumThreshold: args.enumThreshold,
|
|
278
264
|
extractGenerics: args.extractGenerics,
|
|
279
265
|
indentSize: args.indentSize,
|
|
280
266
|
typePrefix: args.typePrefix,
|
package/dist/index.d.mts
CHANGED
|
@@ -139,7 +139,7 @@ interface GenerateResult {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* type-flash - 命名与去重模块
|
|
143
143
|
*
|
|
144
144
|
* 核心功能:
|
|
145
145
|
* - 根据字段名 + 上下文自动生成有意义的类型名
|
|
@@ -280,7 +280,7 @@ declare class TypeCollector {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
|
-
*
|
|
283
|
+
* type-flash - 格式化输出模块
|
|
284
284
|
*
|
|
285
285
|
* 核心功能:
|
|
286
286
|
* - 将类型节点格式化为 TypeScript 代码字符串
|
|
@@ -360,7 +360,7 @@ declare function guessCommentFromFieldName(fieldName: string): string | undefine
|
|
|
360
360
|
declare function addGuessedComments(type: ObjectType): ObjectType;
|
|
361
361
|
|
|
362
362
|
/**
|
|
363
|
-
*
|
|
363
|
+
* type-flash - 类型推断引擎
|
|
364
364
|
*
|
|
365
365
|
* 核心功能:
|
|
366
366
|
* - 基础类型识别(string、number、boolean、null、undefined)
|
|
@@ -408,7 +408,7 @@ declare function inferObjectType(obj: Record<string, unknown>): ObjectType;
|
|
|
408
408
|
declare function isStructurallyEqual(a: TSTypeNode, b: TSTypeNode): boolean;
|
|
409
409
|
|
|
410
410
|
/**
|
|
411
|
-
*
|
|
411
|
+
* type-flash - 增强功能模块
|
|
412
412
|
*
|
|
413
413
|
* 核心功能:
|
|
414
414
|
* - 泛型提取(如 PageResult<T>)
|
|
@@ -448,7 +448,7 @@ declare class OptionalHandler {
|
|
|
448
448
|
declare function applyEnhancements(jsonData: any, type: TSTypeNode, options: GenerateOptions): TSTypeNode;
|
|
449
449
|
|
|
450
450
|
/**
|
|
451
|
-
*
|
|
451
|
+
* type-flash - JSON 智能生成 TypeScript 类型定义
|
|
452
452
|
*
|
|
453
453
|
* 主入口文件
|
|
454
454
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ interface GenerateResult {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* type-flash - 命名与去重模块
|
|
143
143
|
*
|
|
144
144
|
* 核心功能:
|
|
145
145
|
* - 根据字段名 + 上下文自动生成有意义的类型名
|
|
@@ -280,7 +280,7 @@ declare class TypeCollector {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
|
-
*
|
|
283
|
+
* type-flash - 格式化输出模块
|
|
284
284
|
*
|
|
285
285
|
* 核心功能:
|
|
286
286
|
* - 将类型节点格式化为 TypeScript 代码字符串
|
|
@@ -360,7 +360,7 @@ declare function guessCommentFromFieldName(fieldName: string): string | undefine
|
|
|
360
360
|
declare function addGuessedComments(type: ObjectType): ObjectType;
|
|
361
361
|
|
|
362
362
|
/**
|
|
363
|
-
*
|
|
363
|
+
* type-flash - 类型推断引擎
|
|
364
364
|
*
|
|
365
365
|
* 核心功能:
|
|
366
366
|
* - 基础类型识别(string、number、boolean、null、undefined)
|
|
@@ -408,7 +408,7 @@ declare function inferObjectType(obj: Record<string, unknown>): ObjectType;
|
|
|
408
408
|
declare function isStructurallyEqual(a: TSTypeNode, b: TSTypeNode): boolean;
|
|
409
409
|
|
|
410
410
|
/**
|
|
411
|
-
*
|
|
411
|
+
* type-flash - 增强功能模块
|
|
412
412
|
*
|
|
413
413
|
* 核心功能:
|
|
414
414
|
* - 泛型提取(如 PageResult<T>)
|
|
@@ -448,7 +448,7 @@ declare class OptionalHandler {
|
|
|
448
448
|
declare function applyEnhancements(jsonData: any, type: TSTypeNode, options: GenerateOptions): TSTypeNode;
|
|
449
449
|
|
|
450
450
|
/**
|
|
451
|
-
*
|
|
451
|
+
* type-flash - JSON 智能生成 TypeScript 类型定义
|
|
452
452
|
*
|
|
453
453
|
* 主入口文件
|
|
454
454
|
*/
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var O={rootName:"Root",outputStyle:"interface",namingStyle:"PascalCase",sortProp
|
|
|
6
6
|
`)}formatAll(e){return this.allNamedTypes=e,e.map(t=>this.formatTypeDef(t)).join(`
|
|
7
7
|
|
|
8
8
|
`)}generateOutput(e,t){let r=`/**
|
|
9
|
-
* Generated by
|
|
9
|
+
* Generated by type-flash
|
|
10
10
|
* Root type: ${t}
|
|
11
11
|
*/`,i=this.formatAll(e);return`${r}
|
|
12
12
|
|