UNPKG

673 BTypeScriptView Raw
1/**
2Check if a value is a plain object.
3
4An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.
5
6@example
7```
8import isPlainObject from 'is-plain-obj';
9import {runInNewContext} from 'node:vm';
10
11isPlainObject({foo: 'bar'});
12//=> true
13
14isPlainObject(new Object());
15//=> true
16
17isPlainObject(Object.create(null));
18//=> true
19
20// This works across realms
21isPlainObject(runInNewContext('({})'));
22//=> true
23
24isPlainObject([1, 2, 3]);
25//=> false
26
27class Unicorn {}
28isPlainObject(new Unicorn());
29//=> false
30
31isPlainObject(Math);
32//=> false
33```
34*/
35export default function isPlainObject<Value>(value: unknown): value is Record<PropertyKey, Value>;