Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sha1n/dagraph
Directed acyclic graph utility in TypeScript
https://github.com/sha1n/dagraph
dag directed-acyclic-graph topological-sort typescript
Last synced: 13 days ago
JSON representation
Directed acyclic graph utility in TypeScript
- Host: GitHub
- URL: https://github.com/sha1n/dagraph
- Owner: sha1n
- License: mit
- Created: 2022-02-12T14:03:04.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-21T17:24:02.000Z (2 months ago)
- Last Synced: 2024-12-22T03:20:45.525Z (about 1 month ago)
- Topics: dag, directed-acyclic-graph, topological-sort, typescript
- Language: TypeScript
- Homepage:
- Size: 1.69 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![CI](https://github.com/sha1n/dagraph/actions/workflows/ci.yml/badge.svg)](https://github.com/sha1n/dagraph/actions/workflows/ci.yml)
[![Coverage](https://github.com/sha1n/dagraph/actions/workflows/coverage.yml/badge.svg)](https://github.com/sha1n/dagraph/actions/workflows/coverage.yml)
![GitHub](https://img.shields.io/github/license/sha1n/dagraph)
![npm type definitions](https://img.shields.io/npm/types/@sha1n/dagraph)
![npm](https://img.shields.io/npm/v/@sha1n/dagraph)# DAGraph
A direct acyclic graph implementation- [DAGraph](#dagraph)
- [Features](#features)
- [Usage](#usage)
- [Basic](#basic)
- [Custom Objects](#custom-objects)
- [Install](#install)## Features
- Hosts your data in the graph structure
- Topological sort traversal generator
- Traverse root nodes generator
- Reverse graph API## Usage
### Basic
```ts
import createDAG from '@sha1n/dagraph';const dag = createDAG();
dag.addNode({id : 'a'});
dag.addEdge({id : 'b'}, {id : 'a'});
dag.addEdge({id : 'c'}, {id : 'a'});
dag.addEdge({id : 'd'}, {id : 'b'});for (const node of dap.topologicalSort()) {
...
}
```### Custom Objects
```tstype MyThing = {
id: string; // <-- implicitly implements the 'Identifiable' interface
name: string;
doSomething(): void;
};const myThing = {
id: 'a',
name: 'my thing',
doSomething: () => {
console.log('A');
}
};const myOtherThing = {
id: 'b',
name: 'my other thing',
doSomething: () => {
console.log('B');
}
};const myDAG = createDAG();
myDAG.addEdge(myThing, myOtherThing);
```## Install
```bash
yarn install @sha1n/dagraph
``````bash
npm i @sha1n/dagraph
```