(o: any)
| 412 | |
| 413 | // Copied from: https://github.com/jonschlinkert/is-plain-object |
| 414 | export function isPlainObject(o: any): o is Record<PropertyKey, unknown> { |
| 415 | if (!hasObjectPrototype(o)) { |
| 416 | return false |
| 417 | } |
| 418 | |
| 419 | // If has no constructor |
| 420 | const objectPrototype = Object.getPrototypeOf(o) |
| 421 | const ctor = objectPrototype?.constructor |
| 422 | if (ctor === undefined) { |
| 423 | return true |
| 424 | } |
| 425 | |
| 426 | if (typeof ctor !== 'function') { |
| 427 | return false |
| 428 | } |
| 429 | |
| 430 | // If has modified prototype |
| 431 | const prot = ctor.prototype |
| 432 | if (!hasObjectPrototype(prot)) { |
| 433 | return false |
| 434 | } |
| 435 | |
| 436 | // If constructor does not have an Object-specific method |
| 437 | if (!prot.hasOwnProperty('isPrototypeOf')) { |
| 438 | return false |
| 439 | } |
| 440 | |
| 441 | // Handles Objects created by Object.create(<arbitrary prototype>) |
| 442 | if (objectPrototype !== Object.prototype) { |
| 443 | return false |
| 444 | } |
| 445 | |
| 446 | // Most likely a plain Object |
| 447 | return true |
| 448 | } |
| 449 | |
| 450 | function hasObjectPrototype(o: any): boolean { |
| 451 | return Object.prototype.toString.call(o) === '[object Object]' |
no test coverage detected