| [a762898] | 1 | /**
|
|---|
| 2 | * Checks if a given value is a plain object.
|
|---|
| 3 | *
|
|---|
| 4 | * @param {object} value - The value to check.
|
|---|
| 5 | * @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|---|
| 6 | *
|
|---|
| 7 | * @example
|
|---|
| 8 | * ```typescript
|
|---|
| 9 | * // ✅👇 True
|
|---|
| 10 | *
|
|---|
| 11 | * isPlainObject({ }); // ✅
|
|---|
| 12 | * isPlainObject({ key: 'value' }); // ✅
|
|---|
| 13 | * isPlainObject({ key: new Date() }); // ✅
|
|---|
| 14 | * isPlainObject(new Object()); // ✅
|
|---|
| 15 | * isPlainObject(Object.create(null)); // ✅
|
|---|
| 16 | * isPlainObject({ nested: { key: true} }); // ✅
|
|---|
| 17 | * isPlainObject(new Proxy({}, {})); // ✅
|
|---|
| 18 | * isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
|
|---|
| 19 | *
|
|---|
| 20 | * // ✅👇 (cross-realms, node context, workers, ...)
|
|---|
| 21 | * const runInNewContext = await import('node:vm').then(
|
|---|
| 22 | * (mod) => mod.runInNewContext
|
|---|
| 23 | * );
|
|---|
| 24 | * isPlainObject(runInNewContext('({})')); // ✅
|
|---|
| 25 | *
|
|---|
| 26 | * // ❌👇 False
|
|---|
| 27 | *
|
|---|
| 28 | * class Test { };
|
|---|
| 29 | * isPlainObject(new Test()) // ❌
|
|---|
| 30 | * isPlainObject(10); // ❌
|
|---|
| 31 | * isPlainObject(null); // ❌
|
|---|
| 32 | * isPlainObject('hello'); // ❌
|
|---|
| 33 | * isPlainObject([]); // ❌
|
|---|
| 34 | * isPlainObject(new Date()); // ❌
|
|---|
| 35 | * isPlainObject(new Uint8Array([1])); // ❌
|
|---|
| 36 | * isPlainObject(Buffer.from('ABC')); // ❌
|
|---|
| 37 | * isPlainObject(Promise.resolve({})); // ❌
|
|---|
| 38 | * isPlainObject(Object.create({})); // ❌
|
|---|
| 39 | * isPlainObject(new (class Cls {})); // ❌
|
|---|
| 40 | * isPlainObject(globalThis); // ❌,
|
|---|
| 41 | * ```
|
|---|
| 42 | */
|
|---|
| 43 | declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
|
|---|
| 44 |
|
|---|
| 45 | export { isPlainObject };
|
|---|