A JavaScript library to manage Chess Tournaments


chesstournament.js is a JavaScript library to manage chess tournaments.

Note: As this library is under development, it has not been published on npm yet.

You can use this library in node.js as well as natively in your favorite browser. For node.js simply install it using npm:

npm install chesstournament

For browser usage:

<script src="chesstournament.js"></script>
var Tournament = require('chesstournament');
var Player     = Tournament.Player;
var Team       = Tournament.Team;

var type       = 'team';                // either 'individual' or 'team'
var tournament = new Tournament(type);

var team = new Team('Chess Club One');  // create a new Team
tournament.teams.add(team);             //   and register it
team.players.add(new Player('Falco'));  // add some
team.players.add(new Player('Jacob'));  //   nice team mates

// or simply import a SWT file by the chesstournament-SWT-support plugin
Tournament.from('my/tournament.SWT', function(err, importedTournament) {

chesstournament.js provides an easy way to bind import and export plugins. You can simply register such a plugin to your Tournament module:

// import plugin

// export plugin'my-export-handler'));

The so registered plugins can be used via Tournament.from() and

// input can be everything the import plugin supports, for example
//   a filename or the content itself
Tournament.from('your input here', handleImportedTournament);

function handleImportedTournament(err, tournament) {
  // do what you want
  // for example export it to another format, handleExportedTournament);
  // alternatively use, options, handleExportedTournament);

function handleExportedTournament(err, export) {

There is currently only one userland plugin to import existing tournaments from Swiss-Chess Tournament (SWT) files. This list will get updated once there are more plugins:

A plugin which provides both import and export functionalities is specified by an object of the following form:

  // Name of this format, so a direct call Tournament.from[name] is
  //   possible, e.g. Tournament.from.CTX('your CTX data', handleTournament);
  name: 'CTX',

  // Function to determine if this importer should be used, depending
  //   on the content, which might also be a filename.
  determine: function determineFunction(content) { return true; }

  // Function to import this format. Keep in mind, that content might
  //   also be a filename.
  import: function importFunction(content, callback) { callback(err, tournament); }

  // Function to export into this format.
  export: function exportFunction(tournament, options, callback) { callback(err, exported); }

If only the import attribute is specified, it is an import plugin. Same applies to export.

Import as well as export plugins can also be registered directly by assigning it to the Tournament.from and objects:

// register import plugin
Tournament.from.myFormat = function importFunction(content, callback) { callback(err, tournament); };
// necessary if you also want to use the shortcut Tournament.from()
Tournament.from.myFormat.determine = function determineFunction(content) { return true; };

// register export plugin = function exportFunction(tournament, options, callback) { callback(err, exported); };