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

matchframe

v0.0.1

Published

A general-purpose business decision library for solving allocation, assignment, ranking, and scheduling problems under complex business constraints.

Readme

matchframe

A small, deterministic allocation engine for assigning entities to resources under hard constraints and configurable scoring rules.

Install

npm install matchframe
# or
yarn add matchframe

Core concepts

  • Entity (E) — the thing being allocated (a job, student, pallet, ...).
  • Resource (R) — the thing receiving the allocation (a technician, major, warehouse zone, ...).
  • Problem — a collection of entities, wrapped resources, optional global constraints, and optional global scoring rules.
  • Solver — a function that turns a Problem into a Result.

The default solver is a deterministic greedy allocator:

  1. Sort entities by global priority (higher score first).
  2. For each entity, find the best feasible resource using combined global + per-resource scores.
  3. Enforce hard constraints and capacity.
  4. Record every assignment, rejection, and final resource usage.

Quick example

import { createResource, solve, scoring } from "matchframe";

type Job = { id: string; priority: number; zone: string };
type Tech = { id: string; zone: string; maxJobs: number };

const technicians: Resource<Job, Tech>[] = [
  createResource(
    { id: "T1", zone: "north", maxJobs: 2 },
    {
      capacity: 2,
      constraints: [
        createResource.compatible({
          predicate: (job, tech) => job.zone === tech.zone,
          reason: "zone mismatch",
        }),
      ],
      scoring: [
        scoring.preference({
          score: (job, tech) => (job.zone === tech.zone ? 10 : 0),
        }),
      ],
    }
  ),
];

const result = solve({
  entities: [
    { id: "J1", priority: 1, zone: "north" },
    { id: "J2", priority: 2, zone: "north" },
  ],
  resources: technicians,
  scoring: [
    scoring.preference({
      name: "priority",
      score: (job) => job.priority,
    }),
  ],
});

console.log(result.summary);
// { totalEntities: 2, assigned: 2, unassigned: 0, resourcesUsed: 1 }

API

createResource<E, R>(raw, options)

Wrap a raw resource with capacity, constraints, and scoring rules.

createResource(raw, {
  capacity: 5,
  constraints: [...],
  scoring: [...],
});

Built-in constraints

Attach to a resource or pass globally in Problem.constraints.

| Helper | Purpose | | --- | --- | | createResource.hard({ predicate, reason }) | Generic boolean constraint. | | createResource.capacity({ limit }) | Enforce a fixed capacity limit. | | createResource.quota({ groupBy, maxPct, minPct }) | Enforce percentage caps/floors for groups. | | createResource.exclusive({ category, allowedCategories }) | Only allow listed categories. | | createResource.compatible({ predicate, reason }) | Generic compatibility predicate. | | createResource.dependency({ key, dependsOn, sameResource? }) | Require another entity to be assigned first. | | createResource.mutualExclusion({ conflicts, scope? }) | Block conflicting entities from sharing a resource (or globally). | | createResource.timeWindow({ entityWindow, resourceWindows, allowOverlap? }) | Enforce schedule fit and optional no-overlap policy. | | createResource.crossResourceQuota({ groupBy, maxAllowed }) | Enforce group limits across all resources. |

Notes:

  • createResource.capacity(...) also accepts { predicate, reason? } for custom context-aware capacity rules.
  • Backward-compatible signatures are still supported (hard(predicate, options) and capacity(number | predicate)).

Built-in scoring rules

| Helper | Purpose | | --- | --- | | scoring.preference({ score, direction }) | User-defined numeric preference. | | scoring.loadBalance({ weight }) | Prefer resources with lower utilization. | | scoring.orderedFallback({ order }) | Prefer resources in a fixed fallback order. | | scoring.tieBreak({ by, direction }) | Deterministic tie-break key when other scores are equal. | | scoring.waitlist({ score, direction }) | Rank unassigned entities into a deterministic waitlist. |

solve(problem)

Run the configured solver (default: greedySolver). Returns a Result with:

  • assignments — every entity/resource pair.
  • assignments[*].reasons — why the selected resource won and what alternatives failed.
  • unassigned — entities that could not be placed, with reasons.
  • waitlist — ranked view of unassigned entities (with score and reasons).
  • resourceUsage — used/capacity/remaining per resource.
  • decisions — full decision log (assignments and rejections).
  • summary — totals.

Scoring direction

  • "desc" (default) — higher score is better.
  • "asc" — lower score is better.

A rule may return number or number[]. Arrays are compared lexicographically, which is useful for multi-criteria sorting such as [total, english, math].

Notes

  • Global priority rules are used only for entity ordering. They receive undefined for resource and context, so they must not access those fields.
  • Per-resource constraints and scoring rules are evaluated for each candidate resource during allocation.
  • Capacity is tracked per resource and enforced by the built-in capacity constraint or custom constraints.