isObject
A utility function to check if a value is a non-null object.> isObject(value: unknown): value is Record<string, unknown>
- value (unknown): The value to check. It can be any type.
- Returns: A boolean indicating whether the value is a non-null object.
Example
import { isObject } from "@explita/daily-toolset";
// Check if a value is an object
console.log(isObject({})); // true
console.log(isObject([])); // true
console.log(isObject(null)); // false
console.log(isObject("string")); // false
console.log(isObject(42)); // false
Use Cases
- Checking if a value is a valid object before performing object-specific operations.
- Validating input data types in functions or methods.
- Safely determining if a variable holds an object or other data types like arrays or primitive values.