UNPKG

fui-fancyui

Version:
34 lines (33 loc) 958 B
function z(t, i) { let e = 0; const n = t.length; n >= 16 ? e += 35 : n >= 12 ? e += 25 : n >= 8 && (e += 10); const a = /[a-z]/.test(t), l = /[A-Z]/.test(t), r = /[0-9]/.test(t), f = /[^a-zA-Z0-9]/.test(t); a && (e += 10), l && (e += 10), r && (e += 10), f && (e += 20), [ "0123456789", "9876543210", "qwertyuiop", "asdfghjkl", "zxcvbnm", "password", "admin", "123456", "iloveyou" // Added more common patterns ].some((o) => t.includes(o)) && (e -= 15); const h = t.split("").reverse().join(""); t.toLowerCase() === h.toLowerCase() && (e -= 10); const m = /(.)\1{2,}/g; let s; for (; (s = m.exec(t)) !== null; ) e -= (s[0].length - 2) * 2; if (i) for (const o of i) { const c = o.toLowerCase().replace(/[^a-z0-9]/g, ""); t.toLowerCase().replace(/[^a-z0-9]/g, "").includes(c) && (e -= c.length); } return Math.max(0, e); } export { z as calculatePasswordStrength };