New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@ts-graphviz/ast

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-graphviz/ast

Graphviz AST(Abstract Syntax Tree) Utilities


Version published
Weekly downloads
337K
increased by5.35%
Maintainers
1
Weekly downloads
 
Created

What is @ts-graphviz/ast?

@ts-graphviz/ast is an npm package that provides an Abstract Syntax Tree (AST) for Graphviz's DOT language. It allows you to parse, manipulate, and generate DOT files programmatically using TypeScript.

What are @ts-graphviz/ast's main functionalities?

Parsing DOT Files

This feature allows you to parse a DOT string into an AST. The code sample demonstrates how to parse a simple DOT string and output the resulting AST.

const { parse } = require('@ts-graphviz/ast');
const dot = 'digraph G { a -> b; }';
const ast = parse(dot);
console.log(JSON.stringify(ast, null, 2));

Generating DOT Files

This feature allows you to generate a DOT string from an AST. The code sample demonstrates how to create a simple AST and convert it back to a DOT string.

const { print } = require('@ts-graphviz/ast');
const ast = {
  type: 'Graph',
  id: 'G',
  body: [
    { type: 'EdgeStatement', edge_list: [{ id: 'a' }, { id: 'b' }] }
  ]
};
const dot = print(ast);
console.log(dot);

Manipulating AST

This feature allows you to manipulate the AST before converting it back to a DOT string. The code sample demonstrates how to add a new edge to the graph.

const { parse, print } = require('@ts-graphviz/ast');
let dot = 'digraph G { a -> b; }';
let ast = parse(dot);
ast.body.push({ type: 'EdgeStatement', edge_list: [{ id: 'b' }, { id: 'c' }] });
dot = print(ast);
console.log(dot);

Other packages similar to @ts-graphviz/ast

FAQs

Package last updated on 12 Mar 2024

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