An extension of toposort where the inputs can be objects.
API is stable and tests cover all options. No known issues.
var toposort = require('toposort-extended');
sorted = toposort( [
[ { table: 'Ingredient' }, { table: 'Shop' } ],
[ { table: 'Food' }, { table: 'Ingredient' } ]
] );
// sorted = [ { table: 'Food' }, { table: 'Ingredient' }, { table: 'Shop' } ]
Exactly the same as original toposort, except:
- Inputs are converted to JSON before ordering so objects can be used as input
- Cyclic dependency errors are thrown as custom class
toposort.Error
with the source of the error passed asedge
Same as toposort(edges)
except that items which are not dependent on any other item are excluded from the returned array.
sorted = toposort.dependents( [
[ { table: 'Ingredient' }, { table: 'Shop' } ],
[ { table: 'Food' }, { table: 'Ingredient' } ]
] );
// sorted = [ { table: 'Food' }, { table: 'Ingredient' } ]
See changelog.md
Use npm test
to run the tests. Use npm run cover
to check coverage.
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/toposort-extended/issues
Pull requests are very welcome. Please:
- ensure all tests pass before submitting PR
- add an entry to changelog
- add tests for new features
- document new functionality/API additions in README