s2cfgtojson 2.1.6 → 2.2.7

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  const defaultEntries = new Set(["_isArray", "_useAsterisk"]);
2
2
  export * from "./types.mts";
3
+ export * from "./enums.mts";
3
4
  import { DefaultEntries, Value, Entries, Struct as IStruct } from "./types.mts";
4
5
 
5
6
  /**
@@ -210,12 +211,15 @@ export abstract class Struct<T extends Entries = {}> implements IStruct<T> {
210
211
  value = value === "true";
211
212
  } else {
212
213
  try {
213
- // understand 0.1f / 1. / 0.f / .1 / .1f -> ((\d*)\.?(\d+)|(\d+)\.?(\d*))f?
214
- const matches = value.match(/^(\d*)\.?(\d*)f?$/);
215
- const first = matches[1];
216
- const second = matches[2];
214
+ // understand +- 0.1f / 1. / 0.f / .1 / .1f -> ((\d*)\.?(\d+)|(\d+)\.?(\d*))f?
215
+ const matches = value.match(/^(-?)(\d*)\.?(\d*)f?$/);
216
+ const minus = matches[1];
217
+ const first = matches[2];
218
+ const second = matches[3];
217
219
  if (first || second) {
218
- value = parseFloat(`${first || 0}${second ? `.${second}` : ""}`);
220
+ value = parseFloat(
221
+ `${minus ? "-" : ""}${first || 0}${second ? `.${second}` : ""}`,
222
+ );
219
223
  } else {
220
224
  value = JSON.parse(value);
221
225
  }
package/Struct.test.mts CHANGED
@@ -195,15 +195,17 @@ struct.end`;
195
195
  N3 = 0.f
196
196
  N4 = .1
197
197
  N5 = .1f
198
+ N6 = -2.22f
198
199
  struct.end`;
199
- const str = Struct.fromString<
200
- Struct<{ N1: number; N2: number; N3: number; N4: number; N5: number }>
201
- >(dynamicItemGeneratorText);
200
+ const str = Struct.fromString<Struct<{ [key: `N${number}`]: number }>>(
201
+ dynamicItemGeneratorText,
202
+ );
202
203
  expect(str[0].entries.N1).toBe(0.1);
203
204
  expect(str[0].entries.N2).toBe(1);
204
205
  expect(str[0].entries.N3).toBe(0);
205
206
  expect(str[0].entries.N4).toBe(0.1);
206
207
  expect(str[0].entries.N5).toBe(0.1);
208
+ expect(str[0].entries.N6).toBe(-2.22);
207
209
  });
208
210
  });
209
211
  });