ts-graphviz
    Preparing search index...

    Module @ts-graphviz/common - v3.0.2

    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.

    • 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

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

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

    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',
    };

    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);
    }

    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');
    }

    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.

    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!

    See CHANGELOG.md for more details.

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

    Namespaces

    Attribute
    ClusterMode
    Insensitive
    Side

    Type Aliases

    FilterableModel
    Insensitive

    Functions

    isAttributeListModel
    isCompass
    isEdgeModel
    isForwardRefNode
    isNodeModel
    isNodeRef
    isNodeRefGroupLike
    isNodeRefLike
    isRootGraphModel
    isSubgraphModel
    toNodeRef
    toNodeRefGroup

    Attribute

    Attribute
    AttributeKey
    ClusterSubgraphAttributeKey
    EdgeAttributeKey
    GraphAttributeKey
    NodeAttributeKey
    SubgraphAttributeKey

    Attribute Types

    AddDouble
    AddPoint
    ArrowType
    Blank
    ClusterMode
    Color
    ColorList
    Compass
    DirType
    Double
    DoubleList
    EscString
    HTMLLikeLabel
    Int
    LayerList
    LayerRange
    LblString
    OutputMode
    PackMode
    Pagedir
    Point
    PointList
    PortPos
    QuadType
    Rankdir
    RankType
    Rect
    Shape
    SmoothType
    SplineType
    StartType
    Style
    TBbalanceType
    ViewPort

    Models

    AttributeListModel
    Attributes
    AttributesGroupModel
    DotObjectModel
    EdgeConstructor
    EdgeModel
    ForwardRefNode
    GraphBaseModel
    GraphCommonAttributes
    HasAttributes
    HasComment
    NodeConstructor
    NodeModel
    Port
    RootGraphConstructor
    RootGraphModel
    SubgraphConstructor
    SubgraphModel
    ASTType
    AttributeListKind
    AttributesEntities
    AttributesObject
    AttributeValue
    DotObjectType
    EdgeAttributesObject
    EdgeTarget
    EdgeTargetLike
    EdgeTargetLikeTuple
    EdgeTargetTuple
    GraphAttributesObject
    NodeAttributesObject
    NodeRef
    NodeRefGroup
    NodeRefGroupLike
    NodeRefLike
    SubgraphAttributesObject

    Models Context

    ModelsContext
    RootModelsContext
    createModelsContext