dotparser

1.1.1 · maintenance · verified Tue Apr 21

dotparser is a JavaScript library designed to parse GraphViz dot file format into an Abstract Syntax Tree (AST). It provides a language-agnostic AST representation, making it suitable for graph library authors who need to transform `.dot` files into their own specific graph data structures without being tied to a particular graph visualization or manipulation library. The current stable version is 1.1.1, last published approximately four years ago as of early 2026. While widely downloaded, its development appears to be in maintenance mode, with a successor project, `@ts-graphviz/parser`, offering more modern features and active development. A key differentiator is its focus purely on AST generation, capable of parsing the standard Graphviz test suite, providing a robust foundation for building custom graph tooling.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing a sample GraphViz DOT string into its Abstract Syntax Tree (AST) representation and logging the result. It also includes basic error handling and shows how to inspect the resulting AST structure.

import parse from 'dotparser';

const dotString = `
  digraph G {
    node [shape=box];
    a -> b;
    b -> c [label="edge 2"];
    subgraph cluster_0 {
      label = "Cluster 0";
      d -> e;
    }
  }
`;

try {
  const ast = parse(dotString);
  console.log('Successfully parsed DOT string:');
  console.log(JSON.stringify(ast, null, 2));
  // Example of accessing elements: The AST is an array of top-level statements
  if (ast.length > 0 && ast[0].type === 'graph') {
    console.log(`Graph ID: ${ast[0].id}`);
    console.log(`Number of children in graph: ${ast[0].children.length}`);
  }
} catch (error) {
  console.error('Error parsing DOT string:', error.message);
}

view raw JSON →