UNPKG

685 BPlain TextView Raw
1/**
2 * Returns true if the passed value is "plain" object, i.e. an object whose
3 * prototype is the root `Object.prototype`. This includes objects created
4 * using object literals, but not for instance for class instances.
5 *
6 * @param {any} value The value to inspect.
7 * @returns {boolean} True if the argument appears to be a plain object.
8 *
9 * @public
10 */
11export default function isPlainObject(value: unknown): value is object {
12 if (typeof value !== 'object' || value === null) return false
13
14 let proto = value
15 while (Object.getPrototypeOf(proto) !== null) {
16 proto = Object.getPrototypeOf(proto)
17 }
18
19 return Object.getPrototypeOf(value) === proto
20}