predictype

predictype v0.13.0


predictype / predicates/regexps/regexpState / regexpState

Function: regexpState()

regexpState(source, oper): boolean

Defined in: predicates/regexps/regexpState.ts:33

Checks the state of a RegExp (flags and pattern shape) using the specified operation.

Parameters

source

RegExp

The RegExp to check.

oper

RegExpStateOper

The state operation to perform (e.g. ‘is_global’, ‘has_indices’).

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const sourceA = /foo/gi;
const sourceB = new RegExp('');

regexpState(sourceA, 'is_global'); // true
regexpState(sourceA, 'is_ignore_case'); // true
regexpState(sourceB, 'is_empty_pattern'); // true

Remarks

Supported Operators: