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

@btravstack/di

v0.55.1

Published

A module-based dependency-injection container for TypeScript: ports as the vocabulary an application defines, providers bound at one edge, and modules that declare their imports and exports

Readme

@btravstack/di

A module-based dependency-injection container for TypeScript: ports are the vocabulary an application defines for what it needs, providers bind a port to a construction at one edge, modules group them and decide what the outside sees — and every wiring mistake the compiler can catch is a compile error, not a runtime surprise.

📖 Documentation · Getting started · API Reference

pnpm add @btravstack/di unthrown

unthrown is a peer dependency. @btravstack/di depends on nothing else. Node >=22.

Ports, providers, modules

import { Module, Port, Provider } from "@btravstack/di";
import { ErrAsync, OkAsync, TaggedError, type AsyncResult } from "unthrown";

type Order = { readonly id: string; readonly total: number };
class OrderNotFound extends TaggedError("OrderNotFound")<{
  readonly id: string;
}> {}

// A port is named by the domain, never by whatever will implement it.
class OrderRepository extends Port("OrderRepository")<{
  readonly findById: (id: string) => AsyncResult<Order, OrderNotFound>;
}> {}

// A use case is a class that is its own port and provider: its services
// arrive typed on `this.deps`, under the names the `inject` record gave them.
class GetOrder extends Provider.class("GetOrder", { inject: { orders: OrderRepository } }) {
  execute(id: string): AsyncResult<Order, OrderNotFound> {
    return this.deps.orders.findById(id);
  }
}

// An adapter is a provider binding a declared port to a construction.
const inMemoryOrders = Provider(OrderRepository)({
  inject: {},
  sync: () => {
    const orders = new Map<string, Order>([["o-1", { id: "o-1", total: 42 }]]);
    return {
      findById: (id) => {
        const order = orders.get(id);
        return order === undefined
          ? ErrAsync(new OrderNotFound({ id }))
          : OkAsync(order);
      },
    };
  },
});

// A module groups providers and decides what the outside sees. `GetOrder`
// needs `OrderRepository`; a composition that forgets to provide it does not
// compile.
const Application = Module("Application")({
  provides: [GetOrder, inMemoryOrders],
  exports: [GetOrder],
});

// Build the graph, use it, tear it down — on every path.
await Module.scoped(Application, (ctx) => ctx.get(GetOrder).execute("o-1"));

What a module expects from outside is inferred from its providers' inject records and carried in its type, so the entry point refuses a graph that leaves one unsupplied, naming the port. A module may also state its boundary — needs: [Logger] — and is then checked against it at its own declaration.

The five provider arms — value, sync, make (may fail, with a modeled error), class, acquire/release (a resource, released when the scope closes) — the private-by-default modules, Port.many for a plugin registry, Module.forkScope for a per-request scope, and the compile-time gates that carry what is missing are on the documentation site. Under @btravstack/core, start(module) is the one Module.scoped call a process makes.

License

MIT © Benoit TRAVERS