(s: string)
| 97 | |
| 98 | /** Shannon entropy in bits/char. Used to gate env-style KV (skip placeholders). */ |
| 99 | export function shannonEntropy(s: string): number { |
| 100 | if (!s.length) return 0; |
| 101 | const freq: Record<string, number> = {}; |
| 102 | for (const ch of s) freq[ch] = (freq[ch] || 0) + 1; |
| 103 | let h = 0; |
| 104 | for (const ch in freq) { |
| 105 | const p = freq[ch] / s.length; |
| 106 | h -= p * Math.log2(p); |
| 107 | } |
| 108 | return h; |
| 109 | } |
| 110 | |
| 111 | /** True when an IPv4 string is a public address (not RFC1918/loopback/etc). */ |
| 112 | export function isPublicIPv4(ip: string): boolean { |
no outgoing calls
no test coverage detected