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

Function isPlainObject

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

Source from the content-addressed store, hash-verified

474 * @returns `true` if `o` is a plain object.
475 */
476export 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]`.

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