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

michi-typehelper

v1.0.4

Published

Lightweight runtime type checking for JavaScript with full TypeScript support and useful type inference for safer, clearer runtime code.

Downloads

12

Readme

michi-typehelper

Lightweight runtime type checking for JavaScript with full TypeScript support and useful type inference for safer, clearer runtime code.

Key Features

  • Runtime type checking to improve code safety in JavaScript.
  • Full TypeScript support with smart type inference for better type narrowing.
  • Built-in validation utilities that simplify error handling and enforce correct types.
  • Environment agnostic: works seamlessly in browsers, Node.js, Deno, and other JavaScript runtimes.
  • Lightweight and dependency-free, ensuring minimal impact on your project.

Installation

npm install michi-typehelper

Usage

| Method Name | Description | Returns / Throws | | ------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | isNullable<T>(obj: T) | Checks if a value is null or undefined. | true if obj is null or undefined, otherwise false. | | isType<T>(obj: unknown, type: T) | Checks whether a value is of the specified type. | true if obj matches the type, otherwise false. | | isAnyType<T1, T2, T3>(obj: unknown, type1: T1, type2: T2, type3?: T3) | Checks if value matches any of the specified types. | true if matches at least one type, otherwise false. | | isTypeArray<T>(object: unknown, type: T) | Checks if value is an array where every item matches the specified type. | true if array of specified type, otherwise false. | | throwIf(condition: boolean, message: string) | Throws a TypeError if the condition is true. | Throws TypeError if condition is true. | | throwIfNullable<T>(obj: T) | Throws if the object is null or undefined. | Throws TypeError if obj is null or undefined. | | throwIfNotNullable<T>(obj: T) | Throws if the object is not null or undefined. | Throws TypeError if obj is neither null nor undefined. | | throwIfUndefined<T>(obj: T) | Throws if the object is undefined. | Throws TypeError if obj is undefined. | | throwIfType<TObject, TType>(object: TObject, type: TType) | Throws if the object is of the specified type. | Throws TypeError if object is instance of type. | | throwIfNotType<T>(object: unknown, type: T) | Throws if the object is not of the specified type. | Throws TypeError if object is not of the given type. | | throwIfNotAnyType<T1, T2, T3>(obj: unknown, type1: T1, type2: T2, type3?: T3) | Throws if object does not match any of the specified types. | Throws TypeError if obj does not match any types. | | throwIfNotTypeArray<T>(obj: unknown, type: T) | Throws if object is not an array or any item is not of the specified type. | Throws TypeError if not an array or if any item is not of expected type. |

Type Checking

Use the TypeHelper.isType and related functions to verify the type of values at runtime.

Type Guarding

Use assertion functions to ensure values meet expected types at runtime. Multiple assertion functions are available to cover different type-checking scenarios.

import { TypeHelper } from "michi-typehelper";

function greet(name: unknown) {
	TypeHelper.throwIfNotType(name, "string");
	console.log(`Hello, ${name.toUpperCase()}!`);
}

This function throws if name is not a string, guaranteeing safe usage afterwards.

Supported Types

The TypeHelper library supports a variety of runtime type checks. Types you can use in checks fall into these categories:

1. "typeof" strings:

You can check for JavaScript primitive types using their typeof string values:

| Type String | Matches Values of Type | | ------------- | ---------------------- | | "string" | string | | "number" | number | | "bigint" | bigint | | "boolean" | boolean | | "symbol" | symbol | | "undefined" | undefined | | "object" | Any non-null object | | "function" | Any function |

TypeHelper.isType("Hello World!", "string"); // true

2. Special type strings

These special strings represent more complex or combined types:

| Type String | Matches Values of Type | | ------------ | --------------------------------------------- | | "null" | Exactly null | | "nullable" | Either null or undefined | | "array" | Any JavaScript array (Array<unknown>) | | "iterable" | Any object implementing the iterable protocol |

TypeHelper.isType(undefined, "nullable"); // true
TypeHelper.isType({ prop1: "a", prop2: "b" }, "iterable"); // true

3. Class constructors

You can pass a class constructor to check if an object is an instance of that class:

class Animal {}
class Dog extends Animal {}

const dog = new Dog();

TypeHelper.isType(dog, Dog); // true
TypeHelper.isType(dog, Animal); // true

Supports any constructor function (including built-in classes and user-defined classes).

4. Enum-like objects

You can pass an object with string or number values (like TypeScript enums) to check if a value is a member of that enum:

enum HttpStatus {
	OK = 200,
	NotFound = 404,
	InternalError = 500,
}

TypeHelper.isType(200, HttpStatus); // true
TypeHelper.isType(0, HttpStatus); // false

[!NOTE] The enum-like object check verifies if a value matches one of the enum’s defined members. However, it does not support flag enums (bitwise combinations), as it only checks for exact matches within the enum values.