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

@ts-graphviz/ast

v3.0.6

Published

Graphviz AST(Abstract Syntax Tree) Utilities

Downloads

4,837,335

Readme

Main CodeQL License: MIT All Contributors

OpenSSF Best Practices OpenSSF Scorecard Tidelift

npm version node version deno version npm

@ts-graphviz/ast

This package contains the module for processing the DOT language at the Abstract Syntax Tree (AST) level for the ts-graphviz library.

🔗

GitHub npm Reference Ask DeepWiki

Sponsor OpenCollective

format: Biome test: Vitest build: Vite


It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.

Overview

This package is a foundational component of the ts-graphviz library that enables low-level manipulation of DOT language structures. It provides a parser that converts DOT language strings into AST nodes and a stringifier that converts AST nodes back to DOT language.

Main Functions

The AST package provides several key functions:

  • parse(input: string, options?): Parses a DOT language string into an AST structure
  • stringify(ast: ASTNode): Converts an AST structure to a DOT language string
  • fromModel(model): Converts a Graph Model to an AST structure
  • toModel(ast): Converts an AST structure to a Graph Model

Usage Examples

Parsing DOT Language

import { parse } from "@ts-graphviz/ast";

const dotString = "digraph G { A -> B; }";
const ast = parse(dotString);
console.log(ast);
// Output: A DotASTNode representing the DOT structure

Parser Options

The parse function accepts an optional second argument for configuration:

import { parse } from "@ts-graphviz/ast";

// Parse with custom security limits
const ast = parse(dotString, {
  startRule: 'Dot',              // Specify the starting rule (default: 'Dot')
  maxHtmlNestingDepth: 200,      // Maximum HTML nesting depth (default: 100)
  maxEdgeChainDepth: 2000,       // Maximum edge chain depth (default: 1000)
  maxInputSize: 20971520,        // Maximum input size in bytes (default: 10MB)
  maxASTNodes: 200000            // Maximum AST nodes (default: 100,000)
});

Available Options:

| Option | Default | Description | |--------|---------|-------------| | startRule | 'Dot' | Starting grammar rule for parsing | | maxHtmlNestingDepth | 100 | Maximum depth of nested HTML-like structures | | maxEdgeChainDepth | 1000 | Maximum depth of chained edges (e.g., a -> b -> c -> ...) | | maxInputSize | 10485760 (10MB) | Maximum input size in bytes | | maxASTNodes | 100000 | Maximum number of AST nodes to create |

Security Note:

These limits protect against denial-of-service attacks:

  • maxHtmlNestingDepth: Prevents stack overflow from deeply nested HTML-like structures

    • Normal use cases: typically <10 levels
    • HTML-like labels are GraphViz DOT syntax, not browser HTML
  • maxEdgeChainDepth: Prevents stack overflow from deeply chained edges

    • Example dangerous input: a -> b -> c -> ... -> z (1000+ nodes)
  • maxInputSize: Prevents memory exhaustion from extremely large files

    • Default 10MB is sufficient for most legitimate graphs
    • Can be increased for known large graphs or disabled with 0 (not recommended for untrusted input)
  • maxASTNodes: Prevents memory exhaustion from inputs with excessive elements

    • Each DOT element creates multiple AST nodes
    • Example: A single node statement (node1;) creates ~2-3 AST nodes
    • Can be disabled with 0 (not recommended for untrusted input)

Important: When processing untrusted DOT files (e.g., user uploads), keep these limits enabled with conservative values appropriate for your environment. For additional validation of untrusted content, see the validation guide in @ts-graphviz/adapter documentation.

Generating DOT Language

import { parse, stringify } from "@ts-graphviz/ast";

const dotString = "digraph G { A -> B; }";
const ast = parse(dotString);
// Modify the AST if needed
const outputDotString = stringify(ast);
console.log(outputDotString);
// Output: "digraph G { A -> B; }"

Error Handling

The package provides a specialized error class for handling syntax errors during parsing.

When a parsing error occurs, the parser throws a DotSyntaxError with detailed information about the issue, which helps in debugging DOT language syntax problems.

Contributors 👥

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Changelog 📜

See CHANGELOG.md for more details.

License ⚖️

This software is released under the MIT License, see LICENSE.