predictype

predictype v0.8.1


predictype / predicates/objects / objectAttributes

Function: objectAttributes()

objectAttributes(source, oper, key): boolean

Defined in: predicates/objects/objectAttributes.ts:32

Checks object property attributes (writable, enumerable, configurable, accessor, data property) using the specified operation.

Parameters

source

object

The object to check.

oper

ObjectAttributesOper

The attribute operation to perform (e.g. ‘is_writable’, ‘is_accessor’).

key

The property key to check.

string symbol

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const obj = { foo: 42 };
const obj2 = {};
const sym = Symbol('bar');

Object.defineProperty(obj2, sym, { value: 1, writable: false });

objectAttributes(obj, 'is_writable', 'foo'); // true
objectAttributes(obj2, 'is_writable', sym); // false

Remarks

Supported Operators: