@lifeomic/mermaid-simple-flowchart-parser
TypeScript icon, indicating that this package has built-in type declarations

1.3.4 • Public • Published

mermaid-simple-flowchart-parser

Parse a subset of mermaid flowchart markdown syntax to JSON Graph.

Install

yarn add @lifeomic/mermaid-simple-flowchart-parser

Usage

Only one function, parseString is exported. You pass a string containing mermaid flowchart information. The function will return JSON Graph data or raise an error.

import { parseString } from '@lifeomic/mermaid-simple-flowchart-parser';

const chart = `
flowchart
  start
    --> call1("data.debug, arg1: a, arg2: b,c")
`;

const graph = parseString(chart);

/* 
graph = {
  graph: {
    directed: true,
    nodes: {
      call1: {
        label: 'data.debug',
        metadata: {
          action: 'data.debug',
          params: {
            arg1: 'a',
            arg2: 'b,c'
          },
        },
      },
      on_start: {
        label: 'start',
      },
    },
    edges: [
      {
        directed: true,
        source: 'on_start',
        target: 'call1',
      },
    ],
  }
} */

Limitations

This is a subset of mermaid flowchart syntax. It is meant to handle only the following:

  • %% Comments - comments in code
  • flowchart - start of flowchart (required)
  • id - bare node definitions (for start and error)
  • id("xxx") - action nodes with possible parameters
  • --> - edges between nodes (note this is the only edge supported)
  • -- Comment --> and -->|comment| - edge comments are ignored, but will display in mermaid

Readme

Keywords

none

Package Sidebar

Install

npm i @lifeomic/mermaid-simple-flowchart-parser

Weekly Downloads

0

Version

1.3.4

License

UNLICENSED

Unpacked Size

73.4 kB

Total Files

9

Last publish

Collaborators

  • lifeomicdev
  • npm-lifeomicdev-github