Note: This package is now located in the bracketclub/bracketclub monorepo.
Validate a tournament bracket.
To see the data this repo is built on, check out bracket-data.
bracket-validator
is a module that takes a string representation of a bracket and validates it against the real data for that bracket's sport and year.
The main use case for this is to validate a user's entry against the actual data in order to score it or display it showing correct/incorrect picks. There are other modules which rely on bracket-validator
such as bracket-scorer
and bracket-updater
.
Make a new bracket-validator
object with an options object (the year and sport options are required and passed directly to bracket-data
):
var BracketValidator = require('bracket-validator');
var validator = new BracketValidator({
year: '2013',
sport: 'ncaam',
/* User bracket string */
flatBracket: 'MW1812463XXXXXXXXXW19XX614XXXXXXXXXSXX54XXXXXXXXXXXEXX12463XXXXXXXXXFFXXX'
});
console.log(validator.validate());
sport
: The sport you are validating. Seebracket-data
for more info.year
: The year you are validating. Seebracket-data
for more info.testOnly
: (Boolean, default: false) Whether to only test the validation and not return an expanded bracketallowEmpty
: (Boolean, default: true) Whether the validation should allow unpicked matches. This is useful for validating a bracket as a user is selecting it.flatBracket
: (String, default: '') The user's bracket to validate
validate(flatBracket)
: Validate the bracket. The paramflatBracket
is optional here. If you pass it in, it will callreset
first and then validate, otherwise it will use the option it was instantiated with. It will return one of the following:- An
Error
with themessage
set to why the validation failed - The
flatBracket
if validation is successfull andtestOnly
is set totrue
- An expanded bracket object created from
flatBracket
if validation is successful. It will have each region containing a multidimensional array:rounds
. This is ordered by round and picks, where if a pick is made it will contain the teamseed
andname
and if a pick is not made it will benull
.
- An
reset(flatBracket)
: Reset the validator to use a newflatBracket
.
If this is interesting to you, I think you should follow me (@lukekarrys) and @tweetthebracket on Twitter. There are also a lot of other bracket related modules on our GitHub organization page.