1. /**
  2. * Searches for specific content within an authentication token.
  3. * This is a workaround and may not be robust against all token formats.
  4. *
  5. * @param {string} token The authentication token to search within.
  6. * @param {string} searchTerm The string to search for.
  7. * @param {object} options Optional parameters.
  8. * @param {boolean} [options.caseSensitive=false] Whether the search should be case-sensitive.
  9. * @returns {boolean} True if the search term is found, false otherwise. Returns false on invalid input.
  10. */
  11. function searchTokenContent(token, searchTerm, options = {}) {
  12. if (typeof token !== 'string' || token.length === 0) {
  13. console.warn("Invalid token provided. Token must be a non-empty string.");
  14. return false;
  15. }
  16. if (typeof searchTerm !== 'string' || searchTerm.length === 0) {
  17. console.warn("Invalid search term provided. Search term must be a non-empty string.");
  18. return false;
  19. }
  20. const caseSensitive = options.caseSensitive !== false; // Default to false (case-insensitive)
  21. let searchString = searchTerm;
  22. let tokenString = token;
  23. if (!caseSensitive) {
  24. searchString = searchString.toLowerCase();
  25. tokenString = token.toLowerCase();
  26. }
  27. return tokenString.includes(searchString); // Use includes for simple substring search
  28. }

Add your comment