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

Function isPlainObject

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

Source from the content-addressed store, hash-verified

350
351// Copied from: https://github.com/jonschlinkert/is-plain-object
352export function isPlainObject(o: any): o is Record<PropertyKey, unknown> {
353 if (!hasObjectPrototype(o)) {
354 return false
355 }
356
357 // If has no constructor
358 const ctor = o.constructor
359 if (ctor === undefined) {
360 return true
361 }
362
363 // If has modified prototype
364 const prot = ctor.prototype
365 if (!hasObjectPrototype(prot)) {
366 return false
367 }
368
369 // If constructor does not have an Object-specific method
370 if (!prot.hasOwnProperty('isPrototypeOf')) {
371 return false
372 }
373
374 // Handles Objects created by Object.create(<arbitrary prototype>)
375 if (Object.getPrototypeOf(o) !== Object.prototype) {
376 return false
377 }
378
379 // Most likely a plain Object
380 return true
381}
382
383function hasObjectPrototype(o: any): boolean {
384 return Object.prototype.toString.call(o) === '[object Object]'

Callers 3

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

Calls 1

hasObjectPrototypeFunction · 0.85

Tested by

no test coverage detected