@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
31 lines (30 loc) • 950 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPlainObject = void 0;
const isObject_js_1 = require("./isObject.js");
/**
* Determines whether the given value is a plain object.
*/
function isPlainObject(value) {
if (!(0, isObject_js_1.isObject)(value)) {
return false;
}
const constructor = value.constructor;
// If it has a modified constructor
if (constructor === undefined) {
return true;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const prototype = constructor.prototype;
// If it has a modified prototype
if (!(0, isObject_js_1.isObject)(prototype)) {
return false;
}
// If the constructor does not have an Object-specific method
if (!prototype.hasOwnProperty('isPrototypeOf')) {
return false;
}
// Most likely a plain Object
return true;
}
exports.isPlainObject = isPlainObject;