Skip to main content

isPrimitive

A function that checks whether a given argument is a primitive value, and if so, narrows the type of the argument to Primitive.


Code

🔗 View source code

Interface

typescript
type Primitive =
| string
| number
| boolean
| symbol
| bigint
| null
| undefined;

const isPrimitive: (value: unknown) => value is Primitive

Usage

typescript
import { isPrimitive } from '@modern-kit/utils';

isPrimitive(123); // true
isPrimitive('123'); // true
isPrimitive(true); // true
isPrimitive(Symbol()); // true
isPrimitive(null); // true
isPrimitive(undefined); // true

isPrimitive({}); // false
isPrimitive([]); // false
isPrimitive(new Set()); // false
isPrimitive(new Map()); // false