s2cfgtojson 2.0.4 → 2.1.1
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 +9 -1
- package/Struct.test.mts +18 -0
- package/package.json +1 -1
package/Struct.mts
CHANGED
|
@@ -228,7 +228,15 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
228
228
|
const key = match[1].trim();
|
|
229
229
|
let value: string | number = match[3].trim();
|
|
230
230
|
try {
|
|
231
|
-
|
|
231
|
+
// understand 0.1f / 1. / 0.f / .1 / .1f -> ((\d*)\.?(\d+)|(\d+)\.?(\d*))f?
|
|
232
|
+
const matches = value.match(/^(\d*)\.?(\d*)f?$/);
|
|
233
|
+
const first = matches[1];
|
|
234
|
+
const second = matches[2];
|
|
235
|
+
if (first || second) {
|
|
236
|
+
value = parseFloat(`${first || 0}${second ? `.${second}` : ""}`);
|
|
237
|
+
} else {
|
|
238
|
+
value = JSON.parse(value);
|
|
239
|
+
}
|
|
232
240
|
} catch (e) {}
|
|
233
241
|
Struct.addEntry(parent, key, value, index);
|
|
234
242
|
};
|
package/Struct.test.mts
CHANGED
|
@@ -187,5 +187,23 @@ struct.end`;
|
|
|
187
187
|
dynamicItemGeneratorText,
|
|
188
188
|
);
|
|
189
189
|
});
|
|
190
|
+
|
|
191
|
+
test("4", () => {
|
|
192
|
+
const dynamicItemGeneratorText = `A : struct.begin
|
|
193
|
+
N1 = 0.1f
|
|
194
|
+
N2 = 1.
|
|
195
|
+
N3 = 0.f
|
|
196
|
+
N4 = .1
|
|
197
|
+
N5 = .1f
|
|
198
|
+
struct.end`;
|
|
199
|
+
const str = Struct.fromString<
|
|
200
|
+
Struct<{ N1: number; N2: number; N3: number; N4: number; N5: number }>
|
|
201
|
+
>(dynamicItemGeneratorText);
|
|
202
|
+
expect(str[0].entries.N1).toBe(0.1);
|
|
203
|
+
expect(str[0].entries.N2).toBe(1);
|
|
204
|
+
expect(str[0].entries.N3).toBe(0);
|
|
205
|
+
expect(str[0].entries.N4).toBe(0.1);
|
|
206
|
+
expect(str[0].entries.N5).toBe(0.1);
|
|
207
|
+
});
|
|
190
208
|
});
|
|
191
209
|
});
|