This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtop.js
52 lines (43 loc) · 1.56 KB
/
top.js
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
52
var npm = require('npm');
var Hash = require('traverse/hash');
var sprintf = require('sprintf').sprintf;
npm.load({ outfd : null }, function () {
npm.commands.list(['latest'], function (err, pkgs) {
var authors = {};
var total = Hash(pkgs).length;
Hash(pkgs).forEach(function (pkg) {
var user = pkg.words[0].slice(1);
authors[user] = (authors[user] || 0) + 1;
});
console.log('rank percent packages author');
console.log('---- ------- -------- ------');
var sorted = Object.keys(authors)
.sort(function (a,b) {
return authors[b] - authors[a] || (a.toLowerCase() < b.toLowerCase() ? -1 : 1)
})
;
var limit = process.argv[2] || 15;
var start = 0;
if (!limit.toString().match(/^\d+$/)) {
var who = process.argv[2];
start = sorted.indexOf(who);
limit = 1;
}
var fairRank = 1;
var lastVal = -1;
sorted
.slice(start, start + limit)
.forEach(function (name, rank) {
var percent = (authors[name] / total) * 100;
if(authors[name] == lastVal)
rank = fairRank;
console.log(sprintf(
'# %2d %.2f %% %4d %s',
rank + start + 1 , percent, authors[name], name
));
lastVal = authors[name];
fairRank = rank;
})
;
});
});