npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@libnare/rust-dagre

v0.1.1

Published

A directed graph layout library for Rust, Node.js, and WebAssembly

Readme

Rust-Dagre

A high-performance Rust port of dagre.js, a directed graph layout library.

Based on

Overview

This project uses napi-rs to provide a Universal Package supporting both Node.js Native Addons and WebAssembly (WASI).

Installation

yarn add @libnare/rust-dagre
# or
npm install @libnare/rust-dagre

Usage

Node.js

The package automatically loads the native binary for your platform. If the native binary is unavailable, it falls back to the WebAssembly (WASI) version.

Note: The layout function is asynchronous.

const { layout } = require('@libnare/rust-dagre');

async function run() {
  // 1. Define Nodes
  const nodes = JSON.stringify([
    { v: "1", width: 100, height: 50 },
    { v: "2", width: 100, height: 50 }
  ]);

  // 2. Define Edges
  const edges = JSON.stringify([
    { v: "1", w: "2" }
  ]);

  // 3. Optional Configuration
  const config = JSON.stringify({
    rankdir: "TB", // Top-to-Bottom
    align: "ul",   // Up-Left (ul, ur, dl, dr)
    nodesep: 50,
    ranksep: 50,
    edgesep: 10
  });

  // 4. Run Layout
  try {
    const result = await layout(nodes, edges, config);
    
    console.log("Graph Dimensions:", result.width, result.height);
    console.log("Nodes:", JSON.parse(result.nodesJson));
    console.log("Edges:", JSON.parse(result.edgesJson));
  } catch (err) {
    console.error("Layout failed:", err);
  }
}

run();

WebAssembly (Browser)

For browser usage, napi-rs handles the WASM loading. The usage is identical to Node.js, returning a Promise.

import { layout } from '@libnare/rust-dagre';

async function run() {
  // Define inputs (same as Node.js example)
  const nodes = JSON.stringify([
    { v: "1", width: 100, height: 50 },
    { v: "2", width: 100, height: 50 }
  ]);
  const edges = JSON.stringify([
    { v: "1", w: "2" }
  ]);

  // Usage is identical to Node.js
  const result = await layout(nodes, edges);
  console.log(result);
}

run();

API

layout(nodesJson, edgesJson, configJson?)

Computes the layout for the graph. Returns a Promise.

  • nodesJson (string): JSON string array of nodes. Each node must have v (id), width, and height.

  • edgesJson (string): JSON string array of edges. Each edge must have v (source) and w (target).

  • configJson (string, optional): JSON string for layout configuration.

    • rankdir: "TB" | "BT" | "LR" | "RL" (default: "TB")
    • align: "ul" | "ur" | "dl" | "dr" (default: undefined)
    • nodesep: number (default: 50)
    • ranksep: number (default: 50)
    • edgesep: number (default: 20)
    • ranker: "network-simplex" | "tight-tree" | "longest-path" (default: "network-simplex")
  • Returns: Promise<NapiLayoutResult> resolving to an object containing:

    • width: Total graph width.
    • height: Total graph height.
    • nodesJson: Updated nodes with x, y coordinates.
    • edgesJson: Updated edges with control points (points).

layoutSimple(inputJson)

A convenience function that takes a single JSON object containing nodes, edges, and config. Synchronous function.

  • inputJson (string): { nodes: [...], edges: [...], layout: {...} }
  • Returns: JSON string of the output { nodes, edges, width, height }.

Development

Prerequisites

  • Rust: Stable toolchain (install via rustup).
  • Node.js: v18+ recommended.
  • Yarn: v4+ recommended.

Build Commands

  1. Install Dependencies:

    yarn install
  2. Build Native & WASM:

    yarn build

    This command builds the native addon for your current OS and the WASM target.

  3. Run Tests:

    • JS Integration Tests:
      yarn test
  4. Lint & Format:

    yarn lint
    yarn format

License

MIT