# @thi.ng/dgraph

> Type-agnostic directed acyclic graph (DAG) & graph operations

Latest version **2.1.213** (published 2026-09-01) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @thi.ng/dgraph
pnpm add @thi.ng/dgraph
yarn add @thi.ng/dgraph
bun add @thi.ng/dgraph
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.213 |
| Published | 2026-09-01 |
| First published | 2018-04-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 5 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Karsten Schmidt |
| Maintainers | thi.ng |
| Keywords | adjacency, dag, datastructure, dependency, graph, query, sort, topology, typescript |

## Links

- npm: https://www.npmjs.com/package/@thi.ng/dgraph
- Repository: https://codeberg.org/thi.ng/umbrella
- Homepage: https://thi.ng/dgraph
- Funding: https://github.com/sponsors/postspectacular
- npm.io page: https://npm.io/package/@thi.ng/dgraph

## Dependencies (5)

- [@thi.ng/api](https://npm.io/package/@thi.ng/api.md) ^8.12.28
- [@thi.ng/equiv](https://npm.io/package/@thi.ng/equiv.md) ^2.1.117
- [@thi.ng/errors](https://npm.io/package/@thi.ng/errors.md) ^2.6.17
- [@thi.ng/associative](https://npm.io/package/@thi.ng/associative.md) ^7.1.47
- [@thi.ng/transducers](https://npm.io/package/@thi.ng/transducers.md) ^9.7.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 2.1.213 (latest) — 2026-09-01
- 2.1.212 — 2026-08-25
- 2.1.211 — 2026-07-21
- 2.1.210 — 2026-07-02
- 2.1.209 — 2026-06-05
- 2.1.208 — 2026-05-23
- 2.1.207 — 2026-05-20
- 2.1.205 — 2026-05-11
- 2.1.204 — 2026-05-08
- 2.1.202 — 2026-04-26
- 2.1.201 — 2026-04-18
- 2.1.200 — 2026-04-02
- 2.1.199 — 2026-03-19
- 2.1.198 — 2026-03-11
- 2.1.197 — 2026-03-11
- … 349 more at https://npm.io/package/@thi.ng/dgraph/versions

## README

<!-- This file is generated - DO NOT EDIT! -->
<!-- Please see: https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#changes-to-readme-files -->
# ![@thi.ng/dgraph](https://codeberg.org/thi.ng/umbrella/media/branch/develop/assets/banners/thing-dgraph.svg?27398a04)

[![npm version](https://img.shields.io/npm/v/@thi.ng/dgraph.svg)](https://www.npmjs.com/package/@thi.ng/dgraph)
![npm downloads](https://img.shields.io/npm/dm/@thi.ng/dgraph.svg)
[![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)

> [!NOTE]

> This is one of 217 standalone projects. LLM-free, human-made and
> cared for software, maintained as part of the
> [@thi.ng/umbrella](https://codeberg.org/thi.ng/umbrella/) ecosystem and
> anti-framework.
>
> 🚀 Please help me to work full-time on these projects by [sponsoring
> me](https://codeberg.org/thi.ng/umbrella/src/branch/develop/CONTRIBUTING.md#donations).
> Thank you! ❤️

- [About](#about)
  - [Features](#features)
- [Status](#status)
- [Support packages](#support-packages)
- [Related packages](#related-packages)
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Usage examples](#usage-examples)
- [API](#api)
- [Authors](#authors)
- [License](#license)

## About

Type-agnostic directed acyclic graph (DAG), using
[@thi.ng/associative](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/associative)
maps & sets as backend.

Implementation based on [Stuart Sierra's Clojure version](https://github.com/stuartsierra/dependency).

### Features

- cycle detection
- accessors for direct & transitive dependencies / dependents
- topological sorting
- iterable (in topo order)

## Status

**STABLE** - used in production

[Search or submit any issues for this package](https://codeberg.org/thi.ng/umbrella/issues?q=%5Bdgraph%5D)

## Support packages

- [@thi.ng/dgraph-dot](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/dgraph-dot) - Customizable Graphviz DOT serialization for [@thi.ng/dgraph](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/dgraph)

## Related packages

- [@thi.ng/adjacency](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/adjacency) - Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs
- [@thi.ng/dot](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/dot) - Graphviz document abstraction & serialization to DOT format
- [@thi.ng/system](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/system) - Minimal and explicit dependency-injection & lifecycle container for stateful app components

## Installation

```bash
yarn add @thi.ng/dgraph
```

ESM import:

```ts
import * as dgr from "@thi.ng/dgraph";
```

Browser ESM import:

```html
<script type="module" src="https://esm.run/@thi.ng/dgraph"></script>
```

[JSDelivr documentation](https://www.jsdelivr.com/)

For Node.js REPL:

```js
const dgr = await import("@thi.ng/dgraph");
```

Package sizes (brotli'd, pre-treeshake): ESM: 866 bytes

## Dependencies

- [@thi.ng/api](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/api)
- [@thi.ng/associative](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/associative)
- [@thi.ng/equiv](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/equiv)
- [@thi.ng/errors](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors)
- [@thi.ng/transducers](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/transducers)

Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)

## Usage examples

One project in this repo's
[/examples](https://codeberg.org/thi.ng/umbrella/src/branch/develop/examples)
directory is using this package:

| Screenshot                                                                                                           | Description                              | Live demo | Source                                                                                   |
|:---------------------------------------------------------------------------------------------------------------------|:-----------------------------------------|:----------|:-----------------------------------------------------------------------------------------|
| <img src="https://codeberg.org/thi.ng/umbrella/media/branch/develop/assets/examples/package-stats.png" width="240"/> | CLI util to visualize umbrella pkg stats |           | [Source](https://codeberg.org/thi.ng/umbrella/src/branch/develop/examples/package-stats) |

## API

[Generated API docs](https://docs.thi.ng/umbrella/dgraph/)

```ts
import { defDGraph } from "@thi.ng/dgraph";

g = defDGraph();

// add dependencies (order: a -> b)
g.addDependency([1, 2], [10, 20]);
g.addDependency([3, 4], [30, 40]);
g.addDependency([1, 2], [3, 4]);

// add isolated nodes
g.addNode([100, 200]);

g.sort();
// [[30, 40], [3, 4], [10, 20], [100, 200], [1, 2]]
```

## Authors

- [Karsten Schmidt](https://thi.ng)

If this project contributes to an academic publication, please cite it as:

```bibtex
@misc{thing-dgraph,
  title = "@thi.ng/dgraph",
  author = "Karsten Schmidt",
  note = "https://thi.ng/dgraph",
  year = 2015
}
```

## License

&copy; 2015 - 2026 Karsten Schmidt // Apache License 2.0

---
_Source: https://npm.io/package/@thi.ng/dgraph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
