πŸš€ DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

@ts-graphviz/common

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-graphviz/common

Graphviz Types and Utilities

latest
Source
npmnpm
Version
3.0.4
Version published
Weekly downloads
852K
3.82%
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/common

Type information, constants, and utility functions related to the DOT language attributes, attribute values, and models for ts-graphviz.

πŸ”—

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.

Features

  • Type definitions for DOT language elements, including attributes and attribute values
  • Constants representing common attribute names and values
  • Comprehensive type guards for runtime type checking and TypeScript type narrowing
  • Node reference utilities for parsing and converting complex node references
  • Performance-optimized utilities for working with large model collections
  • Seamless integration with @ts-graphviz/react for type-safe model filtering
  • Dual-mode type handling - runtime validation or trusted user assertions

Usage

Basic Type Definitions

Import the necessary types, constants, or utility functions from the @ts-graphviz/common package:

import {
  NodeAttributesObject,
  EdgeAttributesObject,
  isNodeModel,
  isEdgeModel,
  toNodeRef
} from '@ts-graphviz/common';

Type-Safe Model Operations

The package excels at providing type safety for graph model operations:

const nodeAttr: NodeAttributesObject = {
  label: 'Node label',
  shape: 'ellipse',
};

const edgeAttr: EdgeAttributesObject = {
  label: 'Edge label',
  color: 'red',
};

Type Guards and Model Utilities

The package provides powerful type guards for working with graph models with full TypeScript integration:

import {
  isNodeModel,
  isEdgeModel,
  isRootGraphModel,
  isSubgraphModel,
  isAttributeListModel
} from '@ts-graphviz/common';

// Type-safe model checking
if (isNodeModel(someModel)) {
  // TypeScript knows someModel is NodeModel
  console.log(someModel.id);
}

if (isEdgeModel(someModel)) {
  // TypeScript knows someModel is EdgeModel
  console.log(someModel.targets);
}

Node Reference Utilities

Utilities for working with node references and compass directions:

import {
  isNodeRef,
  isNodeRefLike,
  isCompass,
  toNodeRef,
  toNodeRefGroup
} from '@ts-graphviz/common';

// Check if a value is a valid node reference
if (isNodeRefLike('node1:port:n')) {
  const nodeRef = toNodeRef('node1:port:n');
  console.log(nodeRef); // { id: 'node1', port: 'port', compass: 'n' }
}

// Convert multiple node references
const targets = toNodeRefGroup(['node1', 'node2:port', 'node3::s']);
console.log(targets);
// [
//   { id: 'node1' },
//   { id: 'node2', port: 'port' },
//   { id: 'node3', port: '', compass: 's' }
// ]

// Validate compass directions
if (isCompass('ne')) {
  console.log('Valid compass direction');
}

Advanced Type Checking

The package provides additional utilities for complex type checking scenarios:

import {
  isForwardRefNode,
  isNodeRefGroupLike,
  isNodeRef,
  isNodeRefLike,
  FilterableModel
} from '@ts-graphviz/common';

// Check for forward reference nodes
const forwardRef = { id: 'futureNode' };
if (isForwardRefNode(forwardRef)) {
  console.log('Valid forward reference');
}

// Validate arrays of node references
const targets = ['node1', 'node2:port'];
if (isNodeRefGroupLike(targets)) {
  const nodeRefs = toNodeRefGroup(targets);
  // Process validated node references
}

For more examples and usage details, please refer to the ts-graphviz documentation.

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.

Keywords

graphviz

FAQs

Package last updated on 10 Nov 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