/**
* @module strings
* @description This module contains routines for strings manipulation
*/
'use strict';
/**
* This is a function that checks if a text string matches a specified pattern,
* which can be provided either as a plain string or a regular expression
* @param {string} text - Text string for pattern matching
* @param {string} pattern - Pattern for matching
* @param {string} [isRegExp] - Flag indicating that the pattern is a regular
* expression
* @param {string} [flags] - String with a set of flags for matching text
* against a regular expression<br>
* <p><b>Flags for regular expressions:</b></p>
* <ul>
* <li>'i' - Case-insensitive matching</li>
* <li>'g' - Global matching (finds all matches, not just the first one)</li>
* <li>'m' - Multiline mode</li>
* <li>'s' - Dotall mode, where the dot . matches any character including
* newlines</li>
* <li>'u' - Enables full Unicode support, allowing correct handling of
* surrogate pairs</li>
* <li>'y' - Sticky mode for searching at a particular position in the text</li>
* </ul>
* @example
* let
* text = 'test',
* pattern = 'Te.*',
* flags = 'i',
* result;
*
* result = isTextMatch(text, pattern, true, flags);
*
* console.log(result); // true
* @returns {boolean} True if the pattern matches. Else - false
*/
export function isTextMatch(text, pattern, isRegExp, flags) {
let result = false;
if (isRegExp) {
text = text ?? '';
let re = new RegExp(pattern, flags);
result = re.test(text);
} else
result = (text === pattern);
return result;
}