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

composited

v3.0.0

Published

Dumb library for adding composition to JavaScript

Readme

composited

Dumb library for adding composition to JavaScript.

How usies?

// Creature.ts
export class Creature {
	name: string;
	constructor(name: string) {
		this.name = name;
	}
}
// GreetableCreature.ts
import { Creature } from "./Creature.js";
import { composeCheck } from "composited";

export class GreetableCreature {
	that: Creature;
	constructor(that: any) { this.that = composeCheck(Creature, that); }

	count = 0;

	greet() {
		console.log(`Hi! I'm ${this.that.name}. I was greeted ${++this.count} times!`);
	}
}
// index.ts
import { Creature } from "./Creature.js";
import { GreetableCreature } from "./GreetableCreature.js";

import { $ } from "composited";

const leah = new Creature("Léah");

leah[$](GreetableCreature).greet(); // Hi! I'm Léah. I was greeted 1 times!
leah[$](GreetableCreature).greet(); // Hi! I'm Léah. I was greeted 2 times!

As of v2.x.y, you can also use composited with primitives.

How workies?

We extend Object.prototype with $, a symbol. (And since it's a symbol, it won't pollute anything). We use a WeakMap to map each value with an inner WeakMap (or simply a Map for non-WeakKeys) mapping each ThatClass object to the class instance.

API

We assume: import { $ } from "composited";

Object#[$]: (ThatClass: new (v: any) => unknown) => InstanceType<typeof ThatClass>

Gets, or creates, the instance of the "trait" ThatClass. When creating, it will instanciate ThatClass with this (the object it's used on) as an argument.

composeCheck(InputClass: new (v: any) => unknown, v: any) => InstanceType<typeof InputClass>

Behaves as an identity function if v is an instance of InputClass . Will throw a CompositionError otherwise. Meant as a helper function to make trait creation faster.

CompositionError

Error specifying the impossibility to perform the composition.

More obsure and less useful API, might remove at my own discretion

CompositionsHandler.compositions: WeakMap<WeakKey, OnEmptyWeakMap<new (v: WeakKey) => unknown, unknown>>

The memoization WeakMap of all compositions from WeakKey, to WeakMaps from class objects (traits), to class instances

(OnEmptyWeakMap is a WeakMap with a FinalizationRegistry such that when the WeakMap is empty, a hook is called to remove it from e.g. the upper weakMap)

CompositionsHandler.compositions: WeakMap<StrongKey, OnEmptyWeakMap<new (v: WeakKey) => unknown, unknown>>

The memoization Map of all compositions from StrongKey, to WeakMaps from class objects (traits), to class instances

CompositionsHandler.get(ThatClass: new (v: WeakKey) => unknown, obj: WeakKey):

Creates or gets the trait defined by ThatClass holding a reference to obj. Requires obj be a WeakKey.

CompositionsHandler.getStrong(ThatClass: new (v: StrongKey) => unknown, obj: StrongKey)

Creates or gets the trait defined by ThatClass holding a reference to obj.