Parse Swiss-Manager .TUNX binary tournament
files. Zero dependencies, strict TypeScript. Output types align with
@echecs/trf.
npm install @echecs/tunx
import { parse } from '@echecs/tunx';
import { readFileSync } from 'node:fs';
// Parse a TUNX file
const buffer = new Uint8Array(readFileSync('tournament.TUNX'));
const tournament = parse(buffer);
if (tournament) {
console.log(tournament.name); // "IV Elllobregat Open Chess Tmnt Grupo A"
console.log(tournament.rounds); // 9
console.log(tournament.players.length); // 210
// Player data
const player = tournament.players[0];
console.log(player.name); // "Fedoseev, Vladimir"
console.log(player.rating); // 2675
console.log(player.fideId); // "24130737"
console.log(player.title); // "GM"
console.log(player.points); // 6.5
console.log(player.rank); // 1
}
parse(input, options?)Decode a TUNX binary buffer into a Tournament object.
function parse(
input: Uint8Array,
options?: ParseOptions,
): Tournament | undefined;
undefined for unrecoverable failures (bad magic, missing markers).options.onError before returning undefined.options.onWarning for recoverable issues — parsing continues.ParseOptionsinterface ParseOptions {
onError?: (error: ParseError) => void;
onWarning?: (warning: ParseWarning) => void;
}
ParseErrorinterface ParseError {
message: string;
offset?: number;
}
ParseWarninginterface ParseWarning {
message: string;
offset?: number;
}
Output types are compatible with
@echecs/trf.
Tournamentinterface Tournament {
// TRF-compatible fields
chiefArbiter?: string;
city?: string;
deputyArbiters?: string[];
endDate?: string;
federation?: string;
name?: string;
numberOfPlayers?: number;
players: Player[];
roundDates?: string[];
rounds: number;
startDate?: string;
tiebreaks?: string[];
timeControl?: string;
tournamentType?: string;
// TUNX-specific extensions
currentRound?: number;
header?: Header;
pairings?: Pairing[][];
roundTimes?: string[];
subtitle?: string;
venue?: string;
}
Playerinterface Player {
birthDate?: string;
federation?: string;
fideId?: string;
name: string;
nationalRatings?: NationalRating[];
pairingNumber: number;
points: number;
rank: number;
rating?: number;
results: RoundResult[];
sex?: Sex;
title?: Title;
}
RoundResultinterface RoundResult {
color: '-' | 'b' | 'w';
opponentId: number | null;
result: ResultCode;
round: number;
}
PairingPer-board pairing record, grouped by round in Tournament.pairings.
interface Pairing {
black: number;
board: number;
result?: ResultCode;
white: number;
}
HeaderTUNX-specific header metadata. Available on Tournament.header.
interface Header {
installSignature: Uint8Array;
installedAt?: Date;
licenseHash: Uint8Array;
savedAt?: Date;
tournamentId: number;
}
NationalRatinginterface NationalRating {
birthDate?: string;
classification?: string;
federation: string;
name?: string;
nationalId?: string;
origin?: string;
pairingNumber: number;
rating: number;
sex?: Sex;
}
ResultCodetype ResultCode =
| '+'
| '-'
| '0'
| '1'
| '='
| 'D'
| 'F'
| 'H'
| 'L'
| 'U'
| 'W'
| 'Z';
| Code | Meaning |
|---|---|
1 |
Win |
0 |
Loss |
= |
Draw |
+ |
Forfeit win |
- |
Forfeit loss |
D |
Draw by forfeit |
F |
Full-point bye |
H |
Half-point bye |
L |
Loss by forfeit (special) |
W |
Win by forfeit (special) |
Z |
Zero-point bye / unpaired |
U |
Unplayed |
Sextype Sex = 'm' | 'w';
TiebreakKnown tiebreak identifiers used as values in Tournament.tiebreaks.
type Tiebreak =
| 'average-rating'
| 'buchholz'
| 'buchholz-cut-1'
| 'buchholz-cut-2'
| 'buchholz-cut-3'
| 'direct-encounter'
| 'koya'
| 'median-buchholz'
| 'number-of-wins'
| 'performance-rating'
| 'progressive'
| 'sonneborn-berger';
Titletype Title = 'CM' | 'FM' | 'GM' | 'IM' | 'WCM' | 'WFM' | 'WGM' | 'WIM';
TUNX is the proprietary binary format used by Swiss-Manager. The format uses little-endian integers and UTF-16LE strings with U16LE length prefixes.
93 FF 89 44, tournament ID, license data95 FF 89 44) — rounds, players, dates, tiebreaksA3 FF 89 44) — per-round schedule (dates, times)A5 FF 89 44) — 30 strings + 110-byte numeric blockB3 FF 89 44) — 21-byte records per pairingD3 FF 89 44) — section offset tableE3 FF 89 44) — file terminatorMIT