JavaScript and TypeScript type checking utility functions providing precise type validation with automatic type narrowing.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Fundamental type checking functions for JavaScript primitives and basic types. All functions are TypeScript type guards that provide automatic type narrowing.
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)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));
}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)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"); // falseReturns 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); // falseReturns 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(""); // falseReturns 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