(o: any)
| 474 | * @returns `true` if `o` is a plain object. |
| 475 | */ |
| 476 | export function isPlainObject(o: any): o is Record<PropertyKey, unknown> { |
| 477 | if (!hasObjectPrototype(o)) { |
| 478 | return false |
| 479 | } |
| 480 | |
| 481 | // If has no constructor |
| 482 | const objectPrototype = Object.getPrototypeOf(o) |
| 483 | const ctor = objectPrototype?.constructor |
| 484 | if (ctor === undefined) { |
| 485 | return true |
| 486 | } |
| 487 | |
| 488 | if (typeof ctor !== 'function') { |
| 489 | return false |
| 490 | } |
| 491 | |
| 492 | // If has modified prototype |
| 493 | const prot = ctor.prototype |
| 494 | if (!hasObjectPrototype(prot)) { |
| 495 | return false |
| 496 | } |
| 497 | |
| 498 | // If constructor does not have an Object-specific method |
| 499 | if (!prot.hasOwnProperty('isPrototypeOf')) { |
| 500 | return false |
| 501 | } |
| 502 | |
| 503 | // Handles Objects created by Object.create(<arbitrary prototype>) |
| 504 | if (objectPrototype !== Object.prototype) { |
| 505 | return false |
| 506 | } |
| 507 | |
| 508 | // Most likely a plain Object |
| 509 | return true |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * Checks whether a value's `Object.prototype.toString` tag is `[object Object]`. |
no test coverage detected