JavaScript Type Checking Utilities

5.5.0 · active · verified Sun Apr 19

`is-what` is a lightweight, fully TypeScript-supported utility library providing a comprehensive set of functions for JavaScript type checking, such as `isPlainObject()`, `isArray()`, `isString()`, and many more specific checks. Currently at version `5.5.0`, the library maintains a steady release cadence, frequently adding new type-checking utilities and dependency updates. Its core differentiators include a focus on simplicity, a small footprint, robust TypeScript type inference (automatically narrowing types after checks), and a more intuitive handling of edge cases like `NaN` compared to native JavaScript functions. It explicitly distinguishes between plain objects (`{}`) and class instances, addressing a common pain point in JavaScript development. The library aims to be a straightforward and reliable alternative to more complex or less type-safe existing solutions. Its `v5.x` releases moved to ESM-only and refined its TypeScript integration.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic type checking with `is-what`, including special handling for `NaN` and `isPlainObject`.

import { isString, isNumber, isPlainObject, isArray, isDate, isNaNValue, isHexDecimal } from 'is-what';

console.log('Is "hello" a string?', isString('hello')); // true
console.log('Is 123 a number?', isNumber(123)); // true
console.log('Is NaN a number (is-what)?', isNumber(NaN)); // false, by design
console.log('Is NaN truly NaN?', isNaNValue(NaN)); // true
console.log('Is {} a plain object?', isPlainObject({})); // true
console.log('Is new Date() a plain object?', isPlainObject(new Date())); // false
console.log('Is [] an array?', isArray([])); // true
console.log('Is new Date() a Date object?', isDate(new Date())); // true
console.log('Is an invalid date a Date object?', isDate(new Date('invalid date'))); // false
console.log('Is "60adf084f0fbdcab42de841e" a hex decimal of length 24?', isHexDecimal('60adf084f0fbdcab42de841e', 24)); // true

view raw JSON →