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

@billdaddy/assertkit

v0.1.1

Published

Tiny, type-safe assertions — invariant/assert with TypeScript narrowing, assertDefined, assertNever exhaustiveness, ensure, and lazy messages. Zero dependencies.

Readme

assertkit

All Contributors

Tiny, type-safe assertionsinvariant / assert with TypeScript narrowing, assertDefined, assertNever exhaustiveness, ensure, and lazy messages. Zero dependencies.

CI npm version bundle size types license

tiny-invariant throws when a condition is false — but TypeScript still thinks your value could be null on the next line. assertkit uses real assertion signatures (asserts condition), so a passing assertion actually narrows the type. Same tiny footprint, plus assertDefined, exhaustiveness checks, and lazy messages. Zero dependencies.

import { invariant } from "@billdaddy/assertkit";

function greet(name: string | null) {
  invariant(name, "name is required");
  return name.toUpperCase(); // ✅ `name` is `string` here
}

Why assertkit?

  • It narrows. invariant / assert / assertDefined carry asserts signatures, so the compiler refines the type after the call — no ! or casts.
  • Exhaustiveness for free. assertNever makes a switch fail to compile when you add a union member and forget to handle it.
  • Lazy messages. Pass a () => string; it only runs when the assertion fails, so expensive diagnostics cost nothing on the happy path.
  • ensure for inline use. Assert-and-return in a single expression.
  • One typed error. Everything throws AssertionError.
  • Zero dependencies, ESM + CJS + types, ~0.3 kB.

Install

npm install @billdaddy/assertkit
# or: pnpm add @billdaddy/assertkit  /  yarn add @billdaddy/assertkit  /  bun add @billdaddy/assertkit

API

invariant(condition, message?) / assert(condition, message?)

Throw AssertionError when condition is falsy; narrow it to truthy otherwise.

invariant(user, "user not loaded");
invariant(items.length > 0, () => `expected items, got ${items.length}`);

assertDefined(value, message?)

Throw when value is null/undefined; narrow to NonNullable<T>. (0, "", false pass — they're defined.)

assertDefined(config.apiKey, "API key missing");
config.apiKey.slice(0, 4); // string, not string | undefined

ensure(value, message?)

Like assertDefined, but returns the value for inline use.

const root = ensure(document.querySelector("#app"), "missing #app");

assertNever(value, message?)

Exhaustiveness guard for unions.

type Shape = { kind: "circle" } | { kind: "square" };

function area(s: Shape) {
  switch (s.kind) {
    case "circle": return /* … */ 0;
    case "square": return /* … */ 0;
    default: return assertNever(s); // compile error if a case is missing
  }
}

fail(message?)

Always throws — for unreachable branches or "not implemented" guards.

if (mode === "legacy") fail("legacy mode removed");

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 © Tung Tran