UNPKG

sv-strutils

Version:

Simple string utilities (reverse, capitalize, vowels, palindrome)

22 lines (17 loc) 569 B
// stringutils.js function reverse(str) { return String(str).split("").reverse().join(""); } function capitalize(str) { const s = String(str); return s ? s[0].toUpperCase() + s.slice(1).toLowerCase() : s; } function countVowels(str) { const m = String(str).match(/[aeiou]/gi); return m ? m.length : 0; } function isPalindrome(str) { const cleaned = String(str).toLowerCase().replace(/[^a-z0-9]/g, ""); return cleaned === cleaned.split("").reverse().join(""); } module.exports = { reverse, capitalize, countVowels, isPalindrome };