config2ts 2.2.6 → 2.2.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/config/data.csv +7 -7
- package/config/data.csv.ts +5 -0
- package/config/total.ts +5 -0
- package/data.csv +7 -0
- package/data.csv.ts +108 -0
- package/package.json +1 -1
- package/src/config2ts.js +14 -1
package/config/data.csv
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
id,name,bool,num,mytype,stringarray,numberarray,typearray
|
|
2
|
-
Index,String,Boolean,Number,Enum,String[],Number[],Enum[]
|
|
3
|
-
1,xxx,1,111,type1,"1, 2, 3","1, 2, 3",t1
|
|
4
|
-
2,xxx,,222,type2,"a,b",,"t1,t2"
|
|
5
|
-
3,333,,NaN,,,"1,2","t2,t3,t4"
|
|
6
|
-
|
|
7
|
-
4,444,0,Infinity,type2,",1,,b",",1,,3"
|
|
1
|
+
id,name,bool,num,mytype,stringarray,numberarray,typearray,space field/sub
|
|
2
|
+
Index,String,Boolean,Number,Enum,String[],Number[],Enum[],String
|
|
3
|
+
1,xxx,1,111,type1,"1, 2, 3","1, 2, 3",t1,a
|
|
4
|
+
2,xxx,,222,type2,"a,b",,"t1,t2",a
|
|
5
|
+
3,333,,NaN,,,"1,2","t2,t3,t4",b
|
|
6
|
+
,,,,,,,,
|
|
7
|
+
4,444,0,Infinity,type2,",1,,b",",1,,3",,c
|
package/config/data.csv.ts
CHANGED
|
@@ -15,6 +15,7 @@ export namespace DataCsv {
|
|
|
15
15
|
stringarray: string[];
|
|
16
16
|
numberarray: number[];
|
|
17
17
|
typearray: typearray[];
|
|
18
|
+
'space field/sub': string;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
export const List: Record[] = [
|
|
@@ -37,6 +38,7 @@ export namespace DataCsv {
|
|
|
37
38
|
typearray: [
|
|
38
39
|
't1',
|
|
39
40
|
],
|
|
41
|
+
'space field/sub': 'a',
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
id: '2',
|
|
@@ -55,6 +57,7 @@ export namespace DataCsv {
|
|
|
55
57
|
't1',
|
|
56
58
|
't2',
|
|
57
59
|
],
|
|
60
|
+
'space field/sub': 'a',
|
|
58
61
|
},
|
|
59
62
|
{
|
|
60
63
|
id: '3',
|
|
@@ -74,6 +77,7 @@ export namespace DataCsv {
|
|
|
74
77
|
't3',
|
|
75
78
|
't4',
|
|
76
79
|
],
|
|
80
|
+
'space field/sub': 'b',
|
|
77
81
|
},
|
|
78
82
|
{
|
|
79
83
|
id: '4',
|
|
@@ -94,6 +98,7 @@ export namespace DataCsv {
|
|
|
94
98
|
3,
|
|
95
99
|
],
|
|
96
100
|
typearray: [],
|
|
101
|
+
'space field/sub': 'c',
|
|
97
102
|
},
|
|
98
103
|
];
|
|
99
104
|
|
package/config/total.ts
CHANGED
|
@@ -15,6 +15,7 @@ export namespace DataCsv {
|
|
|
15
15
|
stringarray: string[];
|
|
16
16
|
numberarray: number[];
|
|
17
17
|
typearray: typearray[];
|
|
18
|
+
'space field/sub': string;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
export const List: Record[] = [
|
|
@@ -37,6 +38,7 @@ export namespace DataCsv {
|
|
|
37
38
|
typearray: [
|
|
38
39
|
't1',
|
|
39
40
|
],
|
|
41
|
+
'space field/sub': 'a',
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
id: '2',
|
|
@@ -55,6 +57,7 @@ export namespace DataCsv {
|
|
|
55
57
|
't1',
|
|
56
58
|
't2',
|
|
57
59
|
],
|
|
60
|
+
'space field/sub': 'a',
|
|
58
61
|
},
|
|
59
62
|
{
|
|
60
63
|
id: '3',
|
|
@@ -74,6 +77,7 @@ export namespace DataCsv {
|
|
|
74
77
|
't3',
|
|
75
78
|
't4',
|
|
76
79
|
],
|
|
80
|
+
'space field/sub': 'b',
|
|
77
81
|
},
|
|
78
82
|
{
|
|
79
83
|
id: '4',
|
|
@@ -94,6 +98,7 @@ export namespace DataCsv {
|
|
|
94
98
|
3,
|
|
95
99
|
],
|
|
96
100
|
typearray: [],
|
|
101
|
+
'space field/sub': 'c',
|
|
97
102
|
},
|
|
98
103
|
];
|
|
99
104
|
|
package/data.csv
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
id,name,bool,num,mytype,stringarray,numberarray,typearray,space field/sub
|
|
2
|
+
Index,String,Boolean,Number,Enum,String[],Number[],Enum[],String
|
|
3
|
+
1,xxx,1,111,type1,"1, 2, 3","1, 2, 3",t1,a
|
|
4
|
+
2,xxx,,222,type2,"a,b",,"t1,t2",a
|
|
5
|
+
3,333,,NaN,,,"1,2","t2,t3,t4",b
|
|
6
|
+
,,,,,,,,
|
|
7
|
+
4,444,0,Infinity,type2,",1,,b",",1,,3",,c
|
package/data.csv.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export namespace DataCsv {
|
|
2
|
+
|
|
3
|
+
export type mytype = "type1" | "type2" | "";
|
|
4
|
+
export const mytypeList: mytype[] = ["type1", "type2", ""];
|
|
5
|
+
|
|
6
|
+
export type typearray = "t1" | "t2" | "t3" | "t4";
|
|
7
|
+
export const typearrayList: typearray[] = ["t1", "t2", "t3", "t4"];
|
|
8
|
+
|
|
9
|
+
export interface Record {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
bool: boolean;
|
|
13
|
+
num: number;
|
|
14
|
+
mytype: mytype;
|
|
15
|
+
stringarray: string[];
|
|
16
|
+
numberarray: number[];
|
|
17
|
+
typearray: typearray[];
|
|
18
|
+
space field/sub: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const List: Record[] = [
|
|
22
|
+
{
|
|
23
|
+
id: '1',
|
|
24
|
+
name: 'xxx',
|
|
25
|
+
bool: true,
|
|
26
|
+
num: 111,
|
|
27
|
+
mytype: 'type1',
|
|
28
|
+
stringarray: [
|
|
29
|
+
'1',
|
|
30
|
+
' 2',
|
|
31
|
+
' 3',
|
|
32
|
+
],
|
|
33
|
+
numberarray: [
|
|
34
|
+
1,
|
|
35
|
+
2,
|
|
36
|
+
3,
|
|
37
|
+
],
|
|
38
|
+
typearray: [
|
|
39
|
+
't1',
|
|
40
|
+
],
|
|
41
|
+
'space field/sub': 'a',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: '2',
|
|
45
|
+
name: 'xxx',
|
|
46
|
+
bool: false,
|
|
47
|
+
num: 222,
|
|
48
|
+
mytype: 'type2',
|
|
49
|
+
stringarray: [
|
|
50
|
+
'a',
|
|
51
|
+
'b',
|
|
52
|
+
],
|
|
53
|
+
numberarray: [
|
|
54
|
+
0,
|
|
55
|
+
],
|
|
56
|
+
typearray: [
|
|
57
|
+
't1',
|
|
58
|
+
't2',
|
|
59
|
+
],
|
|
60
|
+
'space field/sub': 'a',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: '3',
|
|
64
|
+
name: '333',
|
|
65
|
+
bool: false,
|
|
66
|
+
num: NaN,
|
|
67
|
+
mytype: '',
|
|
68
|
+
stringarray: [
|
|
69
|
+
'',
|
|
70
|
+
],
|
|
71
|
+
numberarray: [
|
|
72
|
+
1,
|
|
73
|
+
2,
|
|
74
|
+
],
|
|
75
|
+
typearray: [
|
|
76
|
+
't2',
|
|
77
|
+
't3',
|
|
78
|
+
't4',
|
|
79
|
+
],
|
|
80
|
+
'space field/sub': 'b',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: '4',
|
|
84
|
+
name: '444',
|
|
85
|
+
bool: true,
|
|
86
|
+
num: Infinity,
|
|
87
|
+
mytype: 'type2',
|
|
88
|
+
stringarray: [
|
|
89
|
+
'',
|
|
90
|
+
'1',
|
|
91
|
+
'',
|
|
92
|
+
'b',
|
|
93
|
+
],
|
|
94
|
+
numberarray: [
|
|
95
|
+
0,
|
|
96
|
+
1,
|
|
97
|
+
0,
|
|
98
|
+
3,
|
|
99
|
+
],
|
|
100
|
+
typearray: [],
|
|
101
|
+
'space field/sub': 'c',
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
export const Map: { [id: string]: Record } = {};
|
|
106
|
+
for (const v of List) { Map[v.id] = v; };
|
|
107
|
+
|
|
108
|
+
};
|
package/package.json
CHANGED
package/src/config2ts.js
CHANGED
|
@@ -98,7 +98,6 @@ function csv2ts(csvString, moduleName) {
|
|
|
98
98
|
for (var field in convert) {
|
|
99
99
|
// var fieldType = convert[field] !== '' ? convert[field].toLowerCase() : 'string';
|
|
100
100
|
// console.log(`generate interface field: ${field}, convert[field]: ${convert[field]}`);
|
|
101
|
-
|
|
102
101
|
var fieldType = 'string';
|
|
103
102
|
|
|
104
103
|
if (convert[field] != '') {
|
|
@@ -113,6 +112,7 @@ function csv2ts(csvString, moduleName) {
|
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
115
|
+
field = serializeField(field)
|
|
116
116
|
template += " ".concat(field, ": ").concat(fieldType, ";\n");
|
|
117
117
|
}
|
|
118
118
|
template += ' };\n\n';
|
|
@@ -136,6 +136,19 @@ function csv2ts(csvString, moduleName) {
|
|
|
136
136
|
template += "};";
|
|
137
137
|
return template;
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* serialize interface field
|
|
142
|
+
* @param {string} field
|
|
143
|
+
*/
|
|
144
|
+
function serializeField(key) {
|
|
145
|
+
const obj = {}
|
|
146
|
+
obj[key] = true
|
|
147
|
+
const objString = json5.stringify(obj);
|
|
148
|
+
// console.log('serializeField:', json5.stringify(obj))
|
|
149
|
+
return objString.includes("'") ? "'" + key + "'" : key;
|
|
150
|
+
}
|
|
151
|
+
|
|
139
152
|
function GetFileExt(filePath) {
|
|
140
153
|
var pathObject = path.parse(filePath);
|
|
141
154
|
return pathObject.ext.slice(1);
|