UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

30 lines (28 loc) 664 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/function/isPrimitive.ts /** * `isPrimitive(value)` * * Checks if a value is a primitive type (string, number, boolean, null, undefined, symbol, bigint). * * ```ts * isPrimitive("hello"); // true * isPrimitive(42); // true * isPrimitive({}); // false * isPrimitive([]); // false * ``` * * ```ts * pipe("hello", isPrimitive()); // true * pipe({}, isPrimitive()); // false * ``` */ const isPrimitive = dfdlT((value) => { if (value == null) return true; const t = typeof value; if (t === "object") return false; if (t === "function") return false; return true; }, 1); //#endregion export { isPrimitive };