predictype

predictype v0.13.0


predictype / predicates/errors / errorName

Function: errorName()

errorName(source, oper, target): boolean

Defined in: predicates/errors/errorName.ts:28

Checks the name of an Error using the specified operation.

Parameters

source

Error

The Error to check.

oper

ErrorNameOper

The name operation to perform (e.g. ‘equals’, ‘starts_with’).

target

string

The string to compare the error name against.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const err = new TypeError('boom');

errorName(err, 'equals', 'TypeError'); // true
errorName(err, 'ends_with', 'Error'); // true
errorName(err, 'equals', 'TypeError'); // true

Remarks

Supported Operators: