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

Function isPlainObject

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

Source from the content-addressed store, hash-verified

412
413// Copied from: https://github.com/jonschlinkert/is-plain-object
414export 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
450function hasObjectPrototype(o: any): boolean {
451 return Object.prototype.toString.call(o) === '[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