(span: string)
| 79 | |
| 80 | /** Luhn checksum — credit-card validity. Strips spaces/dashes first. */ |
| 81 | export function luhnValid(span: string): boolean { |
| 82 | const digits = span.replace(/[ \-]/g, ""); |
| 83 | if (!/^\d{13,19}$/.test(digits)) return false; |
| 84 | let sum = 0; |
| 85 | let alt = false; |
| 86 | for (let i = digits.length - 1; i >= 0; i--) { |
| 87 | let d = digits.charCodeAt(i) - 48; |
| 88 | if (alt) { |
| 89 | d *= 2; |
| 90 | if (d > 9) d -= 9; |
| 91 | } |
| 92 | sum += d; |
| 93 | alt = !alt; |
| 94 | } |
| 95 | return sum % 10 === 0; |
| 96 | } |
| 97 | |
| 98 | /** Shannon entropy in bits/char. Used to gate env-style KV (skip placeholders). */ |
| 99 | export function shannonEntropy(s: string): number { |
no outgoing calls
no test coverage detected