@monstermann/fn
Version:
A utility library for TypeScript.
30 lines (28 loc) • 679 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/object/isObject.ts
/**
* `isObject(target)`
*
* Checks if `target` is a plain object.
*
* ```ts
* isObject({ a: 1 }); // true
* isObject([]); // false
* isObject(null); // false
* isObject("hello"); // false
* ```
*
* ```ts
* pipe({ a: 1 }, isObject()); // true
* pipe([], isObject()); // false
* pipe(null, isObject()); // false
* pipe("hello", isObject()); // false
* ```
*/
const isObject = dfdlT((target) => {
if (typeof target !== "object" || target === null) return false;
const proto = Object.getPrototypeOf(target);
return proto === null || proto === Object.prototype;
}, 1);
//#endregion
export { isObject };