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

hospital-resident

v0.1.0

Published

Matching algorithms for stable marriage, hospital-resident, stable roommates, and student allocation problems

Readme

hospital-resident

Matching algorithms for stable marriage, hospital-resident, stable roommates, and student allocation problems.

A TypeScript/JavaScript port of the Python matching library.

Installation

npm install hospital-resident

Quick Start

Stable Marriage Problem

import { StableMarriage } from 'hospital-resident';

const game = StableMarriage.createFromDictionaries(
  {
    A: ['X', 'Y', 'Z'],
    B: ['Y', 'X', 'Z'],
    C: ['Y', 'Z', 'X'],
  },
  {
    X: ['B', 'A', 'C'],
    Y: ['A', 'B', 'C'],
    Z: ['A', 'B', 'C'],
  }
);

const matching = game.solve();
console.log(matching.toRecord());
// { A: 'Y', B: 'X', C: 'Z' }

Hospital-Resident Problem

import { HospitalResident } from 'hospital-resident';

const game = HospitalResident.createFromDictionaries(
  {
    A: ['CityHospital', 'Memorial'],
    B: ['Memorial', 'CityHospital'],
    C: ['CityHospital'],
  },
  {
    CityHospital: ['A', 'C', 'B'],
    Memorial: ['B', 'A'],
  },
  {
    CityHospital: 2,
    Memorial: 1,
  }
);

const matching = game.solve();
console.log(matching.toRecord());
// { CityHospital: ['A', 'C'], Memorial: ['B'] }

Stable Roommates Problem

import { StableRoommates } from 'hospital-resident';

const game = StableRoommates.createFromDictionary({
  A: ['B', 'C', 'D'],
  B: ['A', 'C', 'D'],
  C: ['A', 'B', 'D'],
  D: ['A', 'B', 'C'],
});

const matching = game.solve();
console.log(matching.toRecord());
// { A: 'B', B: 'A', C: 'D', D: 'C' }

Student Allocation Problem

import { StudentAllocation } from 'hospital-resident';

const game = StudentAllocation.createFromDictionaries(
  // Student preferences (over projects)
  {
    A: ['P1', 'P2'],
    B: ['P2', 'P1'],
    C: ['P1'],
  },
  // Supervisor preferences (over students)
  {
    S1: ['A', 'B', 'C'],
  },
  // Project -> Supervisor mapping
  { P1: 'S1', P2: 'S1' },
  // Project capacities
  { P1: 2, P2: 1 },
  // Supervisor capacities
  { S1: 3 }
);

const matching = game.solve();
console.log(matching.toRecord());
// { P1: ['A', 'C'], P2: ['B'] }

Features

  • Stable Marriage (SM): Gale-Shapley algorithm for bipartite 1:1 matching
  • Hospital-Resident (HR): Many-to-one matching with capacities
  • Stable Roommates (SR): Irving's algorithm for symmetric 1:1 matching
  • Student Allocation (SA): Two-level hierarchical matching

All algorithms support:

  • Party-optimal solutions (suitor/reviewer, resident/hospital, student/supervisor)
  • Validity checking
  • Stability checking (blocking pair detection)

API Reference

StableMarriage

// Create from dictionaries
const game = StableMarriage.createFromDictionaries(suitorPrefs, reviewerPrefs);

// Or create from Player objects
const game = new StableMarriage(suitors, reviewers);

// Solve
const matching = game.solve('suitor'); // or 'reviewer'

// Check validity and stability
game.checkValidity(); // throws MatchingError if invalid
game.checkStability(); // returns boolean, sets game.blockingPairs

// Convert result
matching.toRecord(); // { 'A': 'X', 'B': 'Y', ... }

HospitalResident

const game = HospitalResident.createFromDictionaries(
  residentPrefs,
  hospitalPrefs,
  capacities,
  { clean: false } // options
);

const matching = game.solve('resident'); // or 'hospital'

StableRoommates

const game = StableRoommates.createFromDictionary(playerPrefs);
const matching = game.solve();
// Note: may return null values if no stable matching exists

StudentAllocation

const game = StudentAllocation.createFromDictionaries(
  studentPrefs,
  supervisorPrefs,
  projectSupervisors,
  projectCapacities,
  supervisorCapacities
);

const matching = game.solve('student'); // or 'supervisor'

License

MIT