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

@aurbi/tiny-composite-builder

v1.0.10

Published

Small framework for taking base objects and adding extensions using a builder pattern, but with full and strict compile-time type support.

Readme

tiny-composite-builder

A tiny library that gives you a builder pattern to set up your own composite classes by adding extension classes to a base class. Some of the extension's methods are added to the created object.

This is easy enough in vanilla JS, so the value of this is mostly in TypeScript. It's fully typed.

The relatively dynamic-seeming objects you create by using the builder will result in a fully typed base object that is aware of its extensions, their methods, etc. You basically won't be able to tell it was hacked together behind the scenes.

Um, let me just show you.

Examples

Simple Example

Extensions are (and remain) their own sovereign classes, and can maintain their own internal state.

Methods in the extension, however, have 'forwarders' added to the base class when the builder constructs it. You can control the condition by which methods are forwarded on the base class in this manner, but by default, it will forward any public method that starts with a dollar sign ($).

class MyBase implements IBase<MyBase> {
  constructor(public Extensions: IExtension<MyBase>[]) {}
  FuncBase() { return "Base" }
}

class ExtA implements IExtension<MyBase> {
  constructor (public Base: MyBase) {}
  $FuncA() { return "A" }
}

class ExtB implements IExtension<MyBase> {
  constructor (public Base: MyBase, private _output: string) {}
  $FuncB() { return this._output }
}

const built = Builder.Create(MyBase, b => b
  .with(ExtA)
  .with(ExtB, "B")
);

console.log( built.FuncBase() );  // "Base"
console.log( built.FuncA() );     // "A"
console.log( built.FuncB() );     // "B"

Cross-extension access

Extensions can check-for and access other extensions, because the base is always given a list of all extensions upon construction. This, too, is fully typed.

They can access all the public properties and methods of other extensions, not just the ones with forwarders present on the base class.

class MyBase implements IBase<MyBase> {
  constructor(public Extensions: IExtension<MyBase>[]) {}

  FuncBase() { return "Base" }
}

class ExtA implements IExtension<MyBase> {
  constructor (public Base: MyBase) {}
  
  $FuncA() { return "A" }
  getValue() { return "B" }
}

class ExtB implements IExtension<MyBase> {
  constructor (public Base: MyBase, private _output: string) {}

  $FuncB() {
    const extA = this.Base.Extensions.find(b => b instanceof ExtA)
    if (!extA) {
      throw new Error("extension A not loaded")
    }

    return extA.getValue()
  }
}

const built = Builder.Create(MyBase, b => b
  .with(ExtA)
  .with(ExtB)
);

console.log( built.FuncBase() );  // "Base"
console.log( built.FuncA() );     // "A"
console.log( built.FuncB() );     // "B" - via ExtA.getValue()