Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@hapi/topo
Advanced tools
Package description
The @hapi/topo package is designed for managing dependencies and ordering items in a flexible way. It allows you to specify prerequisites for items and automatically sorts them based on these dependencies. This is particularly useful in scenarios where the order of operations is crucial, such as initializing plugins or tasks in a specific sequence.
Adding items with dependencies
This feature allows you to add items to a Topo instance with specified dependencies. In the code sample, 'first' depends on 'second', so 'second' will come before 'first' in the output order.
{"const Topo = require('@hapi/topo');
const topo = new Topo();
topo.add('first', { after: ['second'], group: 'a' });
topo.add('second', { group: 'b' });
console.log(topo.nodes); // Output will be in the order of dependencies, ['second', 'first']"}
Grouping and ordering
This feature demonstrates how to group items and ensure they are processed in a specific order based on their group dependencies. Items can be added in groups and ordered relative to other groups.
{"const Topo = require('@hapi/topo');
const topo = new Topo();
topo.add(['first', 'second'], { group: 'a' });
topo.add('third', { group: 'b', after: ['a'] });
console.log(topo.nodes); // Output will respect the group order and dependencies, ['first', 'second', 'third']"}
dag-map is a simple DAG (Directed Acyclic Graph) implementation for JavaScript. Similar to @hapi/topo, it allows for specifying dependencies between items and ensures they are processed in order. However, dag-map focuses more on the DAG structure itself, without the specific grouping features that @hapi/topo provides.
dependency-graph is another package that allows for managing dependencies between items in a graph structure. It provides functionality to add nodes and dependencies, and then sort or retrieve them in an order that respects their dependencies. Compared to @hapi/topo, dependency-graph offers a more detailed API for manipulating and querying the graph, but it might be more complex to use for simple ordering tasks.
Readme
topo is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi – they work even better together.
FAQs
Topological sorting with grouping support
The npm package @hapi/topo receives a total of 8,789,471 weekly downloads. As such, @hapi/topo popularity was classified as popular.
We found that @hapi/topo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
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.