Skip to main content

Getting Started

Welcome to the SCXML TypeScript Parser documentation! This library provides a comprehensive, type-safe way to work with SCXML (State Chart XML) documents in TypeScript and JavaScript applications.

What is SCXML?โ€‹

SCXML (State Chart XML) is a W3C standard that provides a generic state-machine based execution environment. It's used to control the logic of applications, from simple UI state management to complex business workflows and AI agent behavior.

Featuresโ€‹

  • ๐Ÿš€ Full SCXML Support: Complete implementation of W3C SCXML specification
  • ๐Ÿ—๏ธ Builder API: Fluent, type-safe API for creating SCXML documents
  • ๐Ÿ”ง Modification API: Programmatically modify existing SCXML documents
  • โœ… Validation: Comprehensive validation with detailed error reporting
  • ๐Ÿ“ XML Serialization: Convert SCXML documents back to XML
  • ๐ŸŽฏ TypeScript: Full TypeScript support with complete type definitions
  • โšก Performance: Efficient parsing and manipulation of large state machines
  • ๐Ÿงช Well Tested: Comprehensive test suite with edge case coverage

Installationโ€‹

Install the package using npm or yarn:

npm install @scxml/parser

Quick Exampleโ€‹

Here's a simple example to get you started:

import { SCXML } from "@scxml/parser";

// Create a simple state machine
const document = SCXML.create()
.name("traffic-light")
.initial("red")
.addState(
SCXML.state("red")
.addTransition(SCXML.transition().event("timer").target("green").build())
.build()
)
.addState(
SCXML.state("green")
.addTransition(SCXML.transition().event("timer").target("yellow").build())
.build()
)
.addState(
SCXML.state("yellow")
.addTransition(SCXML.transition().event("timer").target("red").build())
.build()
)
.build();

// Validate the document
const errors = SCXML.validate(document);
if (errors.length === 0) {
console.log("Valid SCXML document!");
}

// Convert to XML
const xml = SCXML.serialize(document, { spaces: 2 });
console.log(xml);

What's Next?โ€‹

Need Help?โ€‹