s2cfgtojson 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/Struct.mts +5 -5
  2. package/package.json +1 -1
package/Struct.mts CHANGED
@@ -68,7 +68,9 @@ 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
- return name;
71
+ const replacer = (text: string) =>
72
+ text.replace(/\W/g, "_").replace(/_+/g, "_").replace(/^_/, "");
73
+ return `${replacer(name[0]).replace(/\d/, "")}${replacer(name.slice(1))}`;
72
74
  }
73
75
 
74
76
  static createDynamicClass = (name: string): new () => Struct =>
@@ -76,7 +78,7 @@ export abstract class Struct<T extends Entries = {}> {
76
78
 
77
79
  toString(): string {
78
80
  let text: string;
79
- text = this.isRoot ? `${Struct.renderStructName(this._id)} : ` : "";
81
+ text = this.isRoot ? `${this._id} : ` : "";
80
82
  text += "struct.begin";
81
83
  const refs = ["refurl", "refkey", "bskipref"]
82
84
  .map((k) => [k, this[k]])
@@ -158,9 +160,7 @@ export abstract class Struct<T extends Entries = {}> {
158
160
  let name = Struct.parseStructName(match[1].trim());
159
161
 
160
162
  const dummy = new (Struct.createDynamicClass(name))();
161
- if (name === match[1].trim()) {
162
- dummy._id = name;
163
- }
163
+ dummy._id = match[1];
164
164
  if (match[3]) {
165
165
  const refs = match[3]
166
166
  .split(";")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Converts Stalker 2 Cfg file into a POJO",
5
5
  "keywords": [
6
6
  "stalker",