LoginSignup
22
22

More than 5 years have passed since last update.

npmのトレンドを知る

Last updated at Posted at 2016-03-12


スクリーンショット_2016-03-12_15_42_27.png

ローレベルの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'

参考:日ごとの人気パッケージを知りたい - watilde/npm#4

上記の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-count API Reference - a npm/download-counts wrapper

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ともども受け付けていますので、よろしくお願いします。


  1. UTC一日前の集計結果です。 

  2. React+Material-UI+Redux+ReactRouterなど…サーバーはexpress+mocha、クライアントはwebpack-dev-serverで開発を行いました。 

22
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
22