定制 developmint/npm-stats-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

developmint/npm-stats-api

Composer 安装命令:

composer require developmint/npm-stats-api

包简介

Fetch stats for your NPM packages

README 文档

README

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

This package makes it easy to retrieve stats for packages hosted on npmjs.com

PS: It's heavily inspired by the packagist-api package made from Spatie

Installation

You can install the package via composer:

composer require developmint/npm-stats-api

Usage

You must pass a Guzzle client to the constructor of Developmint\NpmStats\NpmStats.

$client = new \GuzzleHttp\Client();

$npmStats = new \Developmint\NpmStats\NpmStats($client);

Get stats for a package of your choice

$npmStats->getStats('jquery');

Get stats with a period of your choice

Use a constant provided by the NpmStats class to get stats for the last day, week, month, year or in total.

$npmStats->getStats('jquery', NpmStats::LAST_DAY);

You can also pass in specific dates

$npmStats->getStats('jquery', '2017-01-01');

Or even ranges

$npmStats->getStats('jquery', '2014-02-07:2014-02-14');

The output will be already decoded from json:

array(4) {
  ["downloads"]=>
  int(198672)
  ["start"]=>
  string(10) "2017-10-10"
  ["end"]=>
  string(10) "2017-10-10"
  ["package"]=>
  string(6) "jquery"
}

Get stats with a period of your choice as range

You can also get the stats as a range, means the downloads split up per day:

$npmStats->getStats('jquery', NpmStats::LAST_WEEK, true);

And this would be the result of that call:

array(4) {
  ["start"]=>
  string(10) "2017-10-04"
  ["end"]=>
  string(10) "2017-10-10"
  ["package"]=>
  string(6) "jquery"
  ["downloads"]=>
  array(7) {
    [0]=>
    array(2) {
      ["downloads"]=>
      int(200678)
      ["day"]=>
      string(10) "2017-10-04"
    }
    [1]=>
    array(2) {
      ["downloads"]=>
      int(195593)
      ["day"]=>
      string(10) "2017-10-05"
    }
    [2]=>
    array(2) {
      ["downloads"]=>
      int(172132)
      ["day"]=>
      string(10) "2017-10-06"
    }
    [3]=>
    array(2) {
      ["downloads"]=>
      int(51068)
      ["day"]=>
      string(10) "2017-10-07"
    }
    [4]=>
    array(2) {
      ["downloads"]=>
      int(46892)
      ["day"]=>
      string(10) "2017-10-08"
    }
    [5]=>
    array(2) {
      ["downloads"]=>
      int(171920)
      ["day"]=>
      string(10) "2017-10-09"
    }
    [6]=>
    array(2) {
      ["downloads"]=>
      int(198672)
      ["day"]=>
      string(10) "2017-10-10"
    }
  }
}

Get bulk stats

Of course you can retrieve up to 128 packages as a bulk query. Simply separate them with a command and you are good to go.

$npmStats->getStats('vue,express', NpmStats::LAST_WEEK);

But beware! This only works in point mode, not in range mode.

$npmStats->getStats('vue,express', NpmStats::LAST_WEEK, true);
//Won't work

Anyway, the output will look similar to the normal point mode output:

array(2) {
  ["vue"]=>
  array(4) {
    ["downloads"]=>
    int(3980980980098089080980983)
    ["package"]=>
    string(5) "vue"
    ["start"]=>
    string(10) "2017-10-10"
    ["end"]=>
    string(10) "2017-10-10"
  }
  ["express"]=>
  array(4) {
    ["downloads"]=>
    int(818264)
    ["package"]=>
    string(7) "express"
    ["start"]=>
    string(10) "2017-10-10"
    ["end"]=>
    string(10) "2017-10-10"
  }
}

More in-depth info about the NPM stats API

You can find a detailed explanation about how the stats API of NPM works in this repository README file

Limits of the API

The official limits are:

  • Bulk queries: 128 packages at a time and at most 365 days of data
  • All other queries: limited to at most 18 months of data
  • Earliest date available: January 10, 2015

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email support@developmint.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

developmint/npm-stats-api 适用场景与选型建议

developmint/npm-stats-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.66k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2017 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「stats」 「npm」 「developmint」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 developmint/npm-stats-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 developmint/npm-stats-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 developmint/npm-stats-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-11