s2cfgtojson 3.0.0 → 3.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.
package/Struct.mts CHANGED
@@ -22,13 +22,16 @@ export abstract class Struct implements IStruct {
22
22
  /**
23
23
  * Creates a new struct instance.
24
24
  */
25
- constructor(parentOrRaw?: string | Struct) {
25
+ constructor(parentOrRaw?: string | Struct | object) {
26
26
  if (parentOrRaw instanceof Struct) {
27
27
  Object.assign(this, parentOrRaw.clone());
28
28
  }
29
29
  if (typeof parentOrRaw === "string") {
30
30
  Object.assign(this, Struct.fromString(parentOrRaw)[0]);
31
31
  }
32
+ if (typeof parentOrRaw === "object" && parentOrRaw !== null) {
33
+ Object.assign(this, parentOrRaw);
34
+ }
32
35
  }
33
36
 
34
37
  fork(clone = false) {
@@ -233,7 +236,7 @@ function walk(lines: string[]) {
233
236
  return roots;
234
237
  }
235
238
 
236
- function parseKey(key: string, parent: Struct, index: number) {
239
+ export function parseKey(key: string, parent: Struct, index: number) {
237
240
  let normKey: string | number = key;
238
241
 
239
242
  if (key.startsWith("[") && key.endsWith("]")) {
package/Struct.test.mts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  pad,
6
6
  IStruct,
7
7
  Struct,
8
+ ArmorPrototype,
8
9
  } from "./Struct.mjs";
9
10
  import fs from "node:fs";
10
11
 
@@ -259,3 +260,5 @@ struct.end`;
259
260
 
260
261
  // noinspection JSUnusedLocalSymbols
261
262
  const MyRank: ERank = "ERank::Experienced, ERank::Veteran, ERank::Master";
263
+ // noinspection BadExpressionStatementJS
264
+ (({}) as ArmorPrototype).Protection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s2cfgtojson",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Converts Stalker 2 Cfg file into POJOs",
5
5
  "keywords": [
6
6
  "stalker",
package/types.mts CHANGED
@@ -66,6 +66,7 @@ import {
66
66
  ERequiredSquadMembers,
67
67
  EMeshSubType,
68
68
  } from "./enums.mjs";
69
+ import { Struct } from "./Struct.mjs";
69
70
 
70
71
  export type Internal = "__internal__";
71
72
  export type IStruct = {
@@ -84,28 +85,19 @@ export interface DefaultEntries {
84
85
  }
85
86
 
86
87
  export type Value = string | boolean | number;
87
-
88
88
  export type Entries = Record<string | number, Value>;
89
-
90
- export type GetTsType<E extends IStruct> = {
91
- [key in Exclude<keyof E, Internal>]: E[key] extends IStruct
92
- ? GetTsType<E[key]>
93
- : E[key];
94
- };
95
- type RKey<In> = Exclude<keyof In, keyof DefaultEntries>;
96
-
97
89
  export type GetStructType<In> =
98
90
  In extends Array<any>
99
- ? IStruct & { [key in number]: GetStructType<In[key]> }
91
+ ? Struct & { [key in number]: GetStructType<In[key]> }
100
92
  : In extends Record<any, any>
101
- ? IStruct & { [key in RKey<In>]: GetStructType<In[key]> }
93
+ ? Struct & { [key in keyof In]: GetStructType<In[key]> }
102
94
  : In extends string
103
95
  ? In
104
96
  : In extends number
105
97
  ? number
106
98
  : In extends boolean
107
99
  ? boolean
108
- : never;
100
+ : In;
109
101
 
110
102
  export type ArmorPrototype = GetStructType<{
111
103
  SID: string;