Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 605 Bytes

README.md

File metadata and controls

28 lines (22 loc) · 605 Bytes

Deno DAG 🦕

A Directed Asyclic Graph (DAG) resolver for Deno

Based on Kahn's algorithm for topographical sorting.

Setup

import { topographicalSort } from "https://deno.land/x/dag/mod.ts";

//         A
//        / \
//       B   C
//        \ /
//         D
const targets = [
  { name: "D" },
  { name: "A", dependencies: ["B", "C"] },
  { name: "C", dependencies: ["D"] },
  { name: "B", dependencies: ["D"] },
];

const sorted = topographicalSort(targets);
console.log(sorted.map(({ name }) => name)); // A,B,C,D