npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

xstate-cpp-generator

v1.0.4

Published

C++ code generator for Xstate State Machine

Readme

C++ State Machine generator for Xstate

This package allows to convert TypeScript language State Machine developed using Xstate into C++ generated SM, no coding required.

  • Project location: https://github.com/shuvalov-mdb/xstate-cpp-generator
  • NPM TypeScript package location: https://www.npmjs.com/package/xstate-cpp-generator
  • Copyright Andrew Shuvalov, MIT License

Features

  • Design and test the State Machine in Xstate and then convert to C++ without any changes
  • SM basic features supported: States, Events, Transitions
    • SM extra features supported: Actions
  • Generated C++ is fully synchronized, safe to use in multi-threaded environemnt without any changes
  • No external dependencies except STL. No boost dependency.
  • Callback model:
    • Entry, Exit and Trasition Actions are code generated as static methods in the template object used to declare the State Machine and can be implemented by the user
    • Every state and transtion callbacks are generated as virtual methods that can be overloaded by subclassing
  • Arbitrary user-defined data structure (called Context) can be stored in the SM
  • Any event can have an arbitrary user-defined payload attached. The event payload is propagated to related callbacks

Resources

Install and Quick Start Tutorial

1. Install the xstate-cpp-generator TypeScript package, locally (or globally with -g option):

   npm install xstate-cpp-generator

2. Create a simple Xstate model file engineer.ts with few lines to trigger C++ generation at the end:

(this example is located at https://github.com/shuvalov-mdb/xstate-cpp-generator/tree/master/demo-project)

const CppGen = require('xstate-cpp-generator');
const path = require('path');

import { Machine } from 'xstate';

const engineerMachine = Machine({
    id: 'engineer',
    initial: 'sleeping',
    states: {
        sleeping: {
            entry: 'startWakeupTimer',
            exit: 'morningRoutine',
            on: {
                'TIMER': { target: 'working', actions: ['startHungryTimer', 'startTiredTimer'] },
            }
        },
        working: {
            entry: ['checkEmail', 'startHungryTimer', 'checkIfItsWeekend' ],
            on: {
                'HUNGRY': { target: 'eating', actions: ['checkEmail']},
                'TIRED': { target: 'sleeping' },
                'ENOUGH': { target: 'weekend' }
            },
        },
        eating: {
            entry: 'startShortTimer',
            exit: [ 'checkEmail', 'startHungryTimer' ],
            on: {
                'TIMER': { target: 'working', actions: ['startHungryTimer'] },
                'TIRED': { target: 'sleeping' }
            }
        },
        weekend: {
            type: 'final',
        }
    }
});

CppGen.generateCpp({
    xstateMachine: engineerMachine,
    destinationPath: "",
    namespace: "engineer_demo",
    pathForIncludes: "",
    tsScriptName: path.basename(__filename)
  });

To visualize this State Machine copy-paste the 'Machine' method call to the online vizualizer.

3. Generate C++

Install all required dependencies:

   npm install

And run the C++ generator:

   ts-node engineer.ts

You should see new generated files:

engineer_sm.h  engineer_sm.cpp  engineer_test.cpp

The engineer_test.cpp is an automatically generated Unit Test for the model. Create a simple SConscript file to compile it:

env = Environment()

LIBS =''

common_libs = ['gtest_main', 'gtest', 'pthread']
env.Append( LIBS = common_libs )

env.Append(CCFLAGS=['-fsanitize=address,undefined',
                    '-fno-omit-frame-pointer'],
           LINKFLAGS='-fsanitize=address,undefined')

env.Program('engineer_test', ['engineer_sm.cpp', 'engineer_test.cpp'], 
            LIBS, LIBPATH='/opt/gtest/lib:/usr/local/lib', CXXFLAGS="-std=c++17")

and run it with:

   scons
   ./engineer_test

Release Notes

V 1.0.3

  • Full support of entry, exit and transition Actions
  • Multi-threading bugfixes

V 1.0.4

  • Converted onEnteredState() from move sematics && to shared_ptr
  • Started Tutorial