UNPKG

@c_s_v_s_subrahmanyam/string-utils

Version:

A comprehensive utility library for advanced string operations.

27 lines (20 loc) 837 B
// Validators for strings module.exports = { isEmail: (str) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str), isURL: (str) => /^(https?:\/\/)?([\w\d-]+\.){1,}\w{2,}(\/[\w\d-_.]*)*\/?$/.test(str), isPalindrome: (str) => { const cleaned = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase(); return cleaned === cleaned.split('').reverse().join(''); }, isAlphanumeric: (str) => /^[a-zA-Z0-9]+$/.test(str), isDigit: (str) => /^\d+$/.test(str), isSpace: (str) => /^\s+$/.test(str), passwordStrength: (password) => { if (password.length < 8) return 'Weak'; if (!/[A-Z]/.test(password)) return 'Medium'; if (!/[0-9]/.test(password)) return 'Medium'; if (!/[!@#$%^&*]/.test(password)) return 'Medium'; return 'Strong'; }, };