Topological sorting with grouping support.
The Topo
object is the container for topologically sorting a list of nodes with non-circular interdependencies.
const Topo = require('@hapi/topo');
const morning = new Topo.Sorter();
morning.add('Nap', { after: ['breakfast', 'prep'] });
morning.add([
'Make toast',
'Pour juice'
], { before: 'breakfast', group: 'prep' });
morning.add('Eat breakfast', { group: 'breakfast' });
morning.nodes; // ['Make toast', 'Pour juice', 'Eat breakfast', 'Nap']