u-toposort
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i u-toposort

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

7.7 kB

Total Files

10

Last publish

Collaborators

  • chanwutk