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

di0

v1.3.0

Published

Dependency injection for ES6 classes

Readme

di0 — Dependency Injection for TS/ES6+

Version Downloads Coverage License tests/audit

Zero-config DI container. Register classes or factories by alias; dependencies are injected automatically via constructor destructuring.

Install

npm install di0

Quick Start

const { ContainerBuilder } = require('di0');

class Engine {}

class Car {
  constructor({ engine }) {
    this.engine = engine;
  }
}

const builder = new ContainerBuilder();
builder.register(Engine).as('engine');
builder.register(Car).as('car');

const container = builder.container();
container.car.engine instanceof Engine; // true

Factories

Register a factory function instead of a class:

builder.register(({ engine }) => new Car(engine), 'car');

Instance Lifetimes

| Method | Behavior | |---|---| | .asInstancePerContainer() | Default. One instance per container. | | .asSingleInstance() | One instance shared across parent and all derived containers. | | .asInstancePerDependency() | New instance on every access. |

builder.register(Engine).as('engine').asSingleInstance();

Container API

container.engine;                          // get by alias (lazy)
container.get('engine');                   // same as above
container.getAll('plugin');                // all registrations under alias
container.has('engine');                   // check without instantiating
container.createInstance(Car, { extra });  // instantiate with extra deps

Collections (asOneOf)

Register multiple types under the same alias to expose them as an array:

builder.register(GasEngine).asOneOf('engines');
builder.register(ElectricEngine).asOneOf('engines');

const container = builder.container();
container.engines; // [GasEngine instance, ElectricEngine instance]

Works with all instance lifetimes and container inheritance — child containers include parent registrations.

Auto-wiring (addResolver)

Register a predicate to automatically wire unaliased types to an alias. The predicate receives an instance; exactly one type must match — multiple matches throw.

builder.addResolver(i => i instanceof Engine, 'engine');
builder.addResolver(i => 'wheels' in i, 'car');

builder.register(Engine);
builder.register(Car); // Car: constructor({ engine }) { ... }

const { car, engine } = builder.container();

Registration order does not matter. Singleton resolver-matched instances propagate to derived containers.

Container Inheritance

Derive a child container that shares singletons with its parent:

const child = container.builder()
  .register(Plugin).as('plugin')
  .container();

// child has all parent services + Plugin
// singletons from parent are reused

Initializers (Side Effects)

Register without an alias to run code eagerly when the container is created:

builder.register(({ db }) => db.connect());  // no .as() — runs on container()

Logging

Register a logger alias to trace instantiation:

builder.register(() => console, 'logger');
// logs: "engine instance created", "car.engine instance created", …

The logger must implement { log(level, message) }.