stringzy
Version:
A versatile string manipulation library providing a range of text utilities for JavaScript and Node.js applications.
22 lines (21 loc) • 715 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPalindrome = isPalindrome;
/**
* Checks whether the given string is a palindrome.
*
* The check is case-insensitive and ignores all non-alphanumeric characters.
*
* @param {string} str - The input string to check.
* @returns {boolean} True if the input is a palindrome, false otherwise.
* @throws {TypeError} If the input is not a string.
*/
function isPalindrome(str) {
if (typeof str !== 'string') {
throw new TypeError('Input must be a string');
}
const sanitized = str
.toLowerCase()
.replace(/[^a-z0-9]/gi, '');
return sanitized === sanitized.split('').reverse().join('');
}
;