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

guardx

v0.0.10

Published

Protect your typescript/javascript projects from unnecessary if/else branches to check null/undefined values

Readme

GuardX

Protect your typescript/javascript projects from unnecessary if/else branches to check null/undefined values.

GuardX help developers to have type-safety during development (compile time) and type-check on runtime. Your IDE understands better when a value is null/undefined, and your app won't crash because of accessing a property of null or undefined value.

Purpose

As a TypeScript/Javascript developer you may end up being in a situation like this.


/**
 * A function that may return undefined
 */
function findUserById(userId: number): User | undefined {
  // an operation that may return undefined or the user
}

function updateUserInfo(userId: number, emailAddress: string;): void {
  const user = findUserById(userId); // Now the user is either a User or an undefined value

  // I should either type-check the user like below
  if (typeof user === 'undefined') {
    throw Error('User not found');
  }

  user.emailAddress = emailAddress;

  // or use ? operator
  user?.emailAddress = emailAddress;
}

Seems easy?

  • What if I have tons of places like this (which we always have)?
  • What if I want to catch the error and behave differently based on the error?

Usage

assert

Assert module help you to throw error based on a certain criteria. This way the app won't run and an error is thrown immediately.

import * as assert from 'guardx/assert';

/**
 * A function that may return undefined
 */
function findUserById(userId: number): User | undefined {
  // an operation that may return undefined or the user
}

const user = findUserById(123);

assert.isDefined(user); // or assert.isNotNullOrUndefined(user);

// from now on, the user is always an instance of User
// I can safely access user properties both in development time and runtime
user.emailAddress = '[email protected]';

There are other methods available. Check them in API references page.

check

Check module helps typescript to have understand types better by type guards. But, it doesn't break the application on runtime. So developer is responsible for reacting to the unwanted types (e.g. null or undefined).

import * as check from 'guardx/check';

/**
 * A function that may return undefined
 */
function findUserById(userId: number): User | undefined {
  // an operation that may return undefined or the user
}

const user = findUserById(123);

if (check.isNullOrUndefined(user)) {
  // custom logic to handle null or undefined values
  return;
}

// from now on, the user is always an instance of User
// I can safely access user properties both in development time and runtime
user.emailAddress = '[email protected]';

There are other methods available. Check them in API references page.

run

Run module help developers to run both sync and async functions and get both result and error on the same line w/o writing a try/catch block. This helps you have a cleaner and more readable code.

/**
 * A function that may return undefined
 */
function findUserById(userId: number): User | undefined {
  // an operation that may return undefined or the user
}

// w/o guardx

let user: User | undefined;

try {
  user = findUserById(123);
} catch (err) {
  // log the error or set an alarm
}

// do something with the user object

// w/ guardx
import * as run from 'guardx/run';

const result = run.safe(() => findUserById(123)); // or you can use bind method here

// it also works with async functions

const result = run.safeAsync(async () => findUserById(123)); // or you can use bind method here

// failed to execute the function
if (!result.success) {
  // Now typescript knows result is an object like this
  // {
  //    success: false,
  //    error: Error
  // }

  console.error('Failed', result.error);
}

// code was executed successfully
if (result.success) {
  // Now typescript knows result is an object like this
  // {
  //    success: true,
  //    output: Error
  // }
}

There are other methods available. Check them in API references page.

util

TBD.

There are other methods available. Check them in API references page.

Development

TBD.

References

API Documentation

Compile Typescript Packages to Multiple format