UNPKG

predictype

Version:

PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.

26 lines (25 loc) 927 B
import { StringPatternOper } from '../../enums/strings.js'; /** * Evaluates a string against a pattern operation (matches or not matches a RegExp) using the specified operation. * * @param source The string to test. * @param oper The pattern operation to perform (e.g. 'matches', 'not_matches'). * @param pattern The RegExp to test against. * @returns True if the operation matches, false otherwise. * * @throws {Error} 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: * - **MATCHES**: String matches the RegExp pattern * - **NOT_MATCHES**: String does not match the pattern */ export declare function stringPattern(source: string, oper: StringPatternOper, pattern: RegExp): boolean;