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 🙏

© 2026 – Pkg Stats / Ryan Hefner

undirected-graph-typed

v2.2.4

Published

Undirected Graph

Readme

NPM GitHub top language npm eslint npm bundle size npm bundle size npm

What

Brief

This is a standalone Undirected Graph data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete data-structure-typed package

How

install

npm

npm i undirected-graph-typed --save

yarn

yarn add undirected-graph-typed

snippet

basic UndirectedGraph vertex and edge creation

 // Create a simple undirected graph
    const graph = new UndirectedGraph<string>();

    // Add vertices
    graph.addVertex('A');
    graph.addVertex('B');
    graph.addVertex('C');
    graph.addVertex('D');

    // Verify vertices exist
    console.log(graph.hasVertex('A')); // true;
    console.log(graph.hasVertex('B')); // true;
    console.log(graph.hasVertex('E')); // false;

    // Check vertex count
    console.log(graph.size); // 4;

UndirectedGraph edge operations (bidirectional)

 const graph = new UndirectedGraph<string>();

    // Add vertices
    graph.addVertex('A');
    graph.addVertex('B');
    graph.addVertex('C');

    // Add undirected edges (both directions automatically)
    graph.addEdge('A', 'B', 1);
    graph.addEdge('B', 'C', 2);
    graph.addEdge('A', 'C', 3);

    // Verify edges exist in both directions
    console.log(graph.hasEdge('A', 'B')); // true;
    console.log(graph.hasEdge('B', 'A')); // true; // Bidirectional!

    console.log(graph.hasEdge('C', 'B')); // true;
    console.log(graph.hasEdge('B', 'C')); // true; // Bidirectional!

    // Get neighbors of A
    const neighborsA = graph.getNeighbors('A');
    console.log(neighborsA[0].key); // 'B';
    console.log(neighborsA[1].key); // 'C';

UndirectedGraph deleteEdge and vertex operations

 const graph = new UndirectedGraph<string>();

    // Build a simple undirected graph
    graph.addVertex('X');
    graph.addVertex('Y');
    graph.addVertex('Z');
    graph.addEdge('X', 'Y', 1);
    graph.addEdge('Y', 'Z', 2);
    graph.addEdge('X', 'Z', 3);

    // Delete an edge
    graph.deleteEdge('X', 'Y');
    console.log(graph.hasEdge('X', 'Y')); // false;

    // Bidirectional deletion confirmed
    console.log(graph.hasEdge('Y', 'X')); // false;

    // Other edges should remain
    console.log(graph.hasEdge('Y', 'Z')); // true;
    console.log(graph.hasEdge('Z', 'Y')); // true;

    // Delete a vertex
    graph.deleteVertex('Y');
    console.log(graph.hasVertex('Y')); // false;
    console.log(graph.size); // 2;

UndirectedGraph connectivity and neighbors

 const graph = new UndirectedGraph<string>();

    // Build a friendship network
    const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
    for (const person of people) {
      graph.addVertex(person);
    }

    // Add friendships (undirected edges)
    graph.addEdge('Alice', 'Bob', 1);
    graph.addEdge('Alice', 'Charlie', 1);
    graph.addEdge('Bob', 'Diana', 1);
    graph.addEdge('Charlie', 'Eve', 1);
    graph.addEdge('Diana', 'Eve', 1);

    // Get friends of each person
    const aliceFriends = graph.getNeighbors('Alice');
    console.log(aliceFriends[0].key); // 'Bob';
    console.log(aliceFriends[1].key); // 'Charlie';
    console.log(aliceFriends.length); // 2;

    const dianaFriends = graph.getNeighbors('Diana');
    console.log(dianaFriends[0].key); // 'Bob';
    console.log(dianaFriends[1].key); // 'Eve';
    console.log(dianaFriends.length); // 2;

    // Verify bidirectional friendship
    const bobFriends = graph.getNeighbors('Bob');
    console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
    console.log(bobFriends[1].key); // 'Diana';

UndirectedGraph for social network connectivity analysis

 interface Person {
      id: number;
      name: string;
      location: string;
    }

    // UndirectedGraph is perfect for modeling symmetric relationships
    // (friendships, collaborations, partnerships)
    const socialNetwork = new UndirectedGraph<number, Person>();

    // Add people as vertices
    const people: [number, Person][] = [
      [1, { id: 1, name: 'Alice', location: 'New York' }],
      [2, { id: 2, name: 'Bob', location: 'San Francisco' }],
      [3, { id: 3, name: 'Charlie', location: 'Boston' }],
      [4, { id: 4, name: 'Diana', location: 'New York' }],
      [5, { id: 5, name: 'Eve', location: 'Seattle' }]
    ];

    for (const [id] of people) {
      socialNetwork.addVertex(id);
    }

    // Add friendships (automatically bidirectional)
    socialNetwork.addEdge(1, 2, 1); // Alice <-> Bob
    socialNetwork.addEdge(1, 3, 1); // Alice <-> Charlie
    socialNetwork.addEdge(2, 4, 1); // Bob <-> Diana
    socialNetwork.addEdge(3, 5, 1); // Charlie <-> Eve
    socialNetwork.addEdge(4, 5, 1); // Diana <-> Eve

    console.log(socialNetwork.size); // 5;

    // Find direct connections for Alice
    const aliceConnections = socialNetwork.getNeighbors(1);
    console.log(aliceConnections[0].key); // 2;
    console.log(aliceConnections[1].key); // 3;
    console.log(aliceConnections.length); // 2;

    // Verify bidirectional connections
    console.log(socialNetwork.hasEdge(1, 2)); // true;
    console.log(socialNetwork.hasEdge(2, 1)); // true; // Friendship works both ways!

    // Remove a person from network
    socialNetwork.deleteVertex(2); // Bob leaves
    console.log(socialNetwork.hasVertex(2)); // false;
    console.log(socialNetwork.size); // 4;

    // Alice loses Bob as a friend
    const updatedAliceConnections = socialNetwork.getNeighbors(1);
    console.log(updatedAliceConnections[0].key); // 3;
    console.log(updatedAliceConnections[1]); // undefined;

    // Diana loses Bob as a friend
    const dianaConnections = socialNetwork.getNeighbors(4);
    console.log(dianaConnections[0].key); // 5;
    console.log(dianaConnections[1]); // undefined;

API docs & Examples

API Docs

Live Examples

Examples Repository

Data Structures

Standard library data structure comparison

Benchmark

Built-in classic algorithms

Software Engineering Design Standards