isPlainObject

Verifica si un valor es un objeto JavaScript simple (no array, null, etc).

#data #type-guard #utility
export const isPlainObject = (value: unknown): value is Record<string, unknown> =>
Object.prototype.toString.call(value) === '[object Object]';
// Usage
isPlainObject({}); // true
isPlainObject({ a: 1 }); // true
isPlainObject([]); // false
isPlainObject(null); // false
isPlainObject(new Date); // false

Comparte este snippet

Comentarios