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

tiny-mixin

v1.1.1

Published

A lightweight TypeScript-first class mixin utility

Downloads

367

Readme

Tiny Mixin

Tiny Mixin is a utility for creating and applying mixins to classes in TypeScript. It aims to provide a simple and efficient way to do prototype composition as an alternative to multiple inheritance.

Why Tiny Mixin?

There are many mixin patterns in TypeScript - from manual class wrapping to complex helper types. Tiny Mixin focuses on doing one thing well:

  • Fully typed - Preserves constructor and instance types across mixin chains.
  • Supports abstract classes - Works seamlessly with both abstract and concrete base classes.
  • Deterministic order - Mixins are applied left-to-right with predictable override behavior.
  • Cached results - Reuses previously applied (Base, Mixin) pairs using WeakMap, avoiding redundant class generation.
  • Tiny & dependency-free - Minimal runtime footprint with zero external dependencies.

Tiny Mixin is designed for cases where you want clean prototype composition without the complexity of multiple inheritance or heavyweight frameworks.

Installation

It works perfectly in Node.js and browsers. You can install it using npm or your package manager of choice:

npm install tiny-mixin
pnpm add tiny-mixin
yarn add tiny-mixin
bun add tiny-mixin

Usage

In this example, we will try to create multiple animal classes with different behaviors.

Creating a base class

abstract class Animal {
	constructor(public name: string, public age: number) {}
}

Creating mixins

Since animal can have different behaviors, we will create mixins for each behavior to reuse them for different animal classes.

import { createMixin } from "tiny-mixin";

const FlyableAnimalMixin = createMixin((base) => {
	class FlyableAnimal extends base {
		public fly() {
			// makes the animal fly	
		}
	}

	return FlyableAnimal;
});

const SwimmableAnimalMixin = createMixin((base) => {
	class SwimmableAnimal extends base {
		public swim() {
			// makes the animal swim
		}
	}

	return SwimmableAnimal;
});

const WalkableAnimalMixin = createMixin((base) => {
	class WalkableAnimal extends base {
		public walk() {
			// makes the animal walk
		}
	}

	return WalkableAnimal;
});

If you need to reference the base class to an existing class, you can do this:

import { createMixin, type ConstructorLike } from "tiny-mixin";

abstract class Animal { ... }

const FlyableAnimalMixin = createMixin((base: ConstructorLike<Animal>) => {
	// Make it abstract like the base so it can be used as a mixin
	abstract class FlyableAnimal extends base {
		public fly() {
			console.log(`${this.name} is flying`);
		}
	}

	return FlyableAnimal;
});

Using mixins

After creating the mixins, we can use them to create animal classes with different behaviors.

import { createMixin, applyMixins } from "tiny-mixin";

const FlyableAnimalMixin = createMixin((base) => ...);
const SwimmableAnimalMixin = createMixin((base) => ...);
const WalkableAnimalMixin = createMixin((base) => ...);

class Duck extends applyMixins(Animal, [FlyableAnimalMixin, SwimmableAnimalMixin, WalkableAnimalMixin]) {
	// ...
}

const duck = new Duck("Duck", 2);

// Now you can do these
duck.fly();
duck.swim();
duck.walk();

console.log(`${duck.name} is ${duck.age} years old`);

Notes

Mixins are applied in the order they appear in the array, so the first mixin will be applied first, followed by the second mixin, and so on. This is useful for creating a composition-like behavior.

The mixin result will also be cached to avoid re-applying the same mixin multiple times.

applyMixins(Base, [A, B])
// is equivalent to:
B(A(Base))
const Duck1 = applyMixins(Animal, [FlyableAnimalMixin, SwimmableAnimalMixin, WalkableAnimalMixin]);
const Duck2 = applyMixins(Animal, [FlyableAnimalMixin, SwimmableAnimalMixin, WalkableAnimalMixin]);

console.log(Duck1 === Duck2); // true
const Duck1 = applyMixins(Animal, [FlyableAnimalMixin, SwimmableAnimalMixin, WalkableAnimalMixin]);
const Duck2 = applyMixins(Animal, [FlyableAnimalMixin, WalkableAnimalMixin, SwimmableAnimalMixin]);

console.log(Duck1 === Duck2); // false

It is also important to check for mixin conflicts, as they can cause unexpected behavior.

Contributing

Contributions are always welcome! If you find a bug or have a suggestion, please open an issue or pull request.

Support

If you like this project and want to support its development, you can buy me a coffee:

ko-fi