config2ts 2.1.6 → 2.2.0
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 +6 -6
- package/config/data.csv.ts +42 -4
- package/config/total.ts +61 -4
- package/package.json +1 -1
- package/src/config2ts.js +7 -0
- package/src/main.js +1 -1
- package/tests/config2ts.spec.js +1 -1
package/config/data.csv
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
id,name,bool,num,mytype
|
|
2
|
-
String,String,Boolean,Number,Enum
|
|
3
|
-
1,xxx,1,111,type1
|
|
4
|
-
2,xxx,,222,type2
|
|
5
|
-
3,333,,33,
|
|
6
|
-
4,444,0,444,type2
|
|
1
|
+
id,name,bool,num,mytype,stringarray,numberarray
|
|
2
|
+
String,String,Boolean,Number,Enum,String[],Number[]
|
|
3
|
+
1,xxx,1,111,type1,"1, 2, 3","1, 2, 3"
|
|
4
|
+
2,xxx,,222,type2,"a,b",
|
|
5
|
+
3,333,,33,,,"1,2"
|
|
6
|
+
4,444,0,444,type2,",1,,b",",1,,3"
|
package/config/data.csv.ts
CHANGED
|
@@ -7,6 +7,8 @@ export namespace DataCsv {
|
|
|
7
7
|
bool: boolean;
|
|
8
8
|
num: number;
|
|
9
9
|
mytype: mytype;
|
|
10
|
+
stringarray: string[];
|
|
11
|
+
numberarray: number[];
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export const List: Record[] = [
|
|
@@ -15,28 +17,64 @@ export namespace DataCsv {
|
|
|
15
17
|
"name": "xxx",
|
|
16
18
|
"bool": true,
|
|
17
19
|
"num": 111,
|
|
18
|
-
"mytype": "type1"
|
|
20
|
+
"mytype": "type1",
|
|
21
|
+
"stringarray": [
|
|
22
|
+
"1",
|
|
23
|
+
" 2",
|
|
24
|
+
" 3"
|
|
25
|
+
],
|
|
26
|
+
"numberarray": [
|
|
27
|
+
1,
|
|
28
|
+
2,
|
|
29
|
+
3
|
|
30
|
+
]
|
|
19
31
|
},
|
|
20
32
|
{
|
|
21
33
|
"id": "2",
|
|
22
34
|
"name": "xxx",
|
|
23
35
|
"bool": false,
|
|
24
36
|
"num": 222,
|
|
25
|
-
"mytype": "type2"
|
|
37
|
+
"mytype": "type2",
|
|
38
|
+
"stringarray": [
|
|
39
|
+
"a",
|
|
40
|
+
"b"
|
|
41
|
+
],
|
|
42
|
+
"numberarray": [
|
|
43
|
+
0
|
|
44
|
+
]
|
|
26
45
|
},
|
|
27
46
|
{
|
|
28
47
|
"id": "3",
|
|
29
48
|
"name": "333",
|
|
30
49
|
"bool": false,
|
|
31
50
|
"num": 33,
|
|
32
|
-
"mytype": ""
|
|
51
|
+
"mytype": "",
|
|
52
|
+
"stringarray": [
|
|
53
|
+
""
|
|
54
|
+
],
|
|
55
|
+
"numberarray": [
|
|
56
|
+
1,
|
|
57
|
+
2
|
|
58
|
+
]
|
|
33
59
|
},
|
|
34
60
|
{
|
|
35
61
|
"id": "4",
|
|
36
62
|
"name": "444",
|
|
37
63
|
"bool": true,
|
|
38
64
|
"num": 444,
|
|
39
|
-
"mytype": "type2"
|
|
65
|
+
"mytype": "type2",
|
|
66
|
+
"stringarray": [
|
|
67
|
+
"",
|
|
68
|
+
"1",
|
|
69
|
+
"",
|
|
70
|
+
"b"
|
|
71
|
+
],
|
|
72
|
+
"numberarray": [
|
|
73
|
+
0,
|
|
74
|
+
1,
|
|
75
|
+
0,
|
|
76
|
+
3
|
|
77
|
+
]
|
|
40
78
|
}
|
|
41
79
|
];
|
|
42
80
|
|
package/config/total.ts
CHANGED
|
@@ -7,6 +7,8 @@ export namespace DataCsv {
|
|
|
7
7
|
bool: boolean;
|
|
8
8
|
num: number;
|
|
9
9
|
mytype: mytype;
|
|
10
|
+
stringarray: string[];
|
|
11
|
+
numberarray: number[];
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
export const List: Record[] = [
|
|
@@ -15,28 +17,64 @@ export namespace DataCsv {
|
|
|
15
17
|
"name": "xxx",
|
|
16
18
|
"bool": true,
|
|
17
19
|
"num": 111,
|
|
18
|
-
"mytype": "type1"
|
|
20
|
+
"mytype": "type1",
|
|
21
|
+
"stringarray": [
|
|
22
|
+
"1",
|
|
23
|
+
" 2",
|
|
24
|
+
" 3"
|
|
25
|
+
],
|
|
26
|
+
"numberarray": [
|
|
27
|
+
1,
|
|
28
|
+
2,
|
|
29
|
+
3
|
|
30
|
+
]
|
|
19
31
|
},
|
|
20
32
|
{
|
|
21
33
|
"id": "2",
|
|
22
34
|
"name": "xxx",
|
|
23
35
|
"bool": false,
|
|
24
36
|
"num": 222,
|
|
25
|
-
"mytype": "type2"
|
|
37
|
+
"mytype": "type2",
|
|
38
|
+
"stringarray": [
|
|
39
|
+
"a",
|
|
40
|
+
"b"
|
|
41
|
+
],
|
|
42
|
+
"numberarray": [
|
|
43
|
+
0
|
|
44
|
+
]
|
|
26
45
|
},
|
|
27
46
|
{
|
|
28
47
|
"id": "3",
|
|
29
48
|
"name": "333",
|
|
30
49
|
"bool": false,
|
|
31
50
|
"num": 33,
|
|
32
|
-
"mytype": ""
|
|
51
|
+
"mytype": "",
|
|
52
|
+
"stringarray": [
|
|
53
|
+
""
|
|
54
|
+
],
|
|
55
|
+
"numberarray": [
|
|
56
|
+
1,
|
|
57
|
+
2
|
|
58
|
+
]
|
|
33
59
|
},
|
|
34
60
|
{
|
|
35
61
|
"id": "4",
|
|
36
62
|
"name": "444",
|
|
37
63
|
"bool": true,
|
|
38
64
|
"num": 444,
|
|
39
|
-
"mytype": "type2"
|
|
65
|
+
"mytype": "type2",
|
|
66
|
+
"stringarray": [
|
|
67
|
+
"",
|
|
68
|
+
"1",
|
|
69
|
+
"",
|
|
70
|
+
"b"
|
|
71
|
+
],
|
|
72
|
+
"numberarray": [
|
|
73
|
+
0,
|
|
74
|
+
1,
|
|
75
|
+
0,
|
|
76
|
+
3
|
|
77
|
+
]
|
|
40
78
|
}
|
|
41
79
|
];
|
|
42
80
|
|
|
@@ -45,6 +83,16 @@ export namespace DataCsv {
|
|
|
45
83
|
|
|
46
84
|
};
|
|
47
85
|
|
|
86
|
+
export const IniFileIni = {
|
|
87
|
+
"num": 1,
|
|
88
|
+
"str": "string",
|
|
89
|
+
"bool": true,
|
|
90
|
+
"ItemType": {
|
|
91
|
+
"book": 1,
|
|
92
|
+
"fruit": 2
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
48
96
|
export namespace NoIdCsv {
|
|
49
97
|
|
|
50
98
|
export interface Record {
|
|
@@ -71,4 +119,13 @@ export namespace NoIdCsv {
|
|
|
71
119
|
}
|
|
72
120
|
];
|
|
73
121
|
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const TomlFileToml = {
|
|
125
|
+
"num": 1,
|
|
126
|
+
"str": "test",
|
|
127
|
+
"ItemType": {
|
|
128
|
+
"book": 1,
|
|
129
|
+
"fruit": 2
|
|
130
|
+
}
|
|
74
131
|
};
|
package/package.json
CHANGED
package/src/config2ts.js
CHANGED
|
@@ -31,6 +31,13 @@ function csv2ts(csvString, moduleName) {
|
|
|
31
31
|
for (var k in d) {
|
|
32
32
|
if (global[convert[k]] instanceof Function) {
|
|
33
33
|
d[k] = global[convert[k]](d[k]);
|
|
34
|
+
} else {
|
|
35
|
+
// console.log(`convert[k]: ${convert[k]}, d[k]: ${d[k]}, k: ${k}`)
|
|
36
|
+
if (convert[k] === 'String[]') {
|
|
37
|
+
d[k] = d[k].trim().split(',');
|
|
38
|
+
} else if (convert[k] === 'Number[]') {
|
|
39
|
+
d[k] = d[k].trim().split(',').map((val) => Number(val));
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
return d;
|
package/src/main.js
CHANGED
|
@@ -30,7 +30,7 @@ if (merge) {
|
|
|
30
30
|
return path.join(dir, filename);
|
|
31
31
|
});
|
|
32
32
|
var mergeFile = path.join(outDir, merge);
|
|
33
|
-
fs.writeFileSync(mergeFile, config2ts.
|
|
33
|
+
fs.writeFileSync(mergeFile, config2ts.GetTsStringFromFileList(fileList));
|
|
34
34
|
console.log("config2ts, ".concat(fileList.length, " config files, merge into: ").concat(mergeFile));
|
|
35
35
|
}
|
|
36
36
|
else {
|
package/tests/config2ts.spec.js
CHANGED
|
@@ -15,7 +15,7 @@ test('convert toml file', function () {
|
|
|
15
15
|
expect(config2ts.GetTsString('./config/toml_file.toml')).toBe(fs.readFileSync('./config/toml_file.toml.ts').toString());
|
|
16
16
|
});
|
|
17
17
|
test('config2ts merge csv file list', function () {
|
|
18
|
-
expect(config2ts.GetTsStringFromFileList(["./config/data.csv", "./config/no-id.csv"])).toBe(fs.readFileSync('./config/total.ts').toString());
|
|
18
|
+
expect(config2ts.GetTsStringFromFileList(["./config/data.csv", "./config/ini-file.ini", "./config/no-id.csv", "./config/toml_file.toml"])).toBe(fs.readFileSync('./config/total.ts').toString());
|
|
19
19
|
});
|
|
20
20
|
test('config2ts merge csv file list', function () {
|
|
21
21
|
expect(config2ts.GetValidFileList(['a.csv', 'b.ini', 'c.xxx'])).toEqual(['a.csv', 'b.ini']);
|