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

expunge

v0.1.1

Published

Self-cleaning temp files and directories — scope-bound via `using`, swept on crash and signal, zero dependencies.

Readme

expunge

Self-cleaning temp files and directories — scope-bound via await using, swept on crash and signal, zero dependencies.

npm version License: MIT

The problem

Tests and CLIs create temp dirs and forget them. A thrown error skips the cleanup line, and CI accumulates gigabytes of /tmp cruft over weeks. Cleanup-on-crash is exactly when hand-rolled finally blocks fail. Existing solutions like tmp and tmp-promise predate TypeScript 5.2's using/Symbol.asyncDispose and have unreliable exit-handler cleanup across signals.

Install

npm install expunge
# or
pnpm add expunge
# or
yarn add expunge

Use

import expunge from "expunge";

// Scope-bound cleanup - auto-removed at end of scope
await using dir = await expunge.dir();
await fs.writeFile(dir.path + "/data", "content");
// dir is automatically removed when scope exits

// Manual cleanup with keep:true
const persist = await expunge.file({ postfix: ".png", keep: true });
await processImage(persist.path);
await persist.remove(); // you own cleanup for keep:true

// Sweep everything (except keep:true temps)
await expunge.all();

API

interface TempOptions {
  prefix?: string;          // default "expunge-"
  postfix?: string;         // e.g. ".png"
  dir?: string;             // parent dir, default os.tmpdir()
  keep?: boolean;           // exclude from auto-sweep
}

interface Temp {
  readonly path: string;
  readonly keep: boolean;
  readonly removed: boolean;
  remove(): Promise<void>;
  removeSync(): void;
  [Symbol.asyncDispose]: () => Promise<void>;
}

interface Expunge {
  dir(opts?: TempOptions): Promise<Temp>;
  file(opts?: TempOptions): Promise<Temp>;
  all(): Promise<void>;
  readonly size: number;
  cleanupHandlers(): void;
}

function createExpunge(): Expunge;
const expunge: Expunge;
export default expunge;

Behavior:

  • dir()/file() create with crypto-random names (base32) to avoid collisions
  • Dirs: mode 0o700, files: mode 0o600
  • remove() is idempotent and recursive for dirs
  • Registry tracks non-keep temps and installs exit/signal handlers lazily
  • keep:true excludes from auto-sweep (caller owns cleanup)
  • Signal handlers (SIGINT/SIGTERM) call all() then re-raise

Non-goals: expunge does NOT provide content writing helpers, template/scaffolding, in-memory FS, file watching, or cross-process locking. Compose with other libraries for those needs.

TypeScript

Requires TypeScript 5.2+ for Symbol.asyncDispose support and Node 18+ for node:fs/promises.

import expunge, { createExpunge } from "expunge";

// Shared default instance
await using dir = await expunge.dir();

// Isolated registry (useful for tests)
const registry = createExpunge();
const file = await registry.file({ postfix: ".log" });
await file.remove();

Related Packages

Caching & Concurrency:

Text Processing:

  • @azghr/shorn — Truncate strings by byte budget without breaking graphemes
  • seriatim — Sequential processing utilities

HTTP & Network:

  • forbear — Read server rate-limit instructions from HTTP responses
  • forestall — Delay execution until a condition is met
  • obviate — Render operations unnecessary through caching

System & Process:

  • quiesce — Ordered, timeboxed graceful shutdown for Node
  • sortition — Deterministic percentage rollouts and A/B bucketing
  • stanch — Stop flows or operations based on conditions

Utilities:

  • occlude — Hide or mask data and functionality
  • placemark — Geographic location and mapping utilities
  • specie — Currency and financial calculations

License

MIT