s2cfgtojson 3.0.1 → 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.1",
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
@@ -86,7 +86,18 @@ export interface DefaultEntries {
86
86
 
87
87
  export type Value = string | boolean | number;
88
88
  export type Entries = Record<string | number, Value>;
89
- export type GetStructType<In> = Struct & In;
89
+ export type GetStructType<In> =
90
+ In extends Array<any>
91
+ ? Struct & { [key in number]: GetStructType<In[key]> }
92
+ : In extends Record<any, any>
93
+ ? Struct & { [key in keyof In]: GetStructType<In[key]> }
94
+ : In extends string
95
+ ? In
96
+ : In extends number
97
+ ? number
98
+ : In extends boolean
99
+ ? boolean
100
+ : In;
90
101
 
91
102
  export type ArmorPrototype = GetStructType<{
92
103
  SID: string;