config2ts 2.5.5 → 2.5.6

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 CHANGED
@@ -36,6 +36,7 @@ config2ts -d config -o dist -n csv.ts -a public
36
36
  * `Ref` / `RefEnum` reference another csv's Record/type by id
37
37
  * `Object` parse `key:value,key:value` format, auto-infer value types (number/boolean/string), generates a dedicated `type` that merges all keys
38
38
  * `Object[]` parse `key:value,key:value;key:value,key:value` format (`;` separates objects, `,` separates key-value pairs), empty value generates `[]`, generates a dedicated element `type` with the field typed as `type[]`
39
+ * Array empty-data convention (`String[]`/`Number[]`/`Enum[]`/`RefEnum[...] []`/`Object[]`): an empty cell generates `[]`; empty segments from stray, leading or trailing separators (e.g. `"a,,b"`, `"1,,3"`, `"x:1;;y:2"`) are skipped — no phantom `""`, `0` or `{}` elements
39
40
  * unrecognized field types fall back to `string` and print a warning (check for typos)
40
41
 
41
42
  ## assets2ts
package/lib/config2ts.js CHANGED
@@ -100,24 +100,11 @@ function csv2ts(csvString, moduleName) {
100
100
  else if (typeof global[convert[k]] === "function") {
101
101
  d[k] = global[convert[k]](d[k]);
102
102
  }
103
- else if (convert[k] === "String[]") {
104
- if (d[k] === "") {
105
- d[k] = [];
106
- }
107
- else {
108
- d[k] = d[k].trim().split(",").map((v) => v.trim());
109
- }
103
+ else if (convert[k] === "String[]" || convert[k] === "Enum[]") {
104
+ d[k] = splitArrayValues(d[k]);
110
105
  }
111
106
  else if (convert[k] === "Number[]") {
112
- d[k] = d[k].trim().split(",").map((val) => Number(val));
113
- }
114
- else if (convert[k] === "Enum[]") {
115
- if (d[k] === "") {
116
- d[k] = [];
117
- }
118
- else {
119
- d[k] = d[k].trim().split(",").map((v) => v.trim());
120
- }
107
+ d[k] = splitArrayValues(d[k]).map((val) => Number(val));
121
108
  }
122
109
  else if (convert[k].startsWith(RefPrefix) && convert[k].endsWith(RefSuffix)) {
123
110
  if (d[k] === "") {
@@ -127,12 +114,7 @@ function csv2ts(csvString, moduleName) {
127
114
  else if (parseRefEnum(convert[k])) {
128
115
  const refEnum = parseRefEnum(convert[k]);
129
116
  if (refEnum.isArray) {
130
- if (d[k] === "") {
131
- d[k] = [];
132
- }
133
- else {
134
- d[k] = d[k].trim().split(",").map((v) => v.trim());
135
- }
117
+ d[k] = splitArrayValues(d[k]);
136
118
  }
137
119
  else {
138
120
  if (d[k] === "") {
@@ -305,11 +287,20 @@ function parseObject(str) {
305
287
  return result;
306
288
  }
307
289
  function parseObjectArray(str) {
308
- const trimmed = str.trim();
309
- if (trimmed === "") {
310
- return [];
311
- }
312
- return trimmed.split(";").map((part) => parseObject(part));
290
+ return str
291
+ .split(";")
292
+ .map((part) => part.trim())
293
+ .filter((part) => part !== "")
294
+ .map((part) => parseObject(part));
295
+ }
296
+ // Split a comma-separated array cell, trimming and dropping empty segments
297
+ // so stray/leading/trailing commas never produce phantom elements.
298
+ // An empty cell resolves to an empty array.
299
+ function splitArrayValues(str) {
300
+ return str
301
+ .split(",")
302
+ .map((v) => v.trim())
303
+ .filter((v) => v !== "");
313
304
  }
314
305
  function parseObjectValue(value) {
315
306
  if (value === "true")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "config2ts",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "description": "Generate type-safe TypeScript from CSV/INI/TOML config tables — inferred types, enums, cross-table references, and a typed asset index, all from one CLI command.",
5
5
  "main": "lib/config2ts.js",
6
6
  "types": "lib/config2ts.d.ts",