Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

References

Re-exports FslDirections
Re-exports build_time
Renames and re-exports jssm_constants
Re-exports find_repeated
Re-exports gen_splitmix32
Re-exports histograph
Re-exports seq
Re-exports sleep
Re-exports unique
Re-exports version
Re-exports weighted_histo_key
Re-exports weighted_rand_select
Re-exports weighted_sample_select

Variables

gviz_shapes: string[]
named_colors: string[]
shapes: string[]

Functions

  • Invoke an optional "everything" hook and normalize its return value into a HookComplexResult.

    Mechanically identical to abstract_hook_step, but typed for the everything-hook family (pre_everything_hook and everything_hook), whose context object carries an extra hook_name field identifying which bracket of the pipeline is firing. Separated from abstract_hook_step so TypeScript can enforce that the hook handler and the context object agree on shape.

    The valid return shapes and their meanings are the same as for abstract_hook_step:

    • undefined or true{ pass: true }
    • false or null{ pass: false }
    • a complex result → returned as-is
    throws

    {TypeError} If the hook returns a value outside the legal shapes.

    internal

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted.

    Parameters

    • maybe_hook: EverythingHookHandler<mDT>

      The everything-hook handler, or undefined when none is installed.

    • hook_args: EverythingHookContext<mDT>

      The everything-hook context object. Differs from a normal hook context in that it also includes hook_name.

    Returns HookComplexResult<mDT>

    A HookComplexResult describing whether the hook passed and any data replacements it requested.

  • Invoke an optional transition/action hook and normalize its return value into a HookComplexResult.

    This is the central adapter the transition pipeline uses to run every non-"everything" hook kind (basic, named, entry, exit, after, action, etc). It accepts undefined for the hook slot because most hooks are not set on most machines; when no hook is installed the step is a no-op pass.

    The valid return shapes from a hook and their normalized meanings are:

    • undefined{ pass: true }
    • true{ pass: true }
    • false{ pass: false }
    • null{ pass: false }
    • a complex result object → returned as-is

    Anything else is a programmer error and throws.

    throws

    {TypeError} If the hook returns a value that is not one of the legal shapes listed above.

    internal

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted.

    Parameters

    • maybe_hook: HookHandler<mDT>

      The hook handler to call, or undefined for the "no hook installed" case.

    • hook_args: HookContext<mDT>

      The context object passed to the hook. Includes the current and proposed state, current and proposed data, action name, and transition kind.

    Returns HookComplexResult<mDT>

    A HookComplexResult describing whether the hook passed and, optionally, any data replacements it requested.

  • Return the direction of an arrow - right, left, or both.

    import { arrow_direction } from 'jssm';

    arrow_direction('->'); // 'right'
    arrow_direction('<~=>'); // 'both'

    Parameters

    Returns JssmArrowDirection

  • Return the direction of an arrow - right, left, or both.

    import { arrow_left_kind } from 'jssm';

    arrow_left_kind('<-'); // 'legal'
    arrow_left_kind('<='); // 'main'
    arrow_left_kind('<~'); // 'forced'
    arrow_left_kind('<->'); // 'legal'
    arrow_left_kind('->'); // 'none'

    Parameters

    Returns JssmArrowKind

  • Return the direction of an arrow - right, left, or both.

    import { arrow_left_kind } from 'jssm';

    arrow_left_kind('->'); // 'legal'
    arrow_left_kind('=>'); // 'main'
    arrow_left_kind('~>'); // 'forced'
    arrow_left_kind('<->'); // 'legal'
    arrow_left_kind('<-'); // 'none'

    Parameters

    Returns JssmArrowKind

  • Compile a machine's JSON intermediate representation to a config object. If you're using this (probably don't,) you're probably also using parse to get the IR, and the object constructor {@link Machine.construct} to turn the config object into a workable machine.

    import { parse, compile, Machine } from 'jssm';

    const intermediate = parse('a -> b;');
    // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]

    const cfg = compile(intermediate);
    // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }

    const machine = new Machine(cfg);
    // Machine { _instance_name: undefined, _state: 'a', ...

    This method is mostly for plugin and intermediate tool authors, or people who need to work with the machine's intermediate representation.

    Hey!

    Most people looking at this want either the sm operator or method from, which perform all the steps in the chain. The library's author mostly uses operator sm, and mostly falls back to .from when needing to parse strings dynamically instead of from template literals.

    Operator sm:

    import { sm } from 'jssm';

    const lswitch = sm`on <=> off;`;

    Method from:

    import * as jssm from 'jssm';

    const toggle = jssm.from('up <=> down;');

    Type Parameters

    • StateType

    • mDT

      The type of the machine data member; usually omitted

    Parameters

    • tree: JssmParseTree<StateType, mDT>

      The parse tree to be boiled down into a machine config

    Returns JssmGenericConfig<StateType, mDT>

  • Deserializes a previously serialized machine state.

    This function recreates a machine from a serialization object, restoring its state, data, and history. For security and compatibility reasons, it will refuse to deserialize data from future versions of the library.

    throws

    {Error} If the serialization is from a future version

    example

    const machine = jssm.from("a -> b;"); const serialized = machine.serialize(); const restored = jssm.deserialize("a -> b;", serialized);

    Type Parameters

    • mDT

      The type of the machine data member

    Parameters

    • machine_string: string

      The FSL string defining the machine structure

    • ser: JssmSerialization<mDT>

      The serialization object to restore from

    Returns Machine<mDT>

    • The restored machine instance
  • Create a state machine from an implementation string. This is one of the two main paths for working with JSSM, alongside sm.

    Use this method when you want to conveniently pull a state machine from a string dynamically. Use operator sm when you just want to work with a template expression.

    import * as jssm from 'jssm';

    const lswitch = jssm.from('on <=> off;');

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted

    Parameters

    • MachineAsString: string

      The FSL code to evaluate

    • Optional ExtraConstructorFields: Partial<JssmGenericConfig<string, mDT>>

      Extra non-code configuration to pass at creation time

    Returns Machine<mDT>

  • Type guard that narrows an unknown value to a HookComplexResult.

    A hook complex result is an object with at minimum a boolean pass field, and may optionally also carry replacement data / next_data fields that the machine should adopt if the hook passes. This helper is used by the hook-dispatch machinery to tell "hook returned a complex object" from "hook returned a bare boolean / null / undefined".

    is_hook_complex_result({ pass: true });                 // true
    is_hook_complex_result({ pass: false, data: { x: 1 }}); // true
    is_hook_complex_result(true); // false
    is_hook_complex_result(null); // false
    is_hook_complex_result({ other: 'thing' }); // false

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted.

    Parameters

    • hr: unknown

      The value to test.

    Returns hr is HookComplexResult<mDT>

    true if hr is a non-null object with a boolean pass field; false otherwise. When true, TypeScript narrows hr to HookComplexResult<mDT>.

  • is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean
  • Normalize any legal hook return value to a single "did it reject?" boolean.

    Hooks in jssm may return any of the following to indicate success: true, undefined, or a complex result whose pass field is true. They may return any of the following to indicate rejection: false, or a complex result whose pass field is false. This helper collapses all of those shapes into one boolean so callers don't have to re-implement the matrix.

    is_hook_rejection(true);            // false (pass)
    is_hook_rejection(undefined); // false (pass)
    is_hook_rejection(false); // true (reject)
    is_hook_rejection({ pass: true }); // false (pass)
    is_hook_rejection({ pass: false }); // true (reject)
    throws

    {TypeError} If hr is not a recognized hook result shape (for example, a number or a plain object without a pass field).

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted.

    Parameters

    • hr: HookResult<mDT>

      A hook result of any legal shape.

    Returns boolean

    true if the hook rejected the transition; false if it passed.

  • An internal convenience wrapper for parsing then compiling a machine string. Not generally meant for external use. Please see compile or sm.

    Type Parameters

    • StateType

    • mDT

      The type of the machine data member; usually omitted

    Parameters

    • plan: string

      The FSL code to be evaluated and built into a machine config

    Returns JssmGenericConfig<StateType, mDT>

  • This method wraps the parser call that comes from the peg grammar, parse. Generally neither this nor that should be used directly unless you mean to develop plugins or extensions for the machine.

    Parses the intermediate representation of a compiled string down to a machine configuration object. If you're using this (probably don't,) you're probably also using compile and Machine.constructor.

    import { parse, compile, Machine } from 'jssm';

    const intermediate = wrap_parse('a -> b;', {});
    // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]

    const cfg = compile(intermediate);
    // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }

    const machine = new Machine(cfg);
    // Machine { _instance_name: undefined, _state: 'a', ...

    This method is mostly for plugin and intermediate tool authors, or people who need to work with the machine's intermediate representation.

    Hey!

    Most people looking at this want either the sm operator or method from, which perform all the steps in the chain. The library's author mostly uses operator sm, and mostly falls back to .from when needing to parse strings dynamically instead of from template literals.

    Operator sm:

    import { sm } from 'jssm';

    const lswitch = sm`on <=> off;`;

    Method from:

    import * as jssm from 'jssm';

    const toggle = jssm.from('up <=> down;');

    wrap_parse itself is an internal convenience method for alting out an object as the options call. Not generally meant for external use.

    Parameters

    • input: string

      The FSL code to be evaluated

    • Optional options: <internal>.Object

      Things to control about the instance

    Returns any

  • Create a state machine from a template string. This is one of the two main paths for working with JSSM, alongside from.

    Use this method when you want to work directly and conveniently with a constant template expression. Use .from when you want to pull from dynamic strings.

    import * as jssm from 'jssm';

    const lswitch = jssm.from('on <=> off;');

    Type Parameters

    • mDT

      The type of the machine data member; usually omitted

    Parameters

    • template_strings: TemplateStringsArray

      The assembled code

    • Rest ...remainder: any[]

      The mechanic for template argument insertion

    Returns Machine<mDT>

  • Collapse a list of individual state-style key/value pairs into a single JssmStateConfig object, remapping FSL-style kebab-case keys to the camelCase field names the runtime uses.

    The parser emits state styling as a flat array like [{ key: 'color', value: 'red' }, { key: 'line-style', value: 'dashed' }] because that is the most natural shape for the grammar to produce. This helper runs once per style bucket during Machine construction to turn those arrays into the compact { color, lineStyle, ... } objects the graph-rendering code expects.

    state_style_condense([
    { key: 'color', value: 'red' },
    { key: 'shape', value: 'oval' },
    { key: 'line-style', value: 'dashed' }
    ]);
    // => { color: 'red', shape: 'oval', lineStyle: 'dashed' }

    state_style_condense(undefined);
    // => {}
    throws

    {JssmError} If jssk is neither an array nor undefined, if any element is not an object, if the same key appears more than once, or if a key is not one of the recognized style names.

    internal

    Parameters

    • jssk: JssmStateStyleKeyList

      The list of style keys to condense. undefined is accepted and yields an empty config.

    • Optional machine: any

      Optional Machine reference, used only so that any JssmError thrown can point at the offending machine in its diagnostic message.

    Returns JssmStateConfig

    A JssmStateConfig object containing every key from jssk remapped into its camelCase field.

  • An internal method meant to take a series of declarations and fold them into a single multi-faceted declaration, in the process of building a state. Not generally meant for external use.

    internal

    Parameters

    Returns JssmStateDeclaration

Generated using TypeDoc