/**
* Searches for specific content within an authentication token.
* This is a workaround and may not be robust against all token formats.
*
* @param {string} token The authentication token to search within.
* @param {string} searchTerm The string to search for.
* @param {object} options Optional parameters.
* @param {boolean} [options.caseSensitive=false] Whether the search should be case-sensitive.
* @returns {boolean} True if the search term is found, false otherwise. Returns false on invalid input.
*/
function searchTokenContent(token, searchTerm, options = {}) {
if (typeof token !== 'string' || token.length === 0) {
console.warn("Invalid token provided. Token must be a non-empty string.");
return false;
}
if (typeof searchTerm !== 'string' || searchTerm.length === 0) {
console.warn("Invalid search term provided. Search term must be a non-empty string.");
return false;
}
const caseSensitive = options.caseSensitive !== false; // Default to false (case-insensitive)
let searchString = searchTerm;
let tokenString = token;
if (!caseSensitive) {
searchString = searchString.toLowerCase();
tokenString = token.toLowerCase();
}
return tokenString.includes(searchString); // Use includes for simple substring search
}
Add your comment