2022-01-11 21:40:03 +01:00
|
|
|
export function getObjectClassLabel(value: any): string {
|
|
|
|
return Object.prototype.toString.call(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isPlainObject(value: any): boolean {
|
|
|
|
if (getObjectClassLabel(value) !== '[object Object]') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const prototype = Object.getPrototypeOf(value)
|
2022-05-30 14:01:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this used to be previously:
|
|
|
|
*
|
|
|
|
* `return prototype === null || prototype === Object.prototype`
|
|
|
|
*
|
|
|
|
* but Edge Runtime expose Object from vm, being that kind of type-checking wrongly fail.
|
|
|
|
*
|
|
|
|
* It was changed to the current implementation since it's resilient to serialization.
|
|
|
|
*/
|
|
|
|
return prototype === null || prototype.hasOwnProperty('isPrototypeOf')
|
2022-01-11 21:40:03 +01:00
|
|
|
}
|