@monstermann/fn
Version:
A utility library for TypeScript.
24 lines (22 loc) • 540 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/object/hasProp.ts
/**
* `hasProp(target, key)`
*
* Checks if `target` object has the specified `key` property with a non-null and non-undefined value.
*
* ```ts
* hasProp({ a: 1, b: null }, "a"); // true
* hasProp({ a: 1, b: null }, "b"); // false
* ```
*
* ```ts
* pipe({ a: 1, b: null }, hasProp("a")); // true
* pipe({ a: 1, b: null }, hasProp("b")); // false
* ```
*/
const hasProp = dfdlT((target, key) => {
return target[key] != null;
}, 2);
//#endregion
export { hasProp };