npm.js 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // all npm authors sorted by number of repos
  2. var fs = require('fs')
  3. , clarinet = require('../clarinet')
  4. , parse_stream = clarinet.createStream()
  5. , author = false
  6. , authors = {}
  7. ;
  8. parse_stream.on('openobject', function(name) {
  9. if(name==='author') author=true;
  10. });
  11. parse_stream.on('key', function(name) {
  12. if(name==='author') author=true;
  13. });
  14. parse_stream.on('end', function () {
  15. var sorted = []
  16. , i
  17. ;
  18. for (var a in authors)
  19. sorted.push([a, authors[a]]);
  20. sorted.sort(function(a, b) { return a[1] - b[1]; });
  21. i = sorted.length-1;
  22. while(i!==-1) {
  23. console.log(sorted.length-i, sorted[i]);
  24. i--;
  25. }
  26. });
  27. parse_stream.on('value', function(value) {
  28. if(author) {
  29. var current_count = authors[value];
  30. if (current_count) authors[value] +=1;
  31. else authors[value] = 1;
  32. author=false;
  33. }
  34. });
  35. fs.createReadStream(__dirname + '/npm.json').pipe(parse_stream);