isPlainObject
EditChecks for object literals and null-prototype records.
/** Checks whether a value is an object literal or has a null prototype. */export const isPlainObject = (value: unknown): value is Record<PropertyKey, unknown> => { if (value === null || typeof value !== "object") return false; const prototype = Object.getPrototypeOf(value); return prototype === null || prototype === Object.prototype;};Download
Section titled “Download”wget -O src/lib/isPlainObject.ts https://raw.githubusercontent.com/jrTilak/lazykit/HEAD/registry/functions/isPlainObject.tstemp_dir="$(mktemp -d)" && bunx degit jrTilak/lazykit/registry/functions "$temp_dir" && mv "$temp_dir/isPlainObject.ts" src/lib/isPlainObject.ts && rm -r "$temp_dir"Examples
Section titled “Examples”import { isPlainObject } from "./isPlainObject";
const value: unknown = JSON.parse('{"status":"ready"}');
if (isPlainObject(value)) { console.log(value.status);}value(unknown) — Candidate value.- Returns a type predicate for
Record<PropertyKey, unknown>. - Arrays, dates, functions, and class instances return
false.