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 🙏

© 2024 – Pkg Stats / Ryan Hefner

directed-graph-map

v1.2.8

Published

[![CircleCI](https://circleci.com/gh/wehriam/directed-graph-map.svg?style=svg)](https://circleci.com/gh/wehriam/directed-graph-map) [![npm version](https://badge.fury.io/js/directed-graph-map.svg)](http://badge.fury.io/js/directed-graph-map) [![codecov](h

Downloads

25

Readme

Directed Graph Map

CircleCI npm version codecov

Directed graph data structure implemented using native Map and Set objects. Similiar to multi-key maps or bidirectional maps.

const dg = new DirectedGraphMap();
                      //  A
dg.addEdge('A', 'X'); //  ├── X
dg.addEdge('A', 'Y'); //  ├── Y
dg.addEdge('A', 'Z'); //  └── Z

dg.getTargets('A');   //  X, Y, Z

dg.size; // 3
dg.edges; // [['A', 'X'], ['A', 'Y'], ['A', 'Z']]
dg.sources; // ['A']
dg.targets; // ['X', 'Y', 'z']

Install

yarn add directed-graph-map

Usage

const DirectedGraphMap = require('directed-graph-map');

const dgm = new DirectedGraphMap([['A', 'B']]);

//  A
//  └── B

dgm.hasEdge('A', 'B'); // true

dgm.addEdge('B', 'C');

//  A
//  └── B
//      └── C

dgm.hasEdge('B', 'C'); // true
dgm.getTargets('A'); // new Set(['B']);
dgm.getTargets('B'); // new Set(['C']);
dgm.getTargets('C'); // new Set();
dgm.getSources('A'); // new Set();
dgm.getSources('B'); // new Set(['A']);
dgm.getSources('C'); // new Set(['B']);

dgm.removeSource('A');

//  B
//  └── C

dgm.hasEdge('A', 'B'); // false
dgm.getTargets('A'); // new Set();

dgm.removeTarget('C');

//  Empty

dgm.getTargets('B'); // new Set();
dgm.hasEdge('B', 'C'); // false

dgm.addEdge('A', 'B');

//  A
//  └── B

dgm.hasEdge('A', 'B'); // true

dgm.removeEdge('A', 'B');

//  Empty

dgm.hasEdge('A', 'B'); // false

API

Table of Contents

DirectedGraphMap

Class representing a Directed Graph Map

Parameters

  • edges Iterable<[S, T]> Iterable containing source -> target pairs (optional, default [])

addEdge

Add an edge to the graph map.

Parameters
  • source S Source of the edge
  • target T Target of the edge

Returns void

removeEdge

Remove an edge from the graph map.

Parameters
  • source S Source of the edge
  • target T Target of the edge

Returns void

hasEdge

Test if a edge exists in the graph map.

Parameters
  • source S Source of the edge
  • target T Target of the edge

Returns boolean Whether the edge exists in the graph map.

hasSource

Test if a source exists in the graph map.

Parameters
  • source S Source of the edge

Returns boolean

hasTarget

Test if a target exists in the graph map.

Parameters
  • target T Target of the edge

Returns boolean

removeSource

Remove all edges from a source.

Parameters
  • source S Source of the edge

Returns void

removeTarget

Remove all edges to a target.

Parameters
  • target T Target of the edge

Returns void

getSources

Get all sources with edges to a target.

Parameters
  • target T Target of the edge

Returns Set<S> Set of sources

getTargets

Get all targets with edges from a source.

Parameters
  • source S Source of the edge

Returns Set<T> Set of targets

DirectedGraphMap#edges

Array of edges

DirectedGraphMap#size

Edge count

DirectedGraphMap#sources

Set of sources

DirectedGraphMap#targets

Set of targets