LendAndRegret/node_modules/es-toolkit/dist/compat/predicate/isPlainObject.js
2026-05-02 17:27:43 +08:00

34 lines
953 B
JavaScript

'use strict';
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;