Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
The 'topo' npm package is a module that provides a way to manage topological sorting of nodes with dependencies. It is useful for scenarios where you need to order items based on their dependencies, ensuring that each item appears after its dependencies have been processed.
Adding Nodes
This feature allows you to add nodes to the topo instance. Each node can be assigned to a group and can specify dependencies using the 'after' and 'before' options.
const Topo = require('topo');
const topo = new Topo();
topo.add('a', { group: 'group1' });
topo.add('b', { group: 'group2', after: ['group1'] });
console.log(topo.nodes);
Sorting Nodes
This feature sorts the nodes based on their dependencies. The 'sort' method returns an array of nodes in the correct order, ensuring that each node appears after its dependencies.
const Topo = require('topo');
const topo = new Topo();
topo.add('a', { group: 'group1' });
topo.add('b', { group: 'group2', after: ['group1'] });
topo.add('c', { group: 'group3', before: ['group2'] });
const sorted = topo.sort();
console.log(sorted);
Handling Cyclic Dependencies
This feature demonstrates how the topo package handles cyclic dependencies. If a cyclic dependency is detected, an error is thrown, preventing the sort operation from completing.
const Topo = require('topo');
const topo = new Topo();
topo.add('a', { group: 'group1' });
topo.add('b', { group: 'group2', after: ['group1'] });
topo.add('c', { group: 'group3', after: ['group2', 'group1'] });
topo.add('d', { group: 'group4', after: ['group3', 'group1'] });
try {
topo.add('e', { group: 'group5', after: ['group4', 'group1', 'group3'] });
topo.add('f', { group: 'group6', after: ['group5', 'group2'] });
const sorted = topo.sort();
console.log(sorted);
} catch (err) {
console.error('Cyclic dependency detected:', err.message);
}
The 'dependency-graph' package provides a similar functionality for managing and sorting dependencies. It allows you to create a directed graph of dependencies and sort them topologically. Compared to 'topo', 'dependency-graph' offers more flexibility in terms of graph manipulation and querying.
The 'graphlib' package is a general-purpose graph library that supports directed and undirected graphs. It includes algorithms for topological sorting, shortest paths, and more. While 'graphlib' is more comprehensive and versatile, 'topo' is more focused on topological sorting with a simpler API.
The 'toposort' package is a lightweight library specifically designed for topological sorting. It provides a straightforward API for adding nodes and dependencies and then sorting them. 'toposort' is simpler and more focused compared to 'topo', which offers additional features like grouping and handling cyclic dependencies.
Topological sorting with grouping support.
Lead Maintainer: Devin Ivy
var Topo = require('topo');
var topo = new Topo();
topo.add('Nap', { after: ['breakfast', 'prep'] });
topo.add([
'Make toast',
'Pour juice'
], { before: 'breakfast', group: 'prep' });
topo.add('Eat breakfast', { group: 'breakfast' });
topo.nodes; // ['Make toast', 'Pour juice', 'Eat breakfast', 'Nap']
Topo
The Topo
object is the container for topologically sorting a list of nodes with non-circular interdependencies.
new Topo()
Creates a new Topo
object.
topo.add(nodes, [options])
Specifies an additional node or list of nodes to be topologically sorted where:
nodes
- a mixed value or array of mixed values to be added as nodes to the topologically sorted list.options
- optional sorting information about the nodes
:
group
- a string naming the group to which nodes
should be assigned. The group name '?'
is reserved.before
- a string or array of strings specifying the groups that nodes
must precede in the topological sort.after
- a string or array of strings specifying the groups that nodes
must succeed in the topological sort.Returns an array of the topologically sorted nodes.
topo.nodes
An array of the topologically sorted nodes. This list is renewed upon each call to topo.add()
.
FAQs
Topological sorting with grouping support
The npm package topo receives a total of 513,413 weekly downloads. As such, topo popularity was classified as popular.
We found that topo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.