Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

toposort-class

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toposort-class - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.travis.yml

63

index.js

@@ -26,19 +26,18 @@ /**

*/
this.add = function(item, deps) {
if (typeof item !== "string" || !item) {
this.add = function( item, deps ) {
if ( typeof item !== "string" || !item ) {
throw new TypeError("Dependent name must be given as a not empty string");
}
if (deps) {
var tmp = Array.isArray(deps) ? deps : [deps];
tmp.forEach(function(dep) {
if (typeof dep !== "string" || !dep) {
if ( deps ) {
var tmp = Array.isArray( deps ) ? deps.slice() : [ deps ];
tmp.forEach(function( dep ) {
if ( typeof dep !== "string" || !dep ) {
throw new TypeError("Dependency name must be given as a not empty string");
}
edges.push( [ item, dep ] );
});
tmp.unshift(item);
edges.push(tmp);
} else {
edges.push([item]);
edges.push( [ item ] );
}

@@ -59,6 +58,6 @@

edges.forEach(function(edge) {
edge.forEach(function(n) {
if (nodes.indexOf(n) === -1) {
nodes.push(n);
edges.forEach(function( edge ) {
edge.forEach(function( n ) {
if ( nodes.indexOf( n ) === -1 ) {
nodes.push( n );
}

@@ -68,34 +67,34 @@ });

function visit(node, predecessors, i) {
if (!predecessors) {
predecessors = [];
} else if (predecessors.indexOf(node) > 0) {
throw new Error(require('util').format("Cyclic dependency found. '%s' is dependent of itself.", node));
function visit( node, predecessors, i ) {
predecessors = predecessors || [];
if ( predecessors.indexOf( node ) > -1 ) {
throw new Error( require("util").format( "Cyclic dependency found. '%s' is dependent of itself.", node ) );
}
var index = nodes.indexOf(node);
if (index === -1) {
var index = nodes.indexOf( node );
if ( index === -1 ) {
return i;
}
nodes.splice(index, 1);
if (predecessors.length === 0) {
nodes.splice( index, 1 );
if ( predecessors.length === 0 ) {
i--;
}
var predsCopy = predecessors.slice(0);
predsCopy.push(node);
var predsCopy = predecessors.slice();
predsCopy.push( node );
edges.filter(function(e) {
return e[0] === node;
}).forEach(function(e) {
i = visit(e[1], predsCopy, i);
edges.filter(function( e ) {
return e[ 0 ] === node;
}).forEach(function( e ) {
i = visit( e[ 1 ], predsCopy, i );
});
sorted.unshift(node);
sorted.unshift( node );
return i;
}
for (var i = 0; i < nodes.length; i++) {
i = visit(nodes[i], null, i);
for ( var i = 0; i < nodes.length; i++ ) {
i = visit( nodes[ i ], null, i );
}

@@ -102,0 +101,0 @@

{
"name": "toposort-class",
"version": "0.1.2",
"version": "0.1.3",
"description": "Topological sort of directed acyclic graphs (like dependecy lists)",
"main": "index.js",
"devDependencies": {
"vows": "*"
},
"scripts": {
"test": "vows --spec test.js"
},
"repository": {

@@ -7,0 +13,0 @@ "type": "git",

@@ -23,3 +23,3 @@ # Toposort

```javascript
var Toposort = require('./index'),
var Toposort = require('toposort-class'),
t = new Toposort();

@@ -26,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc