API reference › @evolu/common › Object › isPlainObject
function isPlainObject(value: unknown): value is Record<string, unknown>;
Defined in: packages/common/src/Object.ts:119
Checks if a value is a plain object (e.g., created with {} or Object).
Accepts objects with a null prototype or emptyPrototype, which
inherit nothing, and so does any other frozen, empty prototype without a
prototype, such as another copy's emptyPrototype. 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,
emptyPrototype,
isPlainObject,
} from "@evolu/common";
class Example {
readonly value = "example";
}
assertTrue(isPlainObject({}));
assertTrue(isPlainObject(Object.create(null)));
assertTrue(isPlainObject(Object.create(emptyPrototype)));
assertFalse(isPlainObject(new Date()));
assertFalse(isPlainObject(new Example()));
assertFalse(isPlainObject([]));
assertFalse(isPlainObject(null));