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

@o.z/zdi

v0.4.0

Published

A lightweight, type-safe Dependency Injection container for TypeScript/JavaScript applications.

Readme

@o.z/zdi ⚡

npm version license TypeScript

A lightweight, type-safe Dependency Injection container for TypeScript/JavaScript applications.

Features

  • ✅ Zero dependencies
  • ✅ Type-safe (written in TypeScript)
  • ✅ Transient and singleton services
  • ✅ Automatic dependency resolution
  • ✅ Child containers with isolated instances
  • ✅ Resource disposal for graceful shutdown
  • ✅ Custom error classes for clear debugging

Installation

yarn add @o.z/zdi
npm install @o.z/zdi
pnpm add @o.z/zdi

Quick Start

import { Container } from '@o.z/zdi';

// Define some classes
class Logger {
  log(message: string) { console.log(message); }
}

class Database {
  constructor(private logger: Logger) {}
  query(sql: string) {
    this.logger.log(`Executing query: ${sql}`);
    // ...
  }
}

// Create container and register services
const container = new Container();
container.registerClass(Logger, []); // transient
container.registerClass(Database, [Logger], true); // singleton

// Resolve instances
const db1 = container.get(Database);
const db2 = container.get(Database);
console.log(db1 === db2); // true (singleton)

const logger1 = container.get(Logger);
const logger2 = container.get(Logger);
console.log(logger1 === logger2); // false (transient)

API Overview

Full API documentation is available at docs/api/README.md.

Core Methods

  • register<T>(token, factory) – Registers a transient service using a factory function.
  • registerSingleton<T>(token, factory) – Registers a singleton service using a factory.
  • registerClass<T>(token, dependencies, singleton?, disposeCallback?) – Registers a class with automatic dependency resolution.
  • get<T>(token) – Resolves a service instance.
  • has<T>(token) – Checks if a service is registered.
  • dispose() – Cleans up all singleton instances that implement Disposable.
  • createChild() – Creates a child container inheriting registrations but with separate singleton instances.

Error Handling

The library throws specific errors to help you debug:

  • ServiceNotFoundError – Thrown when trying to resolve an unregistered service.
  • DuplicateRegistrationError – Thrown when registering a service that already exists.
  • InstantiationError – Thrown when a service factory throws an error.

Advanced Usage

Child Containers

Child containers allow you to create isolated scopes (e.g., per request) while sharing parent registrations.

const parent = new Container();
parent.registerClass(Config, [() => ({ apiUrl: 'https://api.example.com' })], true);

const child = parent.createChild();
child.registerClass(RequestContext, [() => ({ userId: 123 })]); // request-scoped

const config = child.get(Config); // inherited from parent
const context = child.get(RequestContext); // child-specific

Disposal

Services that need cleanup can provide a disposal callback. The container will invoke it when dispose() is called.

container.registerClass(
  DatabaseConnection,
  [Config],
  true, // singleton
  (conn) => conn.close() // dispose callback
);

// Later, during shutdown:
await container.dispose();

Alternatively, services can implement the Disposable interface (with a dispose method) and the container will automatically call it if registered.

Type Safety

The container is fully typed. Dependencies are checked at compile time:

container.registerClass(Car, [Engine, Plate]); // ✅ correct
container.registerClass(Car, [Engine, 'wrong-type']); // ❌ TypeScript error

License and AI Training

This project is licensed under the GNU General Public License v3.0 (GPLv3).

The authors of this software consider the use of this code, including its source code, documentation, and any other project artifacts, for the training of artificial intelligence (AI) systems (including but not limited to machine learning, large language models, and other AI technologies) to be creating a derivative work. As such, any entity using this code for such purposes must comply with the terms of the GPLv3. This includes, but is not limited to, making the entire source code of the AI system that uses this code available under the same GPLv3 license.

If you wish to use this code for AI training without being subject to the GPLv3, please contact the authors to negotiate a separate license.