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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tournament-pairings

v2.0.1

Published

Functions to generate pairings for tournaments

Readme

Tournament Pairings

Node.js package containing functions to generate tournament pairings.

If you want a full-fledged package for organizing tournaments, consider tournament-organizer.

Algorithms

Double elimination: avoids rematches in the loser's bracket by alternating how matches are routed.

Round-robin: players are paired via Berger tables.

Swiss: generated using a weighted blossom algorithm with maximum cardinality.

Swiss Pairings

  • Players are preferred to play against other players with equal point totals
  • If there are an odd number of players, players with the lowest point total who have not previously received a bye are preferred to receive the bye
  • If the tournament is rated, players are preferred to play other players with similar ratings
  • If the seating in a tournament is relevant, such as white and black in chess, players are preferred to play the opposite seat than last played and strongly preferred to not play the same seat more than two times consecutively

Requirements

This is an ESM module. You will need to use import instead of require and add type: "module" to your package.json.

Discussion

You can discuss this repository more in my Discord.

Documentation

Installation

npm i tournament-pairings

Importing

Named imports:

import {
    SingleElimination,
    DoubleElimination,
    RoundRobin,
    Stepladder,
    Swiss
} from 'tournament-pairings'

Namespace import:

import * as Pairings from 'tournament-pairings'

Interfaces for TypeScript:

import {
    Match,
    Player
} from 'tournament-pairings/interfaces'

Functions

Single elimination:

SingleElimination(
    players: Number | Array<String>,
    startingRound: Number = 1,
    consolation: Boolean = false,
    ordered: Boolean = false
): Array<Match>

Double elimination:

DoubleElimination(
    players: Number | Array<String>,
    startingRound: Number = 1,
    ordered: Boolean = false
): Array<Match>

Round-robin:

RoundRobin(
    players: Number | Array<String>,
    startingRound: Number = 1,
    ordered: Boolean = false
): Array<Match>

Stepladder:

Stepladder(
    players: Number | Array<String>,
    startingRound: Number = 1,
    ordered: Boolean = true
): Array<Match>

Swiss:

Swiss(
    players: Array<Player>,
    round: Number,
    rated: Boolean = false,
    seating: Boolean = false
): Array<Match>

Player {
    id: String | Number,
    score: Number,
    pairedUpDown?: Boolean,
    receivedBye? : Boolean,
    avoid?: Array<String | Number>,
    seating?: Array<-1 | 1>,
    rating?: Number | null
}

Notes on Parameters

players: if provided a number n (except for Swiss), then players are array of numbers from 1 to n.

consolation: if there is an additional match in the final round to determine third place.

ordered: if the array provided for players is ordered.

rated: if the players have a rating to be considered for pairing.

seating: if the seating of the players needs to be considered.

Notes on Player Interface

pairedUpDown: if the player has been paired with someone outside their point group in a prior round.

receivedBye: if the player was unpaired in a prior round.

avoid: an array of IDs representing prior opponents of the player.

seating: an array of either 1 or -1 to represent seating. The most obvious example is playing white or black in chess.

Return Value

Each function returns an Array<Match>.

Match {
    round: number,
    match: number,
    player1: string | number | null,
    player2: string | number | null,
    win?: {
        round: number,
        match: number
    },
    loss?: {
        round: number,
        match: number
    }
}

The Swiss function returns matches for the given round, while all other functions return matches for the entire tournament.