Skip to content

Instantly share code, notes, and snippets.

@malko
Created February 4, 2014 13:33
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 malko/8803623 to your computer and use it in GitHub Desktop.
Save malko/8803623 to your computer and use it in GitHub Desktop.
get monthly npm statistics for given package name
function npmMonthlyStats(pkgName){
var xhr=new XMLHttpRequest()
, rows
, obj={}
;
xhr.open('GET','https://isaacs.iriscouch.com/downloads/_design/app/_view/pkg?group_level=2&start_key=%5B%22' + pkgName + '%22%5D&end_key=%5B%22' + pkgName + '%22,%7B%7D%5D', false);
xhr.send();
rows=JSON.parse(xhr.responseText).rows;
rows.forEach(function(v,k){
var d = v.key[1].slice(0,7);
obj[d] = (obj[d] || 0) + v.value;
});
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment