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

Function isPlainObject

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

Source from the content-addressed store, hash-verified

359
360// Copied from: https://github.com/jonschlinkert/is-plain-object
361export function isPlainObject(o: any): o is Record<PropertyKey, unknown> {
362 if (!hasObjectPrototype(o)) {
363 return false
364 }
365
366 // If has no constructor
367 const ctor = o.constructor
368 if (ctor === undefined) {
369 return true
370 }
371
372 // If has modified prototype
373 const prot = ctor.prototype
374 if (!hasObjectPrototype(prot)) {
375 return false
376 }
377
378 // If constructor does not have an Object-specific method
379 if (!prot.hasOwnProperty('isPrototypeOf')) {
380 return false
381 }
382
383 // Handles Objects created by Object.create(<arbitrary prototype>)
384 if (Object.getPrototypeOf(o) !== Object.prototype) {
385 return false
386 }
387
388 // Most likely a plain Object
389 return true
390}
391
392function hasObjectPrototype(o: any): boolean {
393 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