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

glicko-ts

v1.0.3

Published

A TypeScript implementation of the Glicko-1 rating system.

Downloads

69

Readme

Glicko-ts

glicko-ts is a TypeScript implementation of the Glicko-1 rating system, developed by Mark Glickman. It's a popular algorithm for calculating the relative skill levels of players in competitive games, improving upon simpler systems by incorporating rating reliability. This library provides an easy-to-use interface for integrating Glicko-1 ratings into your applications.

License: MIT

Features

  • Implementation of the Glicko-1 rating algorithm in TypeScript.
  • Calculates updated Ratings and Rating Deviations (RD) based on match outcomes.
  • Handles player inactivity via configurable RD increase over time.
  • Configurable system parameters (initial values, inactivity constant, RD ceiling, etc.).
  • Provides clear type definitions for easy integration.
  • Lightweight with zero external dependencies.

Installation

Install the package via npm:

npm install glicko-ts

Usage

Here's a quick example of how to use GlickoTS:

import { Glicko, Player, Match } from 'glicko-ts'; // Adjust path if necessary

// 1. Initialize the Glicko calculator (using default or custom config)
const glicko = new Glicko();

// 2. Get player states *before* the rating period begins
// (Assuming these were loaded from your database or previous calculations)
let playerA: Player = glicko.initializeNewPlayer({ rating: 1500, rd: 200, lastPlayedMatch: new Date(Date.now() - 60 * 24 * 60 * 60 * 1000) }); // Example existing player
let playerB: Player = glicko.initializeNewPlayer({ rating: 1700, rd: 150, lastPlayedMatch: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000) }); // Example existing player
let playerC: Player = glicko.initializeNewPlayer(); // New player this period

console.log('Initial Player A:', playerA);
console.log('Initial Player B:', playerB);
console.log('Initial Player C:', playerC);

// 3. Define matches played *during* this rating period
// Note: The 'score' is always from the perspective of the 'player' in the Match object.
// A single game between A and B results in two Match objects, one for each player's perspective.

// Assume Player A beat Player C (Score 1 for A, Score 0 for C)
const matchA_vs_C: Match = { player: playerA, opponent: playerC, score: 1 };
const matchC_vs_A: Match = { player: playerC, opponent: playerA, score: 0 };

// Assume Player B lost to Player A (Score 0 for B, Score 1 for A - from another match perspective not shown here)
const matchB_vs_A: Match = { player: playerB, opponent: playerA, score: 0 };
// Assume Player B beat Player C (Score 1 for B, Score 0 for C)
const matchB_vs_C: Match = { player: playerB, opponent: playerC, score: 1 };
const matchC_vs_B: Match = { player: playerC, opponent: playerB, score: 0 };


// 4. Collate matches for each player for this period
const matchesForPlayerA = [matchA_vs_C]; // Add other matches A played here
const matchesForPlayerB = [matchB_vs_A, matchB_vs_C]; // Add other matches B played here
const matchesForPlayerC = [matchC_vs_A, matchC_vs_B]; // Add other matches C played here


// 5. Calculate inactivity days for each player (time between their last update and the *start* of this period)
// (This calculation depends on your application's tracking of period start/end times)
const daysInactiveA = 60; // Example
const daysInactiveB = 90; // Example
const daysInactiveC = 0;  // New player, no prior inactivity


// 6. Process results for each player
// This is the standard way: process inactivity and matches in one call.
const updatedPlayerA = glicko.processGameResults(playerA, matchesForPlayerA, daysInactiveA);
const updatedPlayerB = glicko.processGameResults(playerB, matchesForPlayerB, daysInactiveB);
const updatedPlayerC = glicko.processGameResults(playerC, matchesForPlayerC, daysInactiveC); // daysInactiveC is 0, so no inactivity applied


// 7. Store the updated player states for the next rating period
console.log('Updated Player A:', updatedPlayerA);
console.log('Updated Player B:', updatedPlayerB);
console.log('Updated Player C:', updatedPlayerC);

/*
// Alternative Usage Patterns:

// A) Manually applying inactivity first:
const inactivePlayer = glicko.updateRDForInactivity(player, daysInactive);
const updatedPlayer = glicko.processGameResults(inactivePlayer, matches); // Note: no daysInactive here

// B) Processing results without considering inactivity:
const updatedPlayerNoInactivity = glicko.processGameResults(player, matches);
*/

Configuration

You can customize the Glicko system by passing a configuration object to the Glicko constructor. The available configuration options are:

  • initialRating: The default rating for a new player (default: 1500).
  • initialRD: The rating deviation assigned to a new player (default: 350). Higher values reflect more uncertainty..
  • inactivityConstant: Controls the rate of RD increase during inactivity. Often denoted 'c' (default: 0.5). Needs tuning based on the specific game/skill.
  • rdCeiling: The maximum value the RD can reach through inactivity (default: 350). Cannot be lower than initialRD
  • q: The Glicko system constant $\ln(10)/400$ is calculated internally and not configurable.
  • daysPerRatingPeriod: The typical number of days in your rating cycle. Used to scale the inactivity calculation (default: 30).
  • roundingPrecision: The number of decimal places to round final ratings and RDs to (default: 2). Must be a non-negative integer.
import { Glicko } from 'glicko-ts'; // Adjust path if necessary
import { GlickoConfig } from 'glicko-ts'; // Adjust path if necessary

const customConfig: Partial<GlickoConfig> = {
  initialRating: 1000,         // Default: 1500
  initialRD: 250,              // Default: 350
  inactivityConstant: 0.4,     // Default: 0.5 - Controls how fast RD increases
  rdCeiling: 300,              // Default: 350 - Maximum RD value
  daysPerRatingPeriod: 7,      // Default: 30 - Used for inactivity calc scaling
  roundingPrecision: 0,        // Default: 2 - Decimal places for final results
};

const glickoWithCustomConfig = new Glicko(customConfig);
const newPlayer = glickoWithCustomConfig.initializeNewPlayer();
console.log('New player with custom config:', newPlayer); // Rating: 1000, RD: 250

Interfaces

interface Player {  
  rating: number;  
  rd: number;  
  lastPlayedMatch?: Date;  
}

interface Opponent {  
  rating: number;  
  rd: number;  
}

interface Match {  
  player: Player;  
  opponent: Opponent;  
  score: number;  
}

interface GlickoConfig {  
  initialRating: number;  
  initialRD: number;  
  inactivityConstant: number;  
  rdCeiling: number;  
  q: number;  
  daysPerRatingPeriod: number;
  roundingPrecision: number; 
}

License

MIT License

Copyright (c) [2025] [Bradley Robinson]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Acknowledgments

The Glicko(-1) rating system was developed by Mark Glickman. For more information, visit glicko.net.