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

@gmjs/assert

v0.0.6

Published

Assert utils.

Downloads

16

Readme

Assert Util

Some assertion utility functions.

Installation

npm install --save @gmjs/assert

Usage

All functions are exported as named exports.

import { invariant } from '@gmjs/assert';

const x: string | undefined = 'some value';
invariant(x !== undefined, 'x must be defined');

API

ensureNever

Used for compile time check to make sure that the value provided to the function is of type never.

This can be used to make sure, at compile time, that all cases for a type are handled.

If you have the following:

type Operation = 'add' | 'subtract';

function compute(operation: Operation, op1: number, op2: number): number {
  switch (operation) {
    case 'add': {
      return op1 + op2;
    }
    case 'subtract': {
      return op1 - op2;
    }
    default: {
      return ensureNever(operation);
    }
  }
}

And then you decide to change Operation:

type Operation = 'add' | 'subtract' | 'multiply' | 'divide';

compute function will now complain at compile time until you add cases handling the new 'multiply' and 'divide' options, and so exhaustive handling will be ensured at compile time.

After we add the new cases, everything works again:

type Operation = 'add' | 'subtract' | 'multiply' | 'divide';

function compute(operation: Operation, op1: number, op2: number): number {
  switch (operation) {
    case 'add': {
      return op1 + op2;
    }
    case 'subtract': {
      return op1 - op2;
    }
    case 'multiply': {
      return op1 * op2;
    }
    case 'divide': {
      return op1 / op2;
    }
    default: {
      return ensureNever(operation);
    }
  }
}

ensureNotNull

Throws an error if the given value is null, otherwise returns the given value, with the type narrowed to exclude null.

const x: string | null = 'some value';
const y = ensureNotNull(x);
// y is equal to 'some value', and has type string
const x: string | null = null;
const y = ensureNotNull(x); // this line will throw

ensureNotNullish

Throws an error if the given value is null or undefined, otherwise returns the given value, with the type narrowed to exclude null and undefined.

const x: string | null | undefined = 'some value';
const y = ensureNotNullish(x);
// y is equal to 'some value', and has type string
const x: string | null | undefined = null;
const y = ensureNotNullish(x); // this line will throw
const x: string | null | undefined = undefined;
const y = ensureNotNullish(x); // this line will throw

ensureNotUndefined

Throws an error if the given value is undefined, otherwise returns the given value, with the type narrowed to exclude undefined.

const x: string | undefined = 'some value';
const y = ensureNotUndefined(x);
// y is equal to 'some value', and has type string
const x: string | undefined = undefined;
const y = ensureNotUndefined(x); // this line will throw

invariant

Throws an error if the given condition is not truthy.

It will also narrow the type of any variable used in the condition.

const x: string | undefined = 'some value';
invariant(x !== undefined, 'x must be defined');
// from here on, x is narrowed to string type
const x: string | undefined = undefined;
invariant(x !== undefined, 'x must be defined'); // this line will throw