UNPKG

nhb-toolbox

Version:

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

60 lines (59 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPalindrome = void 0; exports.isCamelCase = isCamelCase; exports.isPascalCase = isPascalCase; exports.isSnakeCase = isSnakeCase; exports.isKebabCase = isKebabCase; exports.isEmojiOnly = isEmojiOnly; const convert_1 = require("./convert"); /** * * Checks if a string is a palindrome. * @param input - The string to check. * @returns True if the string is a palindrome, otherwise false. */ const isPalindrome = (input) => { const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, ''); return normalized === (0, convert_1.reverseString)(normalized); }; exports.isPalindrome = isPalindrome; /** * * Checks if a string is in camelCase format. * @param str The string to check. * @returns `true` if the string is in camelCase, otherwise `false`. */ 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`. */ 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`. */ 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`. */ 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`. */ function isEmojiOnly(str) { return /^[\p{Emoji}]+$/u.test(str); }