toposort-extended
v1.0.1
Published
toposort with objects
Downloads
544
Maintainers
Readme
toposort-extended.js
toposort with objects
What it does
An extension of toposort where the inputs can be objects.
Current status
API is stable and tests cover all options. No known issues.
Usage
Main method
toposort(edges)
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
toposort.dependents(edges)
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' } ]
Changelog
See changelog.md
Tests
Use npm test
to run the tests. Use npm run cover
to check coverage.
Issues
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/toposort-extended/issues
Contribution
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