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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-mermaid-parser

v2.0.1

Published

Simple parser for Mermaid Diagrams that you can use in the backend.

Downloads

6

Readme

Mermaid Parser

Mermaid Parser is a parser for mermaid diagrams to help us retrieve information about mermaid diagrams we can then use in our projects.

Parsing a mermaid diagram returns the following information:

ParsedDiagram = {
  title: string;          // Title
  accTitle: string;
  edges: Edge[];          // The connections between nodes
  vertices: {             // Map of Nodes with the Node Id as key
    [key: string]: Vertix
  };
  tooltip: string;
  direction: string;      // Direction of the diagram
  classes: string[];
  subGraphs: SubGraph[];  // Information about the subgraphs, like what nodes are in side each one.
};

How to use it

First add simple-mermaid-parser to the project.

npm i simple-mermaid-parser

Then import it where you need:

import { parse, toSvg, toPng } from "simple-mermaid-parser";

So you can use it to parse mermaid diagrams:

const diagram = `
graph LR
  A["The A"] --> B["The B"] --> C["The C"]
  E["The E"] --> C
  F["The F"] --> B
`;
const diagramInfo = await parse(diagram);

console.log(diagramInfo.edges);
/*
Output:
[
  {
    start: 'A',
    end: 'B',
    type: 'arrow_point',
    text: '',
    labelType: 'text',
    stroke: 'normal',
    length: 1
  },
  {
    start: 'B',
    end: 'C',
    type: 'arrow_point',
    text: '',
    labelType: 'text',
    stroke: 'normal',
    length: 1
  },
  {
    start: 'E',
    end: 'C',
    type: 'arrow_point',
    text: '',
    labelType: 'text',
    stroke: 'normal',
    length: 1
  },
  {
    start: 'F',
    end: 'B',
    type: 'arrow_point',
    text: '',
    labelType: 'text',
    stroke: 'normal',
    length: 1
  }
]
*/

Or you can use it to create an SVG image of the diagram:

const diagram = `
graph LR
  A["The A"] --> B["The B"] --> C["The C"]
  E["The E"] --> C
  F["The F"] --> B
`;
const svgText = await toSvg(diagram);
/*
Outputs:
<svg>...</svg>
*/

await toSvg(diagram, "diagram.svg");
/*
Creates diagram.svg
*/

And also a PNG file of the diagram:

const diagram = `
graph LR
  A["The A"] --> B["The B"] --> C["The C"]
  E["The E"] --> C
  F["The F"] --> B
`;

await toPng(diagram, "diagram.png");
/*
Creates diagram.png with the image for this diagram
*/