Necessitates Proper Modularity
    TypeScript icon, indicating that this package has built-in type declarations

    3.1.5 • Public • Published


    npm version npm downloads Twitter Follow

    This project is part of the monorepo.


    Composable primitives for building declarative, transducer based Finite-State Machines & matchers for arbitrary data streams.

    See the hiccup-markdown parser & example for a concrete use case.


    DEPRECATED - no further development planned

    Search or submit any issues for this package

    This package will be merged with and update the existing package.

    Related packages


    yarn add

    ES module import:

    <script type="module" src=""></script>

    Skypack documentation

    For Node.js REPL:

    # with flag only for < v16
    node --experimental-repl-await
    > const fsm = await import("");

    Package sizes (gzipped, pre-treeshake): ESM: 1.43 KB


    Usage examples

    Several demos in this repo's /examples directory are using this package.

    A selection:

    Screenshot Description Live demo Source
    Minimal Markdown to Hiccup to HTML parser / transformer Demo Source


    Generated API docs

    There're two key concepts provided by this package:


    Matchers are composable functions which receive a single input value and attempt to match it to their configured criteria / patterns. Matchers also support optional user callbacks, which are executed when a match was made and are responsible for state transitions, state update and production of any result values.

    See docs strings in /src folder for now.

    FSM transducer

    The fsm() function is a Finite-state machine transducer / iterator with support for single lookahead values. Takes an object of states and their matchers, an arbitrary context object and an initial state ID.

    The returned transducer consumes inputs of type T and produces results of type R. The results are produced by callbacks of the given state matchers. Each can produce any number of values. If a callback returns a result wrapped w/ reduced(), the FSM causes early termination of the overall transducer pipeline. Failed state callbacks too can produce outputs, but will afterwards terminate the FSM.

    An IllegalStateError will be thrown if a transition to an undefined state ID occurs.

    The optional update function will be invoked for each input prior to executing the currently active state matcher. It is intended to update the context object (e.g. to update input location info for generating error messages).

    If the optional src iterable is given, the function returns a transforming iterator of the FSM results.


    Karsten Schmidt

    If this project contributes to an academic publication, please cite it as:

      title = "",
      author = "Karsten Schmidt",
      note = "",
      year = 2018


    © 2018 - 2021 Karsten Schmidt // Apache Software License 2.0


    npm i

    DownloadsWeekly Downloads






    Unpacked Size

    53.8 kB

    Total Files


    Last publish