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

@foxystar/patches

v0.1.3

Published

A lightweight, type-safe patching system for extending and modifying class behavior using decorators.

Downloads

436

Readme

@foxystar/patches

A lightweight, type-safe patching system for extending and modifying class behavior using decorators.

Installation

npm install @foxystar/patches

Overview

@foxystar/patches provides a clean and flexible way to:

  • Override class methods, getters, and setters
  • Chain multiple patches together
  • Control execution order with priorities
  • Write modular, reusable patches

It was designed primarily for systems like Minecraft: Bedrock Edition's Scripting API, but works anywhere you need runtime patching.

Quick Example

import { createPatch } from "@foxystar/patches";
class SomeClass {
    method(x: number): number {
        return x * 2;
    }
}

const Some = createPatch(SomeClass);

@Some.Patch
class MyPatch {
    @Some.Override("method")
    method(original: (x: number) => number, x: number) {
        return original(x) + 1;
    }
}

new SomeClass().method(5); // -> 11 

How It Works

Each override receives:

(original, ...args) 
  • original -> the next function in the chain (or the original method)
  • ...args -> original arguments

Multiple patches are automatically chained together.

Chaining & Priority

You can stack multiple patches and control execution order:

@Some.Patch
class PatchA {

    @Some.Override("method", { priority: 0 })
    method(original, x: number) {
        console.log("A");
        return original(x);
    }
}

@Some.Patch
class PatchB {

    @Some.Override("method", { priority: 1 })
    method(original, x: number) {
        console.log("B before");
        const result = original(x);
        console.log("B after");

        return result;
    }
} 

Execution order: A -> B before -> (original) -> B after

Getters & Setters

You can override accessors as well:

@Some.Patch
class HealthPatch {

    @Some.Override.get("health")
    getHealth(original) {
        const value = original();
        console.log("get:", value);

        return value;
    }
    
    @Some.Override.set("health")
    setHealth(value: number, original) {
        console.log("set:", value);
        original(value);
    }
} 

Type-Safe Overrides

When using createPatch, property keys are fully typed:

@Some.Override("method") // autocomplete
@Some.Override("invalid") // compile error 

Without createPatch

You can still use the base decorators:

import { Patch, Override } from "@foxystar/patches";

@Patch(SomeClass)
class MyPatch {
    @Override("method")
    method(original, x: number) {
        return original(x);
    }
} 

[!NOTE] But you lose autocomplete and key safety.

API

createPatch(Class)

Creates a typed patch context:

const Some = createPatch(SomeClass); 

Provides:

  • Some.Patch
  • Some.Override
  • Some.Override.get
  • Some.Override.set

@Patch(Class)

Registers a patch class.

@Override(key?, options?)

Overrides a method.

Options:

{
    nativeKey?: string;
    priority?: number;
}

@Override.get(key)

Overrides a getter.

@Override.set(key)

Overrides a setter.

Design Principles

  • Separation of concerns: typed API, generic runtime
  • Composable patches: chain safely and predictably
  • Minimal boilerplate: decorators handle everything

[!IMPORTANT]

  • Static methods are not supported
  • Patch order is determined by priority
  • Lower priority runs closer to the original implementation

Why use this?

Instead of:

// manual monkey patching:
const original = obj.method;
obj.method = function (...) { ... };

You get:

@Override("method")
method(original, ...) { ... }

It's basically cleaner, safer, and scalable.