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

toposort

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toposort - npm Package Compare versions

Comparing version 0.2.5 to 0.2.7

component.json

58

index.js

@@ -45,30 +45,32 @@ /*!

for (var i=0; i < nodes.length; i++) {
(function visit(node, predecessors) {
if (!predecessors) predecessors = []
else // The node is a dependency of itself?! I'd say, we're free to throw
if(predecessors.indexOf(node) > 0)
throw new Error('Cyclic dependency! The following node is a dependency of itself: '+JSON.stringify(node))
// if it's not in nodes[] anymore, we've already had this node
if (nodes.indexOf(node) < 0) return;
// remove this node from nodes[]
nodes.splice(nodes.indexOf(node), 1)
if (predecessors.length == 0) i--;
var predsCopy = predecessors.map(function(n) {return n})
predsCopy.push(node)
edges
.filter(function(e) { return e[0] === node })
.forEach(function(e) {
// visit all dependencies of this node
// and provide them with a *copy* of their predecessors (including *this* node)
visit(e[1], predsCopy)
})
sorted.unshift(node)
})(nodes[i])
}
while (nodes.length > 0)
visit(nodes[0], null, edges, nodes, sorted)
return sorted;
}
}
function visit(node, predecessors, edges, nodes, sorted) {
if (!predecessors) predecessors = []
else // The node is a dependency of itself?! I'd say, we're free to throw
if(predecessors.indexOf(node) > 0)
throw new Error('Cyclic dependency! The following node is a dependency of itself: '+JSON.stringify(node))
// if it's not in nodes[] anymore, we've already had this node
if (nodes.indexOf(node) < 0) return;
// remove this node from nodes[]
nodes.splice(nodes.indexOf(node), 1)
var predsCopy = predecessors.map(function(n) {return n})
predsCopy.push(node)
edges
.filter(function(e) { return e[0] === node })
.forEach(function(e) {
// visit all dependencies of this node
// and provide them with a *copy* of their predecessors (including *this* node)
visit(e[1], predsCopy, edges, nodes, sorted)
})
sorted.unshift(node)
}
{
"name": "toposort",
"version": "0.2.5",
"version": "0.2.7",
"description": "Topological sort of directed ascyclic graphs (like dependecy lists)",

@@ -11,3 +11,3 @@ "main": "index.js",

"type": "git",
"url": "https://github.com/marcelklehr/node-toposort.git"
"url": "https://github.com/marcelklehr/toposort.git"
},

@@ -14,0 +14,0 @@ "devDependencies": {

# Sorting directed acyclic graphs
[![Build Status](https://travis-ci.org/marcelklehr/node-toposort.png)](https://travis-ci.org/marcelklehr/node-toposort)
[![Build Status](https://travis-ci.org/marcelklehr/toposort.png)](https://travis-ci.org/marcelklehr/toposort)
## Installation
`npm install toposort`
`npm install toposort` or `component install toposort`

@@ -7,0 +7,0 @@ ## Example

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