@k67/kaitai-struct-ts 0.2.0 → 0.3.0

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/README.md CHANGED
@@ -1,12 +1,18 @@
1
- # kaitai-struct-ts
1
+ <div align="center">
2
+ <img src="assets/logo.png" alt="kaitai-struct-ts" width="200"/>
3
+
4
+ # kaitai-struct-ts
2
5
 
3
- [![npm version](https://badge.fury.io/js/%40k67%2Fkaitai-struct-ts.svg)](https://www.npmjs.com/package/@k67/kaitai-struct-ts)
4
- [![CI](https://github.com/fabianopinto/kaitai-struct-ts/workflows/CI/badge.svg)](https://github.com/fabianopinto/kaitai-struct-ts/actions)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
7
- [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
6
+ [![npm version](https://badge.fury.io/js/%40k67%2Fkaitai-struct-ts.svg)](https://www.npmjs.com/package/@k67/kaitai-struct-ts)
7
+ [![CI](https://github.com/fabianopinto/kaitai-struct-ts/workflows/CI/badge.svg)](https://github.com/fabianopinto/kaitai-struct-ts/actions)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
10
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
8
11
 
9
- A **runtime interpreter** for [Kaitai Struct](https://kaitai.io/) binary format definitions in TypeScript.
12
+ **A runtime interpreter for [Kaitai Struct](https://kaitai.io/) binary format definitions in TypeScript.**
13
+ </div>
14
+
15
+ ---
10
16
 
11
17
  Parse any binary data format by providing a `.ksy` (Kaitai Struct YAML) definition file - no compilation step required!
12
18
 
package/dist/index.d.mts CHANGED
@@ -611,14 +611,17 @@ declare class Context {
611
611
  private parentStack;
612
612
  /** Current object being parsed */
613
613
  private _current;
614
+ /** Enum definitions from schema */
615
+ private _enums;
614
616
  /**
615
617
  * Create a new execution context.
616
618
  *
617
619
  * @param _io - Binary stream being read
618
620
  * @param _root - Root object of the parse tree
619
621
  * @param _parent - Parent object (optional)
622
+ * @param enums - Enum definitions from schema (optional)
620
623
  */
621
- constructor(_io: KaitaiStream, _root?: unknown, _parent?: unknown);
624
+ constructor(_io: KaitaiStream, _root?: unknown, _parent?: unknown, enums?: Record<string, EnumSpec>);
622
625
  /**
623
626
  * Get the current I/O stream.
624
627
  * Accessible in expressions as `_io`.
@@ -682,6 +685,22 @@ declare class Context {
682
685
  * @param value - Value to set
683
686
  */
684
687
  set(name: string, value: unknown): void;
688
+ /**
689
+ * Get enum value by name.
690
+ * Used for enum access in expressions (EnumName::value).
691
+ *
692
+ * @param enumName - Name of the enum
693
+ * @param valueName - Name of the enum value
694
+ * @returns Enum value (number) or undefined
695
+ */
696
+ getEnumValue(enumName: string, valueName: string): unknown;
697
+ /**
698
+ * Check if an enum exists.
699
+ *
700
+ * @param enumName - Name of the enum
701
+ * @returns True if enum exists
702
+ */
703
+ hasEnum(enumName: string): boolean;
685
704
  /**
686
705
  * Create a child context for nested parsing.
687
706
  * The current object becomes the parent in the child context.
@@ -816,6 +835,17 @@ declare class TypeInterpreter {
816
835
  * @private
817
836
  */
818
837
  private readFloat;
838
+ /**
839
+ * Evaluate an expression or return a literal value.
840
+ * If the value is a string, it's treated as an expression.
841
+ * If it's a number or boolean, it's returned as-is.
842
+ *
843
+ * @param value - Expression string or literal value
844
+ * @param context - Execution context
845
+ * @returns Evaluated result
846
+ * @private
847
+ */
848
+ private evaluateValue;
819
849
  }
820
850
 
821
851
  /**
package/dist/index.d.ts CHANGED
@@ -611,14 +611,17 @@ declare class Context {
611
611
  private parentStack;
612
612
  /** Current object being parsed */
613
613
  private _current;
614
+ /** Enum definitions from schema */
615
+ private _enums;
614
616
  /**
615
617
  * Create a new execution context.
616
618
  *
617
619
  * @param _io - Binary stream being read
618
620
  * @param _root - Root object of the parse tree
619
621
  * @param _parent - Parent object (optional)
622
+ * @param enums - Enum definitions from schema (optional)
620
623
  */
621
- constructor(_io: KaitaiStream, _root?: unknown, _parent?: unknown);
624
+ constructor(_io: KaitaiStream, _root?: unknown, _parent?: unknown, enums?: Record<string, EnumSpec>);
622
625
  /**
623
626
  * Get the current I/O stream.
624
627
  * Accessible in expressions as `_io`.
@@ -682,6 +685,22 @@ declare class Context {
682
685
  * @param value - Value to set
683
686
  */
684
687
  set(name: string, value: unknown): void;
688
+ /**
689
+ * Get enum value by name.
690
+ * Used for enum access in expressions (EnumName::value).
691
+ *
692
+ * @param enumName - Name of the enum
693
+ * @param valueName - Name of the enum value
694
+ * @returns Enum value (number) or undefined
695
+ */
696
+ getEnumValue(enumName: string, valueName: string): unknown;
697
+ /**
698
+ * Check if an enum exists.
699
+ *
700
+ * @param enumName - Name of the enum
701
+ * @returns True if enum exists
702
+ */
703
+ hasEnum(enumName: string): boolean;
685
704
  /**
686
705
  * Create a child context for nested parsing.
687
706
  * The current object becomes the parent in the child context.
@@ -816,6 +835,17 @@ declare class TypeInterpreter {
816
835
  * @private
817
836
  */
818
837
  private readFloat;
838
+ /**
839
+ * Evaluate an expression or return a literal value.
840
+ * If the value is a string, it's treated as an expression.
841
+ * If it's a number or boolean, it's returned as-is.
842
+ *
843
+ * @param value - Expression string or literal value
844
+ * @param context - Execution context
845
+ * @returns Evaluated result
846
+ * @private
847
+ */
848
+ private evaluateValue;
819
849
  }
820
850
 
821
851
  /**