isPrimitive

Check if the given value is a primitive type.

Usage Scenarios

  • Type Checking: Verify if a value is primitive before performing operations that only work with primitives.
  • Performance Optimization: Skip complex object operations when dealing with primitives.
  • Type Narrowing: Narrow variable types in TypeScript.

Examples

import { isPrimitive } from 'funtool';

isPrimitive(123); // ✅ true
isPrimitive('hello'); // ✅ true
isPrimitive(null); // ✅ true
isPrimitive({}); // ❌ false

Signature

function isPrimitive(v: any): boolean

Parameters

  • v (any): The value to test if it is a primitive.

Returns

  • (boolean): Returns true if the value is a primitive, otherwise returns false.