Created
February 4, 2014 13:33
-
-
Save malko/8803623 to your computer and use it in GitHub Desktop.
get monthly npm statistics for given package name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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