Topological sort implemented in Javascript (ES2016)
API
const TopologicalSort = require('topological-sort');
const nodes = new Map();
nodes.set('variables', variablesObj);
nodes.set('mixins', mixinsObj);
const sortOp = new TopologicalSort(nodes);
sortOp.addNode('block', blocksObj);
sortOp.addNodes(new Map([
['block_mod_val1', blockModObj1],
['block_mod_val2', blockModObj2]
]));
sortOp.addEdge('variables', 'mixins');
sortOp.addEdge('mixins', 'block');
sortOp.addEdge('variables', 'block');
sortOp.addEdge('block', 'block_mod_val2');
sortOp.addEdge('block', 'block_mod_val1');
const sorted = sortOp.sort();
const sortedKeys = [...res.keys()];
More info: