
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isnβt whitelisted.
@ts-graphviz/common
Advanced tools
@ts-graphviz/common is a TypeScript library that provides common utilities and types for working with Graphviz, a graph visualization software. It is part of the ts-graphviz project, which aims to provide a set of tools for creating and manipulating Graphviz graphs in TypeScript.
Graph Creation
This feature allows you to create a directed graph (Digraph), add nodes, and add edges between nodes. The `toDot` method converts the graph to DOT format, which is the plain text graph description language used by Graphviz.
const { Digraph } = require('@ts-graphviz/common');
const g = new Digraph('G');
g.addNode('A');
g.addNode('B');
g.addEdge(['A', 'B']);
console.log(g.toDot());
Node and Edge Attributes
This feature allows you to add attributes to nodes and edges. Attributes can include properties like color, shape, and labels, which customize the appearance and behavior of the graph elements.
const { Digraph } = require('@ts-graphviz/common');
const g = new Digraph('G');
g.addNode('A', { color: 'red' });
g.addNode('B', { shape: 'box' });
g.addEdge(['A', 'B'], { label: 'A to B' });
console.log(g.toDot());
Subgraphs
This feature allows you to create subgraphs within a main graph. Subgraphs can be used to group nodes and edges together, often for the purpose of applying specific attributes or for organizational purposes.
const { Digraph, Subgraph } = require('@ts-graphviz/common');
const g = new Digraph('G');
const sg = new Subgraph('cluster_0');
sg.addNode('A');
sg.addNode('B');
g.addSubgraph(sg);
console.log(g.toDot());
Graphlib is a JavaScript library for creating and manipulating directed graphs. It provides a rich set of features for graph creation, traversal, and manipulation. Compared to @ts-graphviz/common, graphlib is more focused on the algorithmic aspects of graph manipulation rather than visualization.
Cytoscape is a JavaScript library for visualizing complex networks and graphs. It provides a wide range of features for graph visualization, including layout algorithms, styling, and interaction. While @ts-graphviz/common focuses on generating DOT files for Graphviz, Cytoscape is more geared towards interactive graph visualization in web applications.
d3-graphviz is a library that combines D3.js and Graphviz to render graphs in the browser. It allows you to create and manipulate graphs using D3.js and then render them using Graphviz. Compared to @ts-graphviz/common, d3-graphviz is more focused on rendering and visualizing graphs in a web environment.
Type information, constants, and utility functions related to the DOT language attributes, attribute values, and models for ts-graphviz.
π
It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
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):
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.
FAQs
Graphviz Types and Utilities
The npm package @ts-graphviz/common receives a total of 331,409 weekly downloads. As such, @ts-graphviz/common popularity was classified as popular.
We found that @ts-graphviz/common demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isnβt whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.