/ archiveofbelonging.org / back / node_modules / toposort-class /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]benchmark/2 years ago -  
[DIR]build/2 years ago -  
[   ]LICENSE10 years ago1.1K7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك]
[TXT]README.md10 years ago3.0Kf12eb36 documentaiton updates [كارل مبارك]
[   ]index.js10 years ago 51  
[   ]package.json2 years ago1.9K7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك]
README.md

Toposort

Build Status Dependency Status

Sorting directed acyclic graphs, for Node.js, io.js and the browser This was originally done by Marcel Klehr. Why not checkout his original repo?

Installation

There are a few ways for installing Toposort. Here are them:

Example

Let's say you have the following dependency graph:

Now, how would you sort this in a way that each asset will be correctly placed? You'll probably need the following sorting:

You can achieve it with the following code, using toposort-class:

var Toposort = require('toposort-class'),
    t = new Toposort();

t.add("jquery-ui-core", "jquery")
 .add("jquery-ui-widget", "jquery")
 .add("jquery-ui-button", ["jquery-ui-core", "jquery-ui-widget"])
 .add("plugin", ["backbone", "jquery-ui-button"])
 .add("backbone", ["underscore", "jquery"]);

console.log(t.sort().reverse());

/* Will output:
 * ['jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button', 'underscore', 'backbone', 'plugin']
 *
 * And you're done.
 */

Usage

CommonJS (Node.js and io.js):

var Toposort = require('toposort-class'),
    t = new Toposort();

Browser with AMD:

define("myModule", ["Toposort"], function(Toposort) {
    var t = new Toposort();
});

Browser without AMD:

var t = new window.Toposort();

or whatever global object there is instead of window.

API

.add(item, deps)

Returns: {Toposort} The Toposort instance, for chaining.

.sort()

Returns: {Array} The list of dependencies topologically sorted.

This method will check for cyclic dependencies, like "A is dependent of A".

.clear()

Returns: {Toposort} The Toposort instance, for chaining.

Clears all edges, effectively resetting the instance.

.Toposort

Reference to the Toposort constructor.

MIT License

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80