es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
34 lines (30 loc) • 953 B
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function isPlainObject(object) {
if (typeof object !== 'object') {
return false;
}
if (object == null) {
return false;
}
if (Object.getPrototypeOf(object) === null) {
return true;
}
if (Object.prototype.toString.call(object) !== '[object Object]') {
const tag = object[Symbol.toStringTag];
if (tag == null) {
return false;
}
const isTagReadonly = !Object.getOwnPropertyDescriptor(object, Symbol.toStringTag)?.writable;
if (isTagReadonly) {
return false;
}
return object.toString() === `[object ${tag}]`;
}
let proto = object;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(object) === proto;
}
exports.isPlainObject = isPlainObject;