code-to-graph

1.0.15 • Public • Published

code-to-graph

Transforms code (JS) into graphs (graphviz, mermaid flowchart, ...)

Interactive Demo

https://crubier.github.io/code-to-graph/

A bigger example

CLI Usage

Call the cli with a js file name, it prints out the Mermaid.js graph definition

yarn global add code-to-graph
code-to-graph example.js

To see the result visualy, paste it in

https://mermaidjs.github.io/mermaid-live-editor

Or you can use it on gitlab using the ```mermaid language in comments, descriptions or markdown files.

Explanation

Turns this:

x => {
  const a = f(x);
  if (=== 0) {
    let a = null;
    throw new Error("Nooes");
  } else {
    const c = 8;
    return 4;
  }
};

Into this:

graph TD
        statementfroml1c6tol1c19("const a = f(x);")
        statementfroml1c19tol1c90{"x === 0"}
        statementfroml1c29tol1c40("let a = null;")
        statementfroml1c41tol1c65>"throw new Error('Nooes');"]
        style statementfroml1c41tol1c65 fill:#FF9999
        statementfroml1c71tol1c81("const c = 8;")
        statementfroml1c81tol1c89>"return 4;"]
        style statementfroml1c81tol1c89 fill:#99FF99
        statementfroml1c19tol1c90 -- true --> statementfroml1c29tol1c40
        statementfroml1c19tol1c90 -- false --> statementfroml1c71tol1c81
        statementfroml1c29tol1c40 --> statementfroml1c41tol1c65
        statementfroml1c71tol1c81 --> statementfroml1c81tol1c89
        statementfroml1c6tol1c19 --> statementfroml1c19tol1c90

Whichs renders into this:

Example mermaid diagram

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.151latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.151
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i code-to-graph

Weekly Downloads

1

Version

1.0.15

License

MIT

Unpacked Size

11.3 MB

Total Files

49

Last publish

Collaborators

  • crubier