The value to check.
True if the value is a plain object or array, false otherwise.
const obj = { a: 1, b: 2, c: 3 };
isPlainContainer(obj) // true
isPlainContainer([1, 2, 3]) // true
isPlainContainer(1) // false
isPlainContainer("hello") // false
isPlainContainer(null) // false
isPlainContainer(undefined) // false
export function isPlainContainer(v: unknown): v is object {
if (v == null || typeof v !== "object") return false;
if (Array.isArray(v)) return true;
const proto = Object.getPrototypeOf(v);
return proto === Object.prototype || proto === null;
}
Check if a value is a plain object or array.