predictype

predictype v0.13.0


predictype / predicates/errors / errorNamePattern

Function: errorNamePattern()

errorNamePattern(source, oper, pattern): boolean

Defined in: predicates/errors/errorNamePattern.ts:25

Evaluates an error name against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters

source

Error

The Error whose name will be tested.

oper

ErrorNamePatternOper

The pattern operation to perform (e.g. ‘matches’, ‘not_matches’).

pattern

RegExp

The RegExp to test against.

Returns

boolean

True if the operation matches, false otherwise.

Throws

If the operation is not recognized.

Example

const err = new TypeError('boom');

errorNamePattern(err, 'matches', /Type/); // true
errorNamePattern(err, 'not_matches', /Range/); // true

Remarks

Supported Operators: