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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mermaid-rs-wasm

v0.0.3

Published

Mermaid diagram renderer compiled to WebAssembly

Readme

mermaid-rs-wasm

Mermaid diagram renderer compiled to WebAssembly, powered by ariel-rs. Renders Mermaid syntax to SVG entirely in the browser — no server, no Node.js runtime.

Installation

npm install mermaid-rs-wasm

Usage

The package exports an ES module (ESM) and a CommonJS module (CJS).

// ESM (browser / bundler)
import { initMermaid, render_mermaid } from 'mermaid-rs-wasm';

await initMermaid();

const result = render_mermaid(`
flowchart TD
    A[Start] --> B{Check}
    B -->|Yes| C[Done]
    B -->|No| D[Retry]
    D --> B
`, 'default');

if (result.startsWith('{')) {
  // parse error — result is a JSON string
  const err = JSON.parse(result);
  console.error(err);
} else {
  // success — result is an SVG string
  document.getElementById('output').innerHTML = result;
}

CommonJS (Node.js)

The Node.js build loads WASM automatically at require time. Do not call any init function — it is not needed nor exported.

const { render_mermaid } = require('mermaid-rs-wasm');
const svg = render_mermaid('flowchart TD\n    A --> B', 'default');

When using TypeScript with tsx or ts-node, import statements are transpiled to require() by default, so the same rule applies:

import { render_mermaid } from 'mermaid-rs-wasm';
const svg = render_mermaid('flowchart TD\n    A --> B', 'default');

Bundler (Vite / webpack)

Pass the WASM URL explicitly so the bundler can handle the asset:

import { initMermaid, render_mermaid } from 'mermaid-rs-wasm';
import wasmUrl from 'mermaid-rs-wasm/pkg/ariel_wasm_bg.wasm?url'; // Vite

await initMermaid(wasmUrl);

API

initMermaid(input?): Promise<InitOutput>

Loads and instantiates the WASM module. Must be awaited before calling any other function. ESM only.

| Parameter | Type | Description | |-----------|------|-------------| | input | string \| URL \| Response \| BufferSource | Optional. Path or response for the .wasm file. Defaults to fetching ariel_wasm_bg.wasm from the same directory. |

initMermaidSync(module): InitOutput

Synchronous variant. ESM only. Pass a pre-loaded BufferSource or WebAssembly.Module.

import { initMermaidSync, render_mermaid } from 'mermaid-rs-wasm';
import { readFileSync } from 'fs';

initMermaidSync({ module: readFileSync(new URL('./node_modules/mermaid-rs-wasm/pkg/ariel_wasm_bg.wasm', import.meta.url)) });

render_mermaid(input, theme): string

Renders a Mermaid diagram to SVG.

| Parameter | Type | Values | |-----------|------|--------| | input | string | Mermaid diagram source | | theme | string | "default" "dark" "forest" "neutral" |

Return value:

  • Starts with < — SVG string, render directly to the DOM or canvas.
  • Starts with { — JSON error string. Parse it to get error details.

Error JSON shape:

// Parse error (syntax problems in the diagram source)
{
  diagram_type: string;
  errors: Array<{
    message: string;
    line?: number;     // 1-based line number, if available
  }>;
}

// Render error (internal failure, no parse errors)
{
  diagram_type: string;
  message: string;
  errors: [];
}

Error handling example:

const result = render_mermaid(source, 'default');

if (result.startsWith('{')) {
  const err = JSON.parse(result);
  for (const e of err.errors) {
    const loc = e.line ? `line ${e.line}: ` : '';
    console.error(`[${err.diagram_type}] ${loc}${e.message}`);
  }
} else {
  container.innerHTML = result;
}

Supported Diagram Types

| Keyword | Diagram | |---------|---------| | flowchart / graph | Flowchart | | sequenceDiagram | Sequence | | classDiagram | Class | | stateDiagram-v2 | State | | erDiagram | Entity Relationship | | gantt | Gantt | | gitGraph | Git Graph | | pie | Pie Chart | | mindmap | Mind Map | | timeline | Timeline | | quadrantChart | Quadrant | | xychart-beta | XY Chart | | C4Context / C4Container / ... | C4 | | block-beta | Block | | packet-beta | Packet | | journey | User Journey | | requirementDiagram | Requirement | | kanban | Kanban | | sankey-beta | Sankey | | treemap | Treemap | | radar | Radar | | venn | Venn | | architecture-beta | Architecture | | eventmodeling | Event Modeling | | fishbone / ishikawa | Ishikawa | | wardley | Wardley Map | | treeView-beta | Tree View |

License

MIT