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

topo

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

topo

Topological sorting with grouping support

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
587K
decreased by-17.37%
Maintainers
1
Weekly downloads
 
Created

What is topo?

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.

What are topo's main functionalities?

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);
}

Other packages similar to topo

Keywords

FAQs

Package last updated on 03 Aug 2014

Did you know?

Socket

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.

Install

Related posts

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