predictype

predictype v0.13.0


predictype / predicates/objects/objectProperty / objectProperty

Function: objectProperty()

objectProperty(source, oper, key): boolean

Defined in: predicates/objects/objectProperty.ts:28

Checks if an object has or lacks a property (own or inherited) using the specified operation.

Parameters

source

object

The object to check.

oper

ObjectPropertyOper

The property operation to perform (e.g. ‘contains_property’, ‘lacks_own_property’).

key

string | symbol

The property key to check.

Returns

boolean

True if the property check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const source = Object.create({ inherited: true });
source.own = 42;

objectProperty(source, 'contains_property', 'inherited'); // true
objectProperty(source, 'contains_own_property', 'own'); // true
objectProperty(source, 'lacks_own_property', 'inherited'); // true

Remarks

Supported Operators: