MCPcopy
hub / github.com/garrytan/gstack / luhnValid

Function luhnValid

lib/redact-patterns.ts:81–96  ·  view source on GitHub ↗
(span: string)

Source from the content-addressed store, hash-verified

79
80/** Luhn checksum — credit-card validity. Strips spaces/dashes first. */
81export 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). */
99export function shannonEntropy(s: string): number {

Callers 2

redact-patterns.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected