Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
toposort-class
Advanced tools
Readme
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?
There are a few ways for installing Toposort. Here are them:
npm install toposort-class
bower install toposort
git clone git://github.com/gustavohenke/toposort.git
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:
jQuery
, jQuery UI Core
, jQuery UI Widget
, jQuery UI Button
, Underscore
, Backbone
, Plugin
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.
*/
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
.
.add(item, deps)
item
- The name of the dependent item that is being addeddeps
- A dependency or list of dependencies of item
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
FAQs
Topological sort of directed acyclic graphs (like dependecy lists)
The npm package toposort-class receives a total of 1,517,557 weekly downloads. As such, toposort-class popularity was classified as popular.
We found that toposort-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.