Registry / data / dotparser

dotparser

JSON →
library1.1.1jsnpmunverified

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.

npm install dotparser
INSTALL
IMPORT
SIG · DOTPARSER
D
dotparser
datajavascriptv1.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import parse from 'dotparser';
import { parse } from 'dotparser';
The primary export is a default export. For ESM environments, ensure `esModuleInterop` is enabled in TypeScript or use `import * as dotparser from 'dotparser'; const parse = dotparser;` in plain JavaScript for reliable interop with CommonJS modules.
parse (CommonJS)
const parse = require('dotparser');
This is the primary and most straightforward way to import the library in CommonJS environments, as shown in the package's original documentation.
Type definitions
import type { GraphAST } from 'dotparser';
import { GraphAST } from 'dotparser';
The package includes built-in TypeScript declarations. Import types using `import type` to ensure they are stripped at compile time, especially if a specific AST shape is needed for type safety.

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); }
Debug
Known issues
gotchaThe `dotparser` package has not received updates for approximately four years as of early 2026. While still functional and widely used, newer GraphViz features or bug fixes might not be supported. Consider more actively maintained alternatives for new projects.
fix
For new projects or if encountering issues with modern DOT syntax, evaluate `@ts-graphviz/parser` or similar libraries which offer active development and broader feature sets.
affects: >=1.1.1
gotchaWhen importing `dotparser` in an ES Module (ESM) environment, direct default imports (`import parse from 'dotparser';`) might require the `esModuleInterop` compiler option set to `true` in TypeScript configurations for correct interoperability with its CommonJS export. Without it, you might need to use `import * as dotparser from 'dotparser'; const parse = dotparser.default || dotparser;` or similar patterns in plain JavaScript.
fix
In `tsconfig.json`, set `"esModuleInterop": true`. In plain JavaScript ESM, use dynamic import or `import * as Name from 'pkg';` and access the `default` property if needed.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Expected "graph", "digraph", "subgraph", "node", "edge", "strict", "ID", "port", "compass_port" or "attribute" but "..." found.
The input string provided to the `parse` function is not valid GraphViz DOT syntax.
fix
Review the DOT string for syntax errors. GraphViz has a strict grammar. Use online validators or refer to the GraphViz DOT language specification to ensure correctness.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
dotparser — npm install dotparser · libregistry