config2ts 2.2.7 → 2.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  id,name,bool,num,mytype,stringarray,numberarray,typearray,space field/sub
2
2
  Index,String,Boolean,Number,Enum,String[],Number[],Enum[],String
3
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
4
+ 2,xxx,,222,type2," a , b",,"t1, t2",a
5
+ 3,333,,NaN,,,"1,2","t2, t3, t4",b
6
6
  ,,,,,,,,
7
7
  4,444,0,Infinity,type2,",1,,b",",1,,3",,c
@@ -27,8 +27,8 @@ export namespace DataCsv {
27
27
  mytype: 'type1',
28
28
  stringarray: [
29
29
  '1',
30
- ' 2',
31
- ' 3',
30
+ '2',
31
+ '3',
32
32
  ],
33
33
  numberarray: [
34
34
  1,
@@ -65,9 +65,7 @@ export namespace DataCsv {
65
65
  bool: false,
66
66
  num: NaN,
67
67
  mytype: '',
68
- stringarray: [
69
- '',
70
- ],
68
+ stringarray: [],
71
69
  numberarray: [
72
70
  1,
73
71
  2,
@@ -1,9 +1,9 @@
1
- num = 1
2
-
3
- str = "string"
4
-
5
- bool = true
6
-
7
- [ItemType]
8
- book = 1
9
- fruit = 2
1
+ num = 1
2
+
3
+ str = "string"
4
+
5
+ bool = true
6
+
7
+ [ItemType]
8
+ book = 1
9
+ fruit = 2
package/config/no-id.csv CHANGED
@@ -1,5 +1,5 @@
1
- name,bool,num
2
- String,Boolean,Number
3
- "xxx",1,111
4
- "xxx",,222
1
+ name,bool,num
2
+ String,Boolean,Number
3
+ "xxx",1,111
4
+ "xxx",,222
5
5
  333,,
@@ -1,7 +1,7 @@
1
- num = 1
2
-
3
- str = "test"
4
-
5
- [ItemType]
6
- book = 1
7
- fruit = 2
1
+ num = 1
2
+
3
+ str = "test"
4
+
5
+ [ItemType]
6
+ book = 1
7
+ fruit = 2
package/config/total.ts CHANGED
@@ -27,8 +27,8 @@ export namespace DataCsv {
27
27
  mytype: 'type1',
28
28
  stringarray: [
29
29
  '1',
30
- ' 2',
31
- ' 3',
30
+ '2',
31
+ '3',
32
32
  ],
33
33
  numberarray: [
34
34
  1,
@@ -65,9 +65,7 @@ export namespace DataCsv {
65
65
  bool: false,
66
66
  num: NaN,
67
67
  mytype: '',
68
- stringarray: [
69
- '',
70
- ],
68
+ stringarray: [],
71
69
  numberarray: [
72
70
  1,
73
71
  2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "config2ts",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "description": "convert config to ts file.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/src/config2ts.js CHANGED
@@ -36,7 +36,12 @@ function csv2ts(csvString, moduleName) {
36
36
  if (global[convert[k]] instanceof Function) {
37
37
  d[k] = global[convert[k]](d[k]);
38
38
  } else if (convert[k] === 'String[]') {
39
- d[k] = d[k].trim().split(',');
39
+ if (d[k] === '') {
40
+ // Enum array do not include empty string
41
+ d[k] = [];
42
+ } else {
43
+ d[k] = d[k].trim().split(',').map((v) => v.trim());
44
+ }
40
45
  } else if (convert[k] === 'Number[]') {
41
46
  d[k] = d[k].trim().split(',').map((val) => Number(val));
42
47
  } else if (convert[k] === 'Enum[]') {
@@ -44,7 +49,7 @@ function csv2ts(csvString, moduleName) {
44
49
  // Enum array do not include empty string
45
50
  d[k] = [];
46
51
  } else {
47
- d[k] = d[k].trim().split(',');
52
+ d[k] = d[k].trim().split(',').map((v) => v.trim());
48
53
  }
49
54
  } else {
50
55
  d[k] = String(d[k]);
package/data.csv DELETED
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,108 +0,0 @@
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
- };