@ts-graphviz/common
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @ts-graphviz/common

Weekly Downloads

564,741

Version

3.0.0

License

MIT

Unpacked Size

253 kB

Total Files

6

Last publish

Collaborators

  • kamiazya