CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-what

JavaScript and TypeScript type checking utility functions providing precise type validation with automatic type narrowing.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

basic-types.mddocs/

Basic Type Checking

Fundamental type checking functions for JavaScript primitives and basic types. All functions are TypeScript type guards that provide automatic type narrowing.

Capabilities

String Type Checking

Returns whether the payload is a string.

/**
 * Returns whether the payload is a string
 * @param payload - Value to check
 * @returns Type guard indicating if payload is string
 */
function isString(payload: unknown): payload is string;

Usage Examples:

import { isString } from "is-what";

if (isString("hello")) {
  // TypeScript knows this is a string
  console.log("hello".toUpperCase()); // "HELLO"
}

isString("text"); // true
isString(123); // false
isString(new String("text")); // false (String object, not primitive)

Number Type Checking

Returns whether the payload is a number (but not NaN). This function specifically excludes NaN values.

/**
 * Returns whether the payload is a number (but not NaN)
 * This will return false for NaN
 * @param payload - Value to check
 * @returns Type guard indicating if payload is number (excluding NaN)
 */
function isNumber(payload: unknown): payload is number;

Usage Examples:

import { isNumber } from "is-what";

isNumber(42); // true
isNumber(3.14); // true
isNumber(NaN); // false (special case!)
isNumber("123"); // false
isNumber(new Number(123)); // false (Number object, not primitive)

if (isNumber(value)) {
  // Safe to use number methods
  console.log(value.toFixed(2));
}

Boolean Type Checking

Returns whether the payload is a boolean.

/**
 * Returns whether the payload is a boolean
 * @param payload - Value to check
 * @returns Type guard indicating if payload is boolean
 */
function isBoolean(payload: unknown): payload is boolean;

Usage Examples:

import { isBoolean } from "is-what";

isBoolean(true); // true
isBoolean(false); // true
isBoolean("true"); // false
isBoolean(1); // false
isBoolean(new Boolean(true)); // false (Boolean object, not primitive)

BigInt Type Checking

Returns whether the payload is a bigint.

/**
 * Returns whether the payload is a bigint
 * @param payload - Value to check
 * @returns Type guard indicating if payload is bigint
 */
function isBigInt(payload: unknown): payload is bigint;

Usage Examples:

import { isBigInt } from "is-what";

isBigInt(123n); // true
isBigInt(BigInt(123)); // true
isBigInt(123); // false
isBigInt("123n"); // false

Symbol Type Checking

Returns whether the payload is a symbol.

/**
 * Returns whether the payload is a symbol
 * @param payload - Value to check
 * @returns Type guard indicating if payload is symbol
 */
function isSymbol(payload: unknown): payload is symbol;

Usage Examples:

import { isSymbol } from "is-what";

isSymbol(Symbol("test")); // true
isSymbol(Symbol.iterator); // true
isSymbol("symbol"); // false
isSymbol(123); // false

Null Type Checking

Returns whether the payload is null.

/**
 * Returns whether the payload is null
 * @param payload - Value to check
 * @returns Type guard indicating if payload is null
 */
function isNull(payload: unknown): payload is null;

Usage Examples:

import { isNull } from "is-what";

isNull(null); // true
isNull(undefined); // false
isNull(0); // false
isNull(""); // false

Undefined Type Checking

Returns whether the payload is undefined.

/**
 * Returns whether the payload is undefined
 * @param payload - Value to check
 * @returns Type guard indicating if payload is undefined
 */
function isUndefined(payload: unknown): payload is undefined;

Usage Examples:

import { isUndefined } from "is-what";

isUndefined(undefined); // true
isUndefined(null); // false
isUndefined(0); // false
isUndefined(""); // false

let x;
isUndefined(x); // true

docs

advanced-types.md

array-types.md

basic-types.md

builtin-types.md

generic-utils.md

index.md

number-validation.md

object-types.md

string-types.md

tile.json