ローレベルのAPI
その日に更新された1npmのパッケージは、下記URLから知ることが出来ます。
あるいは、下記コマンドからnpmのskimdbに直接アクセスします。
2016-03-12の場合
curl https://skimdb.npmjs.com/-/all/since\?stale\=update_after\&startkey\=1457708400000\&endkey\=1457794800000 -H 'host:registry.npmjs.org'
上記のjsonには、npmjs公式の右メニューStatsのように、ダウンロード件数が存在しません。
これは、npm/download-countsから知ることができます。
curl https://api.npmjs.org/downloads/point/last-day/react
# {"downloads":53949,"start":"2016-03-11","end":"2016-03-11","package":"react"}
以上を組み合わせて、「その日更新されたパッケージのダウンロード件数」を知ることが出来ます。
npm-count
npm install npm-count
前述の、ローレベルのAPIの利用を簡略化するためのモジュールを公開しました。
top10.js
const npmCount = require('npm-count');
npmCount.fetchTrending('2015-03-12')
.then((trending) => {
// sort by downloads desc, name asc
const top10 = trending
.sort((a, b) => {
if (a.downloads > b.downloads) {
return -1;
}
if (a.downloads < b.downloads) {
return 1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return -1;
}
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return 1;
}
return 0;
})
.slice(0, 10)
.map((pkg) => (
{
name: pkg.name,
downloads: pkg.downloads,
}
));
console.log(top10);
});
.fetchTrending
は、第一引数を前述のskimdbの引数に変換します(必須です)。
node top10.js
# [ { name: 'set-immediate-shim', downloads: 47693 },
# { name: 'nth-check', downloads: 29911 },
# { name: 'events-to-array', downloads: 12687 },
# { name: 'jszip', downloads: 6314 },
# { name: 'rework-plugin-function', downloads: 2835 },
# { name: 'uglifyjs', downloads: 1207 },
# { name: 'union-find', downloads: 1082 },
# { name: 'strip-debug', downloads: 898 },
# { name: 'ember-backoff', downloads: 625 },
# { name: 'jasmine-focused', downloads: 349 } ]
.fetchLastDay
から、api.npmjs.org
の最終日を取得できるので、.fetchTrending
デフォルト値を得たい場合は利用して下さい。
const npmCount = require('npm-count');
npmCount.fetchLastDay()
.then((lastday) => {
console.log(lastday);// 2016-03-11
});
npm-today.berabou.me
npm-count
にGUI2を施したものが、冒頭のスクリーンショットで載せたWEBアプリケーションです。
殆ど1ページ構成で、リンクはnpmjsへ移動します。移動済みのモジュールは灰色になります(目視の巡回を効率化させるため)。
filter by name, authors, keywords...
は検索欄です。入力後、エンターキーで結果をフィルタリングします。
リソース削減のため、500位以降は無視、jsonはgzipで保存しています。
issueの報告やPRはnpm-count
ともども受け付けていますので、よろしくお願いします。