mana-common
Version:
Common utils for mana
23 lines (19 loc) • 733 B
JavaScript
export function getPropertyDescriptor(o, propertyName) {
let proto = o;
let descriptor = undefined;
while (proto && !descriptor) {
descriptor = Object.getOwnPropertyDescriptor(proto, propertyName);
proto = Object.getPrototypeOf(proto);
}
return descriptor;
}
export function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null || // window/navigator/Global
Object.prototype.toString.call(obj) !== '[object Object]') return false;
const proto = Object.getPrototypeOf(obj);
if (proto === null) {
return true;
}
const ctor = proto.hasOwnProperty('constructor') && proto.constructor;
return typeof ctor == 'function' && ctor instanceof ctor && ctor.toString() === Object.toString();
}