predictype

predictype v0.13.0


predictype / predicates/regexps/regexpPattern / regexpPattern

Function: regexpPattern()

regexpPattern(pattern, oper, target): boolean

Defined in: predicates/regexps/regexpPattern.ts:29

Checks the pattern string of a RegExp using the specified operation.

Parameters

pattern

RegExp

The RegExp pattern to check.

oper

RegExpPatternOper

The pattern operation to perform (e.g. ‘equals’, ‘includes’).

target

string

The string to compare against the RegExp pattern source.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const pattern = /^user_[a-z]+$/;
const targetA = '^user_';
const targetB = 'admin';

regexpPattern(pattern, 'starts_with', targetA); // true
regexpPattern(pattern, 'excludes', targetB); // true

Remarks

Supported Operators: