Type guards and predicates for common JavaScript values.
Checks use standard JavaScript and web-platform types available in current
browsers, Node, Deno, and Bun. A true type-guard result narrows the input
to the type shown in its signature.
import is from "@rcompat/is";is.array#
Checks whether a value is an array.
is.array(x: unknown): x is unknown[];is.arraybuffer#
Checks whether a value is an ArrayBuffer.
is.arraybuffer(x: unknown): x is ArrayBuffer;is.bigint#
Checks whether a value is a bigint.
is.bigint(x: unknown): x is bigint;is.blank#
Checks whether a value is an empty or whitespace-only string.
is.blank(x: unknown): x is string;is.blob#
Checks whether a value is a Blob.
is.blob(x: unknown): x is Blob;is.boolish#
Checks whether a value is the string "true" or "false".
is.boolish(x: unknown): x is Boolish;is.boolean#
Checks whether a value is a boolean.
is.boolean(x: unknown): x is boolean;is.branded#
Checks whether an object owns a symbol brand.
is.branded<S extends symbol>(
x: unknown,
brand: S,
): x is Record<S, () => unknown>;is.bytes#
Checks whether a value is a Uint8Array.
is.bytes(x: unknown): x is Uint8Array;is.date#
Checks whether a value is a Date.
is.date(x: unknown): x is Date;is.defined#
Checks whether a value is not undefined.
is.defined<T>(x: T): x is Exclude<T, undefined>;is.dict#
Checks whether a value is a plain object.
is.dict(x: unknown): x is Dict;is.empty#
Checks whether a string, collection, or object is empty.
is.empty(x: unknown): boolean;is.error#
Checks whether a value is an Error.
is.error(x: unknown): x is Error;is.f32#
Checks whether a number is exactly representable as a float32.
is.f32(x: unknown): x is number;is.f32array#
Checks whether a value is a Float32Array.
is.f32array(x: unknown): x is Float32Array;is.f64array#
Checks whether a value is a Float64Array.
is.f64array(x: unknown): x is Float64Array;is.falsy#
Checks whether a value is falsy.
is.falsy(x: unknown): boolean;is.file#
Checks whether a value is a File.
is.file(x: unknown): x is File;is.finite#
Checks whether a value is a finite number or bigint.
is.finite(x: unknown): x is bigint | number;is.function#
Checks whether a value is callable.
is.function(x: unknown): x is UnknownFunction;is.int#
Checks whether a value is an integer number or bigint.
is.int(x: unknown): x is bigint | number;is.iterable#
Checks whether a value implements the iterable protocol.
is.iterable(x: unknown): x is Iterable<unknown>;is.json#
Checks whether a value can be represented in JSON.
is.json(x: unknown): x is JSONValue;is.map#
Checks whether a value is a Map.
is.map(x: unknown): x is Map<unknown, unknown>;is.nan#
Checks whether a value is NaN.
is.nan(x: unknown): x is number;is.nonempty#
Checks whether a nullable value is nonempty.
is.nonempty<T>(x: T | Nullish): x is T;is.newable#
Checks whether a value is constructible with new.
is.newable(x: unknown): x is Newable;is.null#
Checks whether a value is null.
is.null(x: unknown): x is null;is.nullish#
Checks whether a value is null or undefined.
is.nullish(x: unknown): x is Nullish;is.number#
Checks whether a value is a number, including NaN.
is.number(x: unknown): x is number;is.numeric#
Checks whether a value is a decimal numeric string.
is.numeric(x: unknown): x is string;is.object#
Checks whether a value is a non-null object.
is.object(x: unknown): x is object;is.primitive#
Checks whether a value is a JavaScript primitive.
is.primitive(x: unknown): x is Primitive;is.promise#
Checks whether a value is a Promise.
is.promise(x: unknown): x is Promise<unknown>;is.request#
Checks whether a value is a Request.
is.request(x: unknown): x is Request;is.response#
Checks whether a value is a Response.
is.response(x: unknown): x is Response;is.regexp#
Checks whether a value is a regular expression.
is.regexp(x: unknown): x is RegExp;is.safeint#
Checks whether a value is a safe integer number.
is.safeint(x: unknown): x is number;is.set#
Checks whether a value is a Set.
is.set(x: unknown): x is Set<unknown>;is.stream#
Checks whether a value is a readable web stream.
is.stream(x: unknown): x is ReadableStream;is.string#
Checks whether a value is a string.
is.string(x: unknown): x is string;is.symbol#
Checks whether a value is a symbol.
is.symbol(x: unknown): x is symbol;is.text#
Checks whether a value is a nonempty, non-whitespace string.
is.text(x: unknown): x is string;is.truthy#
Checks whether a value is truthy and narrows out falsy literals.
is.truthy<T>(
x: T,
): x is Exclude<T, "" | 0 | 0n | false | null | undefined>;is.typedarray#
Checks whether a value is an ArrayBuffer view.
is.typedarray(x: unknown): x is ArrayBufferView;is.uint#
Checks whether a value is a non-negative integer or bigint.
is.uint(x: unknown): x is bigint | number;is.undefined#
Checks whether a value is undefined.
is.undefined(x: unknown): x is undefined;is.url#
Checks whether a value is a URL.
is.url(x: unknown): x is URL;is.versioned#
Checks whether an object owns the requested global version brand.
Throws: If brand is not global or the object has another version of it.
is.versioned(x: unknown, brand: symbol): boolean;