predictype
Version:
PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.
26 lines (25 loc) • 1.01 kB
TypeScript
import { StringSubstringOper } from '../../enums/strings.js';
/**
* Checks if a string contains, excludes, starts with, or ends with a substring using the specified operation.
*
* @param source The string to check.
* @param oper The substring operation to perform (e.g. 'includes', 'starts_with').
* @param target The substring to check for.
* @returns True if the substring check is valid according to the operator, otherwise false.
*
* @throws {Error} If the operation is not recognized.
*
* @example
* const str = 'foobar';
*
* stringSubstring(str, 'includes', sub); // true
* stringSubstring(str, 'starts_with', sub); // true
*
* @remarks
* Supported Operators:
* - **INCLUDES**: String includes the substring
* - **EXCLUDES**: String does not include the substring
* - **STARTS_WITH**: String starts with the substring
* - **ENDS_WITH**: String ends with the substring
*/
export declare function stringSubstring(source: string, oper: StringSubstringOper, target: string): boolean;