API reference@evolu/commonObject › isPlainObject

function isPlainObject(value: unknown): value is Record<string, unknown>;

Defined in: packages/common/src/Object.ts:81

Checks if a value is a plain object (e.g., created with {} or Object).

Accepts objects with a null prototype. Otherwise, it uses a realm-neutral structural heuristic: the immediate prototype must be a root object with own hasOwnProperty and isPrototypeOf properties. This recognizes ordinary Objects from another JavaScript realm without relying on prototype identity.

A custom root prototype with the same shape can therefore be classified as plain. This function assumes trusted JavaScript and is not a prototype authentication or security boundary. Other custom prototypes, class instances, and built-in objects are rejected.

Example

import { assertFalse, assertTrue, isPlainObject } from "@evolu/common";

class Example {
  readonly value = "example";
}

assertTrue(isPlainObject({}));
assertTrue(isPlainObject(Object.create(null)));
assertFalse(isPlainObject(new Date()));
assertFalse(isPlainObject(new Example()));
assertFalse(isPlainObject([]));
assertFalse(isPlainObject(null));