UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

51 lines (50 loc) 1.57 kB
import { reverseString } from './convert.js'; /** * * Checks if a string is a palindrome. * @param input - The string to check. * @returns True if the string is a palindrome, otherwise false. */ export const isPalindrome = (input) => { const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, ''); return normalized === reverseString(normalized); }; /** * * Checks if a string is in camelCase format. * @param str The string to check. * @returns `true` if the string is in camelCase, otherwise `false`. */ export function isCamelCase(str) { return /^[a-z]+([A-Z][a-z]*)*$/.test(str); } /** * * Checks if a string is in PascalCase format. * @param str The string to check. * @returns `true` if the string is in PascalCase, otherwise `false`. */ export function isPascalCase(str) { return /^[A-Z][a-zA-Z]*$/.test(str); } /** * * Checks if a string is in snake_case format. * @param str The string to check. * @returns `true` if the string is in snake_case, otherwise `false`. */ export function isSnakeCase(str) { return /^[a-z]+(_[a-z]+)*$/.test(str); } /** * * Checks if a string is in kebab-case format. * @param str The string to check. * @returns `true` if the string is in kebab-case, otherwise `false`. */ export function isKebabCase(str) { return /^[a-z]+(-[a-z]+)*$/.test(str); } /** * * Checks if a string contains only emojis. * @param str The string to check. * @returns `true` if the string contains only emojis, otherwise `false`. */ export function isEmojiOnly(str) { return /^[\p{Emoji}]+$/u.test(str); }