config2ts 2.5.7 → 2.5.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/README.md +2 -2
- package/lib/config2ts.js +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,8 +35,8 @@ config2ts -d config -o dist -n csv.ts -a public
|
|
|
35
35
|
* `EnumIndex` will generate index type, and will use `Enum` type to generate interface
|
|
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
|
-
* `Object[]`
|
|
39
|
-
* Array convention (`String[]`/`Number[]`/`Enum[]`/`RefEnum[...] []
|
|
38
|
+
* `Object[]` separates objects with `;` while commas still separate `key:value` pairs inside each object (same syntax as the `Object` type), e.g. `num:1,,str:a;num:2` makes `[{num:1,str:'a'},{num:2}]`, a bare `;` makes `[{},{}]`; generates a dedicated element `type` merging all keys with the field typed as `type[]`
|
|
39
|
+
* Array convention: primitive arrays (`String[]`/`Number[]`/`Enum[]`/`RefEnum[...] []`) separate elements with `,` and `Object[]` separates objects with `;`; raw cell values are normalized (line breaks removed, whitespace trimmed); an empty cell generates `[]`; otherwise n separators make n+1 slots and every slot is kept (including interior or trailing ones) so parallel arrays stay index-aligned. Empty slots use the type's own zero value — `''` for string/enum/ref-enum, `0` for number, `{}` for empty object slots; `null` is never generated
|
|
40
40
|
* unrecognized field types fall back to `string` and print a warning (check for typos)
|
|
41
41
|
|
|
42
42
|
## assets2ts
|
package/lib/config2ts.js
CHANGED
|
@@ -292,22 +292,29 @@ function parseObject(str) {
|
|
|
292
292
|
function normalizeCell(str) {
|
|
293
293
|
return String(str).replace(/\r\n?|\n/g, "").trim();
|
|
294
294
|
}
|
|
295
|
-
// Split a comma-separated array cell: n commas make n+1 slots and every
|
|
296
|
-
// is kept (including an interior or trailing empty one), so parallel arrays
|
|
295
|
+
// Split a comma-separated primitive-array cell: n commas make n+1 slots and every
|
|
296
|
+
// slot is kept (including an interior or trailing empty one), so parallel arrays
|
|
297
297
|
// stay index-aligned. Empty slots follow the element's own parsing rule
|
|
298
|
-
// ('' for strings/enums, 0 for numbers
|
|
298
|
+
// ('' for strings/enums, 0 for numbers); null is never emitted.
|
|
299
299
|
// An empty cell resolves to an empty array.
|
|
300
|
+
// Note: Object[] uses semicolons as element separator (see parseObjectArray),
|
|
301
|
+
// because commas already separate key:value pairs inside an object.
|
|
300
302
|
function splitStringArray(str) {
|
|
301
303
|
if (str === "") {
|
|
302
304
|
return [];
|
|
303
305
|
}
|
|
304
306
|
return str.split(",").map((v) => v.trim());
|
|
305
307
|
}
|
|
308
|
+
// Object[] separates objects with semicolons (commas are reserved for the
|
|
309
|
+
// key:value pairs inside an object, same syntax as the Object type); each
|
|
310
|
+
// semicolon slot is parsed by the same object rule, so stray empty pairs within
|
|
311
|
+
// an object (e.g. "num:1,,str:a") are ignored while an empty object slot between
|
|
312
|
+
// semicolons (e.g. "a:1;;b:2") becomes an empty object placeholder.
|
|
306
313
|
function parseObjectArray(str) {
|
|
307
314
|
if (str === "") {
|
|
308
315
|
return [];
|
|
309
316
|
}
|
|
310
|
-
return str.split("
|
|
317
|
+
return str.split(";").map((part) => parseObject(part));
|
|
311
318
|
}
|
|
312
319
|
function parseObjectValue(value) {
|
|
313
320
|
if (value === "true")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "config2ts",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.8",
|
|
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",
|