npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chesstournament

v0.0.1

Published

A JavaScript library to manage Chess Tournaments

Downloads

11

Readme

chesstournament.js

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.

Installation

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>

Quick Start

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.use(require('chesstournament-SWT-support'));
Tournament.from('my/tournament.SWT', function(err, importedTournament) {
  console.log(importedTournament.rounds.length);
});

Import & Export

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
Tournament.from.use(require('my-import-handler'));

// export plugin
Tournament.to.use(require('my-export-handler'));

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

// 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
  tournament.to.myRegisteredExport(options, handleExportedTournament);
  
  // alternatively use
  Tournament.to.myRegisteredExport(tournament, options, handleExportedTournament);
}

function handleExportedTournament(err, export) {
  console.log(export);
}

Existing Import/Export Plugins

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:

Write your own plugin

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 Tournament.to 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
Tournament.to.myFormat = function exportFunction(tournament, options, callback) { callback(err, exported); };