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

Function shannonEntropy

lib/redact-patterns.ts:99–109  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

97
98/** Shannon entropy in bits/char. Used to gate env-style KV (skip placeholders). */
99export 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). */
112export function isPublicIPv4(ip: string): boolean {

Callers 2

redact-patterns.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected