s2cfgtojson 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/Struct.mts +9 -6
  2. package/package.json +1 -1
package/Struct.mts CHANGED
@@ -68,9 +68,11 @@ export abstract class Struct<T extends Entries = {}> {
68
68
  if (Struct.isNumber(Struct.extractKeyFromBrackets(name))) {
69
69
  return `_${name.match(/\[(\d+)]/)[1]}`; // Special case for indexed structs
70
70
  }
71
- const replacer = (text: string) =>
72
- text.replace(/\W/g, "_").replace(/_+/g, "_").replace(/^_/, "");
73
- return `${replacer(name[0]).replace(/\d/, "")}${replacer(name.slice(1))}`;
71
+ return name
72
+ .replace(/\W/g, "_")
73
+ .replace(/^\d+/, "_")
74
+ .replace(/_+/g, "_")
75
+ .replace(/^_+/, "");
74
76
  }
75
77
 
76
78
  static createDynamicClass = (name: string): new () => Struct =>
@@ -150,14 +152,15 @@ export abstract class Struct<T extends Entries = {}> {
150
152
  ): IntendedType[] {
151
153
  const lines = text.trim().split("\n");
152
154
 
153
- const parseHead = (line: string): Struct => {
155
+ const parseHead = (line: string, index: number): Struct => {
154
156
  const match = line.match(
155
157
  /^(.*)\s*:\s*struct\.begin\s*({\s*((refurl|refkey|bskipref)\s*(=.+)?)\s*})?/,
156
158
  );
157
159
  if (!match) {
158
160
  throw new Error(`Invalid struct head: ${line}`);
159
161
  }
160
- let name = Struct.parseStructName(match[1].trim());
162
+ let name =
163
+ Struct.parseStructName(match[1].trim()) || `UnnamedStruct${index}`;
161
164
 
162
165
  const dummy = new (Struct.createDynamicClass(name))();
163
166
  dummy._id = match[1];
@@ -202,7 +205,7 @@ export abstract class Struct<T extends Entries = {}> {
202
205
  }
203
206
  const current = stack[stack.length - 1];
204
207
  if (line.includes("struct.begin")) {
205
- const newStruct = parseHead(line);
208
+ const newStruct = parseHead(line, index);
206
209
  if (current) {
207
210
  const key = Struct.renderStructName(newStruct.constructor.name);
208
211
  Struct.addEntry(current, key, newStruct, index);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Converts Stalker 2 Cfg file into a POJO",
5
5
  "keywords": [
6
6
  "stalker",