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 | */
|
11 | export default function isPlainObject(value: unknown): value is object {
|
12 | if (typeof value !== 'object' || value === null) return false
|
13 |
|
14 | let proto = Object.getPrototypeOf(value)
|
15 | if (proto === null) return true
|
16 |
|
17 | let baseProto = proto
|
18 | while (Object.getPrototypeOf(baseProto) !== null) {
|
19 | baseProto = Object.getPrototypeOf(baseProto)
|
20 | }
|
21 |
|
22 | return proto === baseProto
|
23 | }
|