-
Notifications
You must be signed in to change notification settings - Fork 0
/
npm.html
51 lines (42 loc) · 1.45 KB
/
npm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>monthly downloads of @jspsych & @jspsych-contrib scoped packages</h1>
<div id="data-display"></div>
</body>
<script>
async function run() {
const package_list = await fetch(
"https://registry.npmjs.org/-/v1/search?text=scope:jspsych&size=250"
).then((response) => response.json());
const package_list_contrib = await fetch(
"https://registry.npmjs.org/-/v1/search?text=scope:jspsych-contrib&size=250"
).then((response) => response.json());
const packages = package_list.objects.concat(package_list_contrib.objects).map(x => x.package.name);
packages.push("jspsych");
const npm_data = [];
for (const package of packages) {
fetch(`https://api.npmjs.org/downloads/point/last-month/${package}`)
.then(function (response) {
return response.json();
})
.then(function (data) {
npm_data.push(data);
npm_data.sort((a,b)=>b.downloads - a.downloads);
pretty_print_data(npm_data, '#data-display');
});
}
console.log(npm_data);
}
function pretty_print_data(npm_data, target){
let html = '<table>';
for(const row of npm_data){
html += `<tr><td>${row.package}</td><td>${row.downloads}</td></tr>`
}
html += `</table>`;
document.querySelector(target).innerHTML = html;
}
run();
</script>
</html>