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

level-directed-graph-map

v1.1.1

Published

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

Readme

LevelDB Directed Graph Map

CircleCI npm version codecov

Directed graph data structure implemented using LevelDB. Similiar to multi-key maps or bidirectional maps.

See directed-graph-map for a synchronous, in-memory version.

const run = async () => {
  const db = level('./optional-db-path');
  const dg = new LevelDirectedGraphMap(db, [], { namespace: 'example' });
  await dg.ready;
                              //  A
  await dg.addEdge('A', 'X'); //  ├── X
  await dg.addEdge('A', 'Y'); //  ├── Y
  await dg.addEdge('A', 'Z'); //  └── Z

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

  await dg.size(); // 3
  await dg.edges(); // [['A', 'X'], ['A', 'Y'], ['A', 'Z']]
  await dg.sources(); // ['A']
  await dg.targets(); // ['X', 'Y', 'Z']
}

run();

Install

yarn add level-level-directed-graph-map

Usage

const level = require('level');
const LevelDirectedGraphMap = require('level-directed-graph-map');

const run = async () => {
  const db = level('./optional-db-path');
  const dgm = new LevelDirectedGraphMap(db, [['A', 'B']], { namespace: 'example' });
  await dgm.ready;

  //  A
  //  └── B
  
  await dgm.hasEdge('A', 'B'); // true
  
  await dgm.addEdge('B', 'C');
  
  //  A
  //  └── B
  //      └── C
  
  await  dgm.hasEdge('B', 'C'); // true
  await  dgm.getTargets('A'); // new Set(['B']);
  await  dgm.getTargets('B'); // new Set(['C']);
  await  dgm.getTargets('C'); // new Set();
  await  dgm.getSources('A'); // new Set();
  await  dgm.getSources('B'); // new Set(['A']);
  await  dgm.getSources('C'); // new Set(['B']);
  
  await  dgm.removeSource('A');
  
  //  B
  //  └── C
  
  await dgm.hasEdge('A', 'B'); // false
  await dgm.getTargets('A'); // new Set();
  
  await dgm.removeTarget('C');
  
  //  Empty
  
  await dgm.getTargets('B'); // new Set();
  await dgm.hasEdge('B', 'C'); // false
  
  await dgm.addEdge('A', 'B');
  
  //  A
  //  └── B
  
  await dgm.hasEdge('A', 'B'); // true
  
  await dgm.removeEdge('A', 'B');
  
  //  Empty
  
  await dgm.hasEdge('A', 'B'); // false
}

run();

API

Table of Contents

LevelDirectedGraphMap

Class representing a Level Directed Graph Map

Parameters

  • db Object? Object implementing the LevelUp interface
  • edges Iterable<[string, string]> Iterable containing source -> target pairs (optional, default [])
  • options Object Options object (optional, default {})

addEdge

Add an edge to the graph map.

Parameters

  • source string Source of the edge
  • target string Target of the edge

Returns Promise<void>

removeEdge

Remove an edge from the graph map.

Parameters

  • source string Source of the edge
  • target string Target of the edge

Returns Promise<void>

hasEdge

Test if a edge exists in the graph map.

Parameters

  • source string Source of the edge
  • target string Target of the edge

Returns Promise<boolean> Whether the edge exists in the graph map.

removeSource

Remove all edges from a source.

Parameters

  • source string Source of the edge

Returns Promise<void>

removeTarget

Remove all edges to a target.

Parameters

  • target string Target of the edge

Returns Promise<void>

hasSource

Test if a source exists in the graph map.

Parameters

  • source string Source of the edge

Returns Promise<boolean> Whether the source exists in the graph map.

hasTarget

Test if a target exists in the graph map.

Parameters

  • target string Target of the edge

Returns Promise<boolean> Whether the target exists in the graph map.

getSources

Get all sources with edges to a target.

Parameters

  • target string Target of the edge

Returns Promise<Set<string>> Set of sources

getTargets

Get all targets with edges from a source.

Parameters

  • source string Source of the edge

Returns Promise<Set<string>> Set of targets

edges

Array of edges

Returns Promise<Array<[string, string]>>

size

Edge count. Costly operation, use sparingly.

Returns Promise<number>

sources

Set of sources

Returns Promise<Set<string>>

targets

Set of targets

Returns Promise<Set<string>>

LevelDirectedGraphMap#ready

Resolves when the map is initialized and ready for use