๐Ÿš€ DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more โ†’
Socket
Book a DemoInstallSign in
Socket

@ts-graphviz/ast

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-graphviz/ast

Graphviz AST(Abstract Syntax Tree) Utilities

latest
Source
npmnpm
Version
3.0.4
Version published
Weekly downloads
784K
37.38%
Maintainers
1
Weekly downloads
ย 
Created
Source

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 HTML nesting depth limit
const ast = parse(dotString, {
  startRule: 'Dot',  // Specify the starting rule (default: 'Dot')
  maxHtmlNestingDepth: 200  // Set maximum HTML nesting depth (default: 100)
});

Security Note:

  • The maxHtmlNestingDepth option limits the depth of nested HTML-like structures in DOT files to prevent stack overflow attacks
  • The default limit of 100 is sufficient for normal use cases (typically <10 levels)
  • HTML-like labels are GraphViz DOT syntax, not browser HTML
  • For processing untrusted DOT files, 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):

Yuki Yamazaki
Yuki Yamazaki

๐Ÿ’ป โš ๏ธ ๐Ÿ“– ๐Ÿค”
LaySent
LaySent

๐Ÿ› โš ๏ธ
elasticdotventures
elasticdotventures

๐Ÿ“–
Christian Murphy
Christian Murphy

๐Ÿ’ป ๐Ÿค” ๐Ÿ“–
Artem
Artem

๐Ÿ›
fredericohpandolfo
fredericohpandolfo

๐Ÿ›
diegoquinteiro
diegoquinteiro

๐Ÿ›
robross0606
robross0606

๐Ÿค”
Blake Regalia
Blake Regalia

๐Ÿ›
bigbug
bigbug

๐Ÿ’ฌ
mrwk
mrwk

๐Ÿ’ฌ
svdvonde
svdvonde

๐Ÿ’ฌ
Adam
Adam

๐Ÿ’ฌ
Trevor Scheer
Trevor Scheer

๏ธ๏ธ๏ธ๏ธโ™ฟ๏ธ
Prem Pillai
Prem Pillai

๐Ÿ›
nagasawaryoya
nagasawaryoya

๐Ÿ’ป โš ๏ธ
YukiSasaki
YukiSasaki

๐Ÿ’ป โš ๏ธ
Madd0g
Madd0g

๐Ÿ›
j4k0xb
j4k0xb

๐Ÿ›
HKrogstie
HKrogstie

๐Ÿ›
Nils K
Nils K

๐Ÿ›
hao2013
hao2013

๐Ÿšง ๐Ÿ‘€
Walter Rafelsberger
Walter Rafelsberger

๐Ÿ’ฌ
grsjst
grsjst

๐Ÿ›
Steve
Steve

๐Ÿ›

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.

FAQs

Package last updated on 25 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts