toposort-extended

toposort with objects

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
toposort-extended
1.0.19 years ago9 years agoMinified + gzip package size for toposort-extended in KB

Readme

toposort-extended.js
toposort with objects

What it does

An extension of toposort where the inputs can be objects.

Current status

NPM version Build Status Dependency Status Dev dependency Status Coverage 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 as edge

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