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

@axijs/ensure

v1.0.2

Published

A lightweight collection of TypeScript type guards and assertions

Readme

@axijs/ensure

NPM version

A lightweight, zero-dependency collection of TypeScript type guards and assertions.

Designed to ensure type safety and handle runtime validation cleanly without the boilerplate.

Installation

npm install @axijs/ensure
# or
pnpm add @axijs/ensure
# or
yarn add @axijs/ensure

Features

  • Zero dependencies: Extremely lightweight.
  • Strict Type Guards: Safely narrow down types (e.g., isObject correctly filters out null and arrays).
  • Assertion Utilities: Clean flow control with throwIf and throwIfEmpty.

Usage

1. Assertions & Flow Control

Use assertions to enforce conditions.

import {throwIfEmpty, throwIf, throwError} from '@axijs/ensure';

// Example: Narrowing a potentially undefined value
const user: { name: string } | undefined = findUser();

throwIfEmpty(user, 'User not found');
console.log(user.name);

// Example: Conditional throwing
const isInvalid = validate(data);
throwIf(isInvalid, 'Data validation failed');

// Example: Unconditional throw
function notImplemented(): never {
  throwError('This feature is coming soon');
}

2. Type Guards

Check types safely at runtime while giving TypeScript the correct type context.

import {isString, isObject, isPromise, isIterable} from '@axijs/ensure';

const data: unknown = fetchData();

if (isString(data)) {
  console.log(data.toUpperCase());
}

if (isObject(data)) {
  // True plain object (not null, not array)
  console.log(Object.keys(data));
}

if (isPromise(data)) {
  data.then(resolve);
}

if (isIterable(data)) {
  for (const item of data) {
    console.log(item);
  }
}

3. Emptiness Check

A single utility to check if a value is conceptually "empty".

import {isEmpty} from '@axijs/ensure';

isEmpty({}); // true
isEmpty(0); // false
isEmpty(false); // false

API Documentation

For a complete list of available type guards, assertions, and their detailed descriptions, please visit the API Documentation.

License

MIT