📦 Checks if a value is a plain object.

Info

A plain object is an object created by the {} object literal or one created with Object.create(null).

Syntax

TypeScript
import { isPlainObject } from '@opentf/std';

isPlainObject(val: unknown): val is Record<string, unknown>

Parameters

  • val: The value to check.

Returns

true if the value is a plain object, false otherwise.

Examples

TypeScript
isPlainObject({}) //=> true

isPlainObject({ a: 1 }) //=> true

isPlainObject(Object.create(null)) //=> true

isPlainObject(new Object()) //=> true

// Non-plain objects
isPlainObject([]) //=> false

isPlainObject(new Map()) //=> false

isPlainObject(new Error()) //=> false

isPlainObject(null) //=> false
Last updated on
Edit this page