{"id":15594,"library":"dotparser","title":"dotparser","description":"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.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/anvaka/dotparser","tags":["javascript","dot","xdot","graphviz","parser","ast"],"install":[{"cmd":"npm install dotparser","lang":"bash","label":"npm"},{"cmd":"yarn add dotparser","lang":"bash","label":"yarn"},{"cmd":"pnpm add dotparser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { parse } from 'dotparser';","symbol":"parse","correct":"import parse from 'dotparser';"},{"note":"This is the primary and most straightforward way to import the library in CommonJS environments, as shown in the package's original documentation.","symbol":"parse (CommonJS)","correct":"const parse = require('dotparser');"},{"note":"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.","wrong":"import { GraphAST } from 'dotparser';","symbol":"Type definitions","correct":"import type { GraphAST } from 'dotparser';"}],"quickstart":{"code":"import parse from 'dotparser';\n\nconst dotString = `\n  digraph G {\n    node [shape=box];\n    a -> b;\n    b -> c [label=\"edge 2\"];\n    subgraph cluster_0 {\n      label = \"Cluster 0\";\n      d -> e;\n    }\n  }\n`;\n\ntry {\n  const ast = parse(dotString);\n  console.log('Successfully parsed DOT string:');\n  console.log(JSON.stringify(ast, null, 2));\n  // Example of accessing elements: The AST is an array of top-level statements\n  if (ast.length > 0 && ast[0].type === 'graph') {\n    console.log(`Graph ID: ${ast[0].id}`);\n    console.log(`Number of children in graph: ${ast[0].children.length}`);\n  }\n} catch (error) {\n  console.error('Error parsing DOT string:', error.message);\n}","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.1.1"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"The input string provided to the `parse` function is not valid GraphViz DOT syntax.","error":"SyntaxError: Expected \"graph\", \"digraph\", \"subgraph\", \"node\", \"edge\", \"strict\", \"ID\", \"port\", \"compass_port\" or \"attribute\" but \"...\" found."}],"ecosystem":"npm"}