isObject
Returns true if `value` is a plain object, a class instance (excluding built-in classes like Date/RegExp), or an `Object.create(null)` result. Objects from [other realms][1] are also supported. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms
Usage
isObject({}); // trueisObject(new Object()); // trueisObject(Object.create(null)); // trueisObject(new (class {})()); // true
isObject([]); // falseisObject(/.+/g); // falseisObject(new Date()); // falseisObject(new Map()); // falseisObject(new Set()); // false
Installation
npx atmx add helper is-object
Copy and paste the following method into @/utils/helpers/undefined.ts
:
import { isTagged } from "@/helpers/is-tagged.ts";
/*** Returns true if `value` is a plain object, a class instance* (excluding built-in classes like Date/RegExp), or an* `Object.create(null)` result. Objects from [other realms][1] are* also supported.** [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms** @example* isObject({}) // true* isObject(new Object()) // true* isObject(Object.create(null)) // true* isObject(new class {}) // true** isObject([]) // false* isObject(/.+/g) // false* isObject(new Date()) // false* isObject(new Map()) // false* isObject(new Set()) // false*/export function isObject(value: unknown): value is object {return isTagged(value, "[object Object]");}