UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

32 lines 1.31 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isPalindrome; /** * Checks if a given string is a palindrome. * A string is considered a palindrome if it reads the same backward as forward, * ignoring case, spaces, and non-alphanumeric characters. * * @param str - The string to check. * @returns True if the string is a palindrome, false otherwise. * * @example * isPalindrome("A man, a plan, a canal: Panama"); // Output: true * isPalindrome("hello"); // Output: false */ function isPalindrome(str) { // Normalize the string: remove non-alphanumeric characters, convert to lowercase const normalized = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase(); // Compare the normalized string to its reverse return normalized === normalized.split('').reverse().join(''); } }); //# sourceMappingURL=isPalindrome.js.map