s2cfgtojson 2.1.0 → 2.1.2
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/Struct.mts +15 -11
- package/package.json +1 -1
package/Struct.mts
CHANGED
|
@@ -16,7 +16,7 @@ export type GetStructType<In> =
|
|
|
16
16
|
: In extends Record<any, any>
|
|
17
17
|
? Struct<{ [key in RKey<In>]: GetStructType<In[key]> }>
|
|
18
18
|
: In extends string
|
|
19
|
-
?
|
|
19
|
+
? In
|
|
20
20
|
: In extends number
|
|
21
21
|
? number
|
|
22
22
|
: In extends boolean
|
|
@@ -226,18 +226,22 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
226
226
|
throw new Error(`Invalid key-value pair: ${line}`);
|
|
227
227
|
}
|
|
228
228
|
const key = match[1].trim();
|
|
229
|
-
let value: string | number = match[3].trim();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
let value: string | number | boolean = match[3].trim();
|
|
230
|
+
if (value === "true" || value === "false") {
|
|
231
|
+
value = value === "true";
|
|
232
|
+
} else {
|
|
233
|
+
try {
|
|
234
|
+
// understand 0.1f / 1. / 0.f / .1 / .1f -> ((\d*)\.?(\d+)|(\d+)\.?(\d*))f?
|
|
235
|
+
const matches = value.match(/^(\d*)\.?(\d*)f?$/);
|
|
234
236
|
const first = matches[1];
|
|
235
237
|
const second = matches[2];
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
if (first || second) {
|
|
239
|
+
value = parseFloat(`${first || 0}${second ? `.${second}` : ""}`);
|
|
240
|
+
} else {
|
|
241
|
+
value = JSON.parse(value);
|
|
242
|
+
}
|
|
243
|
+
} catch (e) {}
|
|
244
|
+
}
|
|
241
245
|
Struct.addEntry(parent, key, value, index);
|
|
242
246
|
};
|
|
243
247
|
let index = 0;
|