UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

59 lines (58 loc) 1.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPlainObject = void 0; const getTag_1 = __importDefault(require("./.internal/getTag")); const isObjectLike_1 = __importDefault(require("./isObjectLike")); /** * @ignore */ const objectTag = "[object Object]"; /** * @ignore */ const objectCtorString = Function.prototype.toString.call(Object); /** * Checks if `value` is a plain object, that is, an object created by the * `Object` constructor or one with a `[[Prototype]]` of `null`. * * @since 5.6.0 * @category Lang * @param value The value to check. * @returns Returns `true` if `value` is a plain object, else `false`. * @example * * ```js * function Foo() { * this.a = 1 * } * * isPlainObject(new Foo) * // => false * * isPlainObject([1, 2, 3]) * // => false * * isPlainObject({ 'x': 0, 'y': 0 }) * // => true * * isPlainObject(Object.create(null)) * // => true * ``` */ function isPlainObject(value) { if (!(0, isObjectLike_1.default)(value) || (0, getTag_1.default)(value) != objectTag) { return false; } const proto = Object.getPrototypeOf(value); if (proto === null) { return true; } const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor; return typeof Ctor == "function" && Ctor instanceof Ctor && Function.prototype.toString.call(Ctor) == objectCtorString; } exports.isPlainObject = isPlainObject; exports.default = isPlainObject;