Skip to content

chanwutk/u-toposort

Repository files navigation

Universal Topological Sort

Supports both JavaScript/TypeScript and HTML imports

JavaScript/TypeScript import example

installation

npm install u-toposort

Using import

import toposort from 'u-toposort';

const edges: [number, number][] = [
  [1, 2],
  [2, 3],
];

console.log(toposort(edges));
// [1, 2, 3]

Using require

const toposort = require('u-toposort');

const edges: [string, string][] = [
  ['1', '2'],
  ['2', '3'],
];

console.log(toposort(edges));
// ['1', '2', '3']

HTML import example

<html lang="en">
  <head>
    <script src="https://cdn.jsdelivr.net/npm/u-toposort/build/toposort.min.js"></script>
  </head>
  <body>
    <script>
      console.log(
        toposort([
          [1, 2],
          [2, 3],
        ]),
      );
    </script>
  </body>
</html>

API

this module only export toposort function (and as default). Here is its function signature:

function toposort<N>(edges: [N, N][]): N[];

Reference

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published