predictype

predictype v0.8.1


predictype / predicates/strings / stringPattern

Function: stringPattern()

stringPattern(source, oper, pattern): boolean

Defined in: predicates/strings/stringPattern.ts:26

Evaluates a string against a pattern operation (matches or not matches a RegExp) using the specified operation.

Parameters

source

string

The string to test.

oper

StringPatternOper

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 str = 'foobar';
const pattern1 = /^foo/;
const pattern2 = /baz/;

stringPattern(str, 'matches', pattern1); // true
stringPattern(str, 'not_matches', pattern2); // true

Remarks

Supported Operators: