UNPKG
email-audit
Version:
latest (1.0.4)
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
Lightweight email validation and fraud detection library.
github.com/gtkppr/email-audit
email-audit
/
src
/
lib
/
entropy.js
14 lines
•
302 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export const shannonEntropy = (string) => { const len = string.length
if
(len ===
0
)
return
0
const freq = {}
for
(const c of string) { fre
q[c]
= (fre
q[c]
||
0
) +
1
} let entropy =
0
for
(const c in freq) { const p = fre
q[c]
/ len entropy -= p * Math.log2(p) }
return
entropy }