remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 1.61 kB
Source Map (JSON)
{"version":3,"file":"isObjectType.cjs","names":[],"sources":["../src/isObjectType.ts"],"sourcesContent":["import type { NarrowedTo } from \"./internal/types/NarrowedTo\";\n\n/**\n * Checks if the given parameter is of type `\"object\"` via `typeof`, excluding `null`.\n *\n * It's important to note that in JavaScript, many entities are considered objects, like Arrays, Classes, RegExps, Maps, Sets, Dates, URLs, Promise, Errors, and more. Although technically an object too, `null` is not considered an object by this function, so that its easier to narrow nullables.\n *\n * For a more specific check that is limited to plain objects (simple struct/shape/record-like objects), consider using `isPlainObject` instead. For a simpler check that only removes `null` from the type prefer `isNonNull` or `isDefined`.\n *\n * @param data - The variable to be checked for being an object type.\n * @returns The input type, narrowed to only objects.\n * @signature\n * R.isObjectType(data)\n * @example\n * // true\n * R.isObjectType({}) //=> true\n * R.isObjectType([]) //=> true\n * R.isObjectType(Promise.resolve(\"something\")) //=> true\n * R.isObjectType(new Date()) //=> true\n * R.isObjectType(new Error(\"error\")) //=> true\n *\n * // false\n * R.isObjectType('somethingElse') //=> false\n * R.isObjectType(null) //=> false\n * @dataFirst\n * @category Guard\n */\nexport function isObjectType<T>(\n data: T | object,\n): data is NarrowedTo<T, object> {\n return typeof data === \"object\" && data !== null;\n}\n"],"mappings":"AA2BA,SAAgB,EACd,EAC+B,CAC/B,OAAO,OAAO,GAAS,YAAY"}