MCPcopy Create free account
hub / github.com/TanStack/query / isPlainObject

Function isPlainObject

packages/query-core/src/utils.ts:480–514  ·  view source on GitHub ↗
(o: any)

Source from the content-addressed store, hash-verified

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

Callers 4

utils.test-d.tsxFile · 0.90
utils.test.tsxFile · 0.90
hashKeyFunction · 0.70
replaceEqualDeepFunction · 0.70

Calls 1

hasObjectPrototypeFunction · 0.85

Tested by

no test coverage detected