Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Created July 20, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdehaan/17689268626dc4b247b6895264df0dc6 to your computer and use it in GitHub Desktop.
Save pdehaan/17689268626dc4b247b6895264df0dc6 to your computer and use it in GitHub Desktop.
HIBP DataClass count
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const HIBP_URL = "https://haveibeenpwned.com/api/v3/breaches";
const breaches = await fetch(HIBP_URL).then(res => res.json());
const count = breaches.length;
const stats = breaches.reduce((stats, breach) => {
const count = breach.DataClasses.length;
if (count in stats) {
stats[count].push(stringify(breach));
} else {
stats[count] = [stringify(breach)];
}
return stats;
}, {});
let sum = 0;
console.log("DATACLASSES | BREACHES\n----|----")
for (const [dataClassCount, breaches] of Object.entries(stats)) {
sum += breaches.length;
const pct = Intl.NumberFormat("en", { style: "percent" }).format(sum / count);
console.log(`${dataClassCount} | ${breaches.length} (${pct})`);
}
function stringify({Title, Name}) {
return `${Title} (${Name})`;
}
@pdehaan
Copy link
Author

pdehaan commented Jul 20, 2023

DATACLASSES BREACHES
1 7 (1%)
2 71 (11%)
3 89 (24%)
4 153 (47%)
5 96 (61%)
6 85 (73%)
7 60 (82%)
8 45 (89%)
9 20 (92%)
10 21 (95%)
11 11 (96%)
12 8 (98%)
13 5 (98%)
14 1 (99%)
15 2 (99%)
16 3 (99%)
17 1 (99%)
19 1 (100%)
20 2 (100%)
25 1 (100%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment