Simplify isPojo
This commit is contained in:
@@ -174,26 +174,11 @@ export const ellipsize = (s: string, l: number, suffix = '...') => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const isPojo = (obj: any) => {
|
export const isPojo = (obj: any) => {
|
||||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
if (obj === null || typeof obj !== "object") {
|
||||||
const toString = Object.prototype.toString
|
|
||||||
|
|
||||||
// Detect obvious negatives use toString to catch host objects
|
|
||||||
if (obj === null || toString.call(obj) !== '[object Object]') {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const proto = Object.getPrototypeOf(obj)
|
return Object.getPrototypeOf(obj) === Object.prototype
|
||||||
// Objects with no prototype (e.g., `Object.create( null )`) are plain
|
|
||||||
if (!proto) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Objects with prototype are plain iff constructed by `Object` function
|
|
||||||
const ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor
|
|
||||||
return (
|
|
||||||
typeof ctor === 'function' &&
|
|
||||||
hasOwnProperty.toString.call(ctor) === hasOwnProperty.toString.call(Object)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const equals = (a: any, b: any) => {
|
export const equals = (a: any, b: any) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user