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

disposablekit

v0.1.0

Published

Zero-dependency TypeScript resource management: defer(), DisposableGroup, using(), AsyncDisposableGroup. Symbol.dispose polyfill. Like Go defer / Python contextlib.ExitStack / C# IDisposable.

Readme

disposablekit

All Contributors

Zero-dependency TypeScript resource management: defer(), DisposableGroup, using(), AsyncDisposableGroup. Symbol.dispose polyfill included. Port of Go defer / Python contextlib.ExitStack / C# IDisposable / Java try-with-resources.

npm License: MIT

Install

npm install disposablekit

Works with any TypeScript version. Full Symbol.dispose/Symbol.asyncDispose support for TypeScript 5.2+ (with runtime polyfill for older Node.js).

Quick start

import { defer, DisposableGroup, using, usingAsync } from "disposablekit";

// Go-style defer — runs on dispose
const cleanup = defer(() => console.log("cleaned up"));
cleanup[Symbol.dispose]();

// Group multiple resources
const group = new DisposableGroup();
group.add(fileHandle);           // add any Disposable
group.defer(() => db.close());   // or schedule a callback
group[Symbol.dispose]();         // disposes all in reverse order

// Scoped using (like Java try-with-resources, Python with)
const result = using(openFile("data.txt"), (file) => file.readAll());
// file is closed automatically, even on error

// Async version
await usingAsync(openDbConn(), async (conn) => {
  return conn.query("SELECT 1");
});

Why disposablekit?

TypeScript 5.2 added using / await using keywords (TC39 Explicit Resource Management). But:

  • The using keyword needs TypeScript 5.2+ AND modern Node.js
  • DisposableStack/AsyncDisposableStack are TC39 Stage 4 but not yet in all environments
  • The disposablestack polyfill has 12 runtime dependencies
  • @tioniq/disposiq exists but has only 67 downloads/week

disposablekit is a single, zero-dep utility covering everything you need: defer(), DisposableGroup, using(), combine(), tryDispose(), suppress(), and their async counterparts.

API

defer(fn) / toDisposable(fn)

Create a Disposable from a callback. Like Go's defer, Python's contextlib.contextmanager cleanup section, or finally cleanup.

import { defer } from "disposablekit";

const conn = openConnection();
const d = defer(() => conn.close());
// ... use conn ...
d[Symbol.dispose]();  // conn.close() called

DisposableGroup

Collect multiple disposables; dispose all in reverse order on Symbol.dispose. Like Python's contextlib.ExitStack or C#'s CompositeDisposable.

import { DisposableGroup } from "disposablekit";

const group = new DisposableGroup();
const file = group.add(openFile("data.txt"));  // add() returns the resource
const conn = group.add(openConnection());
group.defer(() => console.log("all done"));

group[Symbol.dispose]();
// → closes in reverse: "all done", conn.close(), file.close()

Properties: group.size, group.disposed

AsyncDisposableGroup

Like DisposableGroup but async — accepts both sync and async disposables.

import { AsyncDisposableGroup } from "disposablekit";

const group = new AsyncDisposableGroup();
group.add(syncResource);
group.add(asyncResource);
group.defer(async () => await flushLogs());
await group[Symbol.asyncDispose]();

using(resource, fn) / usingAsync(resource, fn)

Functional scoped cleanup. Like Java try (Resource r = ...) { ... } or Python with open(...) as f:.

// Sync
const content = using(openFile("data.txt"), (f) => f.read());
// file closed automatically

// Async
const rows = await usingAsync(openConnection(), async (conn) => {
  return conn.query("SELECT * FROM users");
});

combine(...disposables) / combineAsync(...disposables)

Merge multiple disposables into one (disposes in reverse order).

import { combine, defer } from "disposablekit";

const d = combine(
  defer(() => closeA()),
  defer(() => closeB()),
  defer(() => closeC()),
);
d[Symbol.dispose](); // C, B, A

tryDispose(d) / tryDisposeAsync(d)

Dispose without throwing — returns the Error instead (or null on success).

const err = tryDispose(resource);
if (err) console.error("dispose failed:", err);

suppress(d) / suppressAsync(d)

Wrap a disposable to silently ignore all errors on dispose.

const safe = suppress(flakyResource);
safe[Symbol.dispose](); // never throws

isDisposable(value) / isAsyncDisposable(value)

Type guards.

if (isDisposable(value)) value[Symbol.dispose]();

Comparison

| Language | Pattern | disposablekit equivalent | |---|---|---| | Go | defer fn() | defer(fn) | | Python | with contextlib.ExitStack() | DisposableGroup | | Python | async with contextlib.AsyncExitStack() | AsyncDisposableGroup | | C# | using (var r = ...) { } | using(r, fn) | | Java | try (Resource r = ...) { } | using(r, fn) | | TypeScript 5.2 | using r = resource | using(resource, fn) (pre-5.2) |

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.

Thanks goes to these wonderful people:

License

MIT © trananhtung