File size: 943 Bytes
5fae594 |
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 |
// all npm authors sorted by number of repos
var fs = require('fs')
, clarinet = require('../clarinet')
, parse_stream = clarinet.createStream()
, author = false
, authors = {}
;
parse_stream.on('openobject', function(name) {
if(name==='author') author=true;
});
parse_stream.on('key', function(name) {
if(name==='author') author=true;
});
parse_stream.on('end', function () {
var sorted = []
, i
;
for (var a in authors)
sorted.push([a, authors[a]]);
sorted.sort(function(a, b) { return a[1] - b[1]; });
i = sorted.length-1;
while(i!==-1) {
console.log(sorted.length-i, sorted[i]);
i--;
}
});
parse_stream.on('value', function(value) {
if(author) {
var current_count = authors[value];
if (current_count) authors[value] +=1;
else authors[value] = 1;
author=false;
}
});
fs.createReadStream(__dirname + '/npm.json').pipe(parse_stream); |