@mcptoolshop/registry-stats 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.zh.md CHANGED
@@ -3,30 +3,35 @@
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <img src="assets/logo.png" alt="registry-stats 标志" width="280" />
6
+ <img src="https://raw.githubusercontent.com/mcp-tool-shop-org/brand/main/logos/registry-stats/readme.png" alt="registry-stats logo" width="400" />
7
7
  </p>
8
8
 
9
- <h1 align="center">@mcptoolshop/registry-stats</h1>
9
+ <p align="center">
10
+ One command. Five registries. All your download stats.
11
+ </p>
10
12
 
11
13
  <p align="center">
12
- 一个命令。五个注册表。所有下载统计。
14
+ <a href="https://github.com/mcp-tool-shop-org/registry-stats/actions/workflows/pages.yml"><img src="https://github.com/mcp-tool-shop-org/registry-stats/actions/workflows/pages.yml/badge.svg" alt="CI"></a>
15
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT License"></a>
16
+ <a href="https://www.npmjs.com/package/@mcptoolshop/registry-stats"><img src="https://img.shields.io/npm/v/@mcptoolshop/registry-stats" alt="npm version"></a>
17
+ <a href="https://mcp-tool-shop-org.github.io/registry-stats/"><img src="https://img.shields.io/badge/Landing_Page-live-blue" alt="Landing Page"></a>
13
18
  </p>
14
19
 
15
20
  <p align="center">
16
- <a href="https://mcp-tool-shop-org.github.io/registry-stats/">文档</a> &middot;
17
- <a href="#安装">安装</a> &middot;
21
+ <a href="https://mcp-tool-shop-org.github.io/registry-stats/">Docs</a> &middot;
22
+ <a href="#install">Install</a> &middot;
18
23
  <a href="#cli">CLI</a> &middot;
19
- <a href="#配置文件">配置</a> &middot;
20
- <a href="#编程接口">API</a> &middot;
21
- <a href="#rest-api-服务器">REST 服务器</a> &middot;
22
- <a href="#许可证">许可证</a>
24
+ <a href="#config-file">Config</a> &middot;
25
+ <a href="#programmatic-api">API</a> &middot;
26
+ <a href="#rest-api-server">REST Server</a> &middot;
27
+ <a href="#license">License</a>
23
28
  </p>
24
29
 
25
30
  ---
26
31
 
27
- 如果你在 npm、PyPI、NuGet、VS Code Marketplace 或 Docker Hub 上发布包,你目前需要五个不同的 API 来回答"这个月我有多少下载量?"这个库提供统一接口 支持 CLI 和编程方式。
32
+ 如果您将软件包发布到 npm、PyPI、NuGet、VS Code Marketplace 或 Docker Hub,目前您需要使用五个不同的 API 来回答“我这个月下载了多少次?”。这个库为您提供一个统一的接口,用于访问所有这些平台,可以通过命令行界面 (CLI) 或编程 API 使用。
28
33
 
29
- 零依赖。使用原生 `fetch()`。Node 18+。
34
+ 无任何依赖。使用原生的 `fetch()` 方法。Node 18 及以上版本。
30
35
 
31
36
  ## 安装
32
37
 
@@ -34,47 +39,61 @@
34
39
  npm install @mcptoolshop/registry-stats
35
40
  ```
36
41
 
37
- ## CLI
42
+ ## 命令行界面 (CLI)
38
43
 
39
44
  ```bash
40
- # 查询单个注册表
45
+ # Query a single registry
41
46
  registry-stats express -r npm
47
+ # npm | express
48
+ # month: 283,472,710 week: 67,367,773 day: 11,566,113
42
49
 
43
- # 一次查询所有注册表
50
+ # Query all registries at once
44
51
  registry-stats express
45
52
 
46
- # 带月度细分和趋势的时间序列
53
+ # Time series with monthly breakdown + trend
47
54
  registry-stats express -r npm --range 2025-01-01:2025-06-30
55
+ # 2025-01 142,359,021
56
+ # 2025-02 147,522,528
57
+ # ...
58
+ # Total: 448,383,383 Avg/day: 4,982,038 Trend: flat (-0.46%)
48
59
 
49
- # JSON 输出
60
+ # Raw JSON output
50
61
  registry-stats express -r npm --json
51
62
 
52
- # 其他注册表
63
+ # Other registries
53
64
  registry-stats requests -r pypi
54
65
  registry-stats Newtonsoft.Json -r nuget
55
66
  registry-stats esbenp.prettier-vscode -r vscode
56
67
  registry-stats library/node -r docker
57
68
 
58
- # 创建配置文件
69
+ # Create a config file
59
70
  registry-stats --init
60
71
 
61
- # 从配置运行获取所有跟踪包的统计
72
+ # Run with config fetches all tracked packages
62
73
  registry-stats
63
74
 
64
- # 跨注册表比较
75
+ # Compare across registries
65
76
  registry-stats express --compare
66
-
67
- # 导出为 CSV 或图表友好的 JSON
77
+ # express — comparison
78
+ #
79
+ # Metric npm pypi
80
+ # ─────────────────────────────────
81
+ # Total - -
82
+ # Month 283,472 47,201
83
+ # Week 67,367 11,800
84
+ # Day 11,566 1,686
85
+
86
+ # Export as CSV or chart-friendly JSON
68
87
  registry-stats express -r npm --range 2025-01-01:2025-06-30 --format csv
69
88
  registry-stats express -r npm --range 2025-01-01:2025-06-30 --format chart
70
89
 
71
- # 启动 REST API 服务器
90
+ # Start a REST API server
72
91
  registry-stats serve --port 3000
73
92
  ```
74
93
 
75
94
  ## 配置文件
76
95
 
77
- 在项目根目录创建 `registry-stats.config.json`(或运行 `registry-stats --init`):
96
+ 在您的项目根目录下创建一个 `registry-stats.config.json` 文件(或者运行 `registry-stats --init` 命令):
78
97
 
79
98
  ```json
80
99
  {
@@ -95,91 +114,110 @@ registry-stats serve --port 3000
95
114
  }
96
115
  ```
97
116
 
98
- 不带参数运行 `registry-stats` 即可获取所有配置包的统计。CLI 会从当前目录向上查找配置文件。
117
+ 运行 `registry-stats` 命令,不带任何参数,即可获取所有配置软件包的统计数据。命令行界面会从当前工作目录向上查找最近的配置文件。
118
+
119
+ 配置文件也可以通过编程方式访问:
120
+
121
+ ```typescript
122
+ import { loadConfig, defaultConfig, starterConfig } from '@mcptoolshop/registry-stats';
123
+
124
+ const config = loadConfig(); // finds nearest config file, or null
125
+ const defaults = defaultConfig(); // returns default Config object
126
+ const template = starterConfig(); // returns starter JSON string
127
+ ```
99
128
 
100
- ## 编程接口
129
+ ## 编程 API
101
130
 
102
131
  ```typescript
103
132
  import { stats, calc, createCache } from '@mcptoolshop/registry-stats';
104
133
 
105
- // 单个注册表
134
+ // Single registry
106
135
  const npm = await stats('npm', 'express');
107
136
  const pypi = await stats('pypi', 'requests');
137
+ const nuget = await stats('nuget', 'Newtonsoft.Json');
138
+ const vscode = await stats('vscode', 'esbenp.prettier-vscode');
139
+ const docker = await stats('docker', 'library/node');
108
140
 
109
- // 所有注册表(使用 Promise.allSettled — 永不抛出)
141
+ // All registries at once (uses Promise.allSettled — never throws)
110
142
  const all = await stats.all('express');
111
143
 
112
- // 批量多个包,并发限制(默认:5
144
+ // Bulkmultiple packages, concurrency-limited (default: 5)
113
145
  const bulk = await stats.bulk('npm', ['express', 'koa', 'fastify']);
114
146
 
115
- // 时间序列(仅 npm + pypi
147
+ // Time series (npm + pypi only)
116
148
  const daily = await stats.range('npm', 'express', '2025-01-01', '2025-06-30');
117
149
 
118
- // 计算
119
- calc.total(daily); // 下载总量
120
- calc.avg(daily); // 日均量
150
+ // Calculations
151
+ calc.total(daily); // sum of all downloads
152
+ calc.avg(daily); // daily average
153
+ calc.groupTotals(calc.monthly(daily)); // { '2025-01': 134982, ... }
121
154
  calc.trend(daily); // { direction: 'up', changePercent: 8.3 }
122
- calc.movingAvg(daily, 7); // 7天移动平均
123
- calc.popularity(daily); // 0-100 对数刻度评分
155
+ calc.movingAvg(daily, 7); // 7-day moving average
156
+ calc.popularity(daily); // 0-100 log-scale score
124
157
 
125
- // 导出格式
126
- calc.toCSV(daily); // CSV 字符串
127
- calc.toChartData(daily, 'express'); // { labels: [...], datasets: [...] }
158
+ // Export formats
159
+ calc.toCSV(daily); // "date,downloads\n2025-01-01,1234\n..."
160
+ calc.toChartData(daily, 'express'); // { labels: [...], datasets: [{ label, data }] }
128
161
 
129
- // 比较跨注册表的同一包
162
+ // Comparisonsame package across registries
130
163
  const comparison = await stats.compare('express');
131
- await stats.compare('express', ['npm', 'pypi']);
164
+ // → { package: 'express', registries: { npm: {...}, pypi: {...} }, fetchedAt: '...' }
165
+ await stats.compare('express', ['npm', 'pypi']); // specific registries only
132
166
 
133
- // 缓存(5分钟 TTL,内存中)
167
+ // Caching (5 min TTL, in-memory)
134
168
  const cache = createCache();
135
- await stats('npm', 'express', { cache });
169
+ await stats('npm', 'express', { cache }); // fetches
170
+ await stats('npm', 'express', { cache }); // cache hit
136
171
  ```
137
172
 
138
- ## 注册表支持
173
+ ## 仓库支持
139
174
 
140
- | 注册表 | 包格式 | 时间序列 | 可用数据 |
141
- |--------|--------|----------|----------|
142
- | `npm` | `express`, `@scope/pkg` | 支持(549天) | lastDay, lastWeek, lastMonth |
143
- | `pypi` | `requests` | 支持(180天) | lastDay, lastWeek, lastMonth, total |
144
- | `nuget` | `Newtonsoft.Json` | 不支持 | total |
145
- | `vscode` | `publisher.extension` | 不支持 | total(安装数)、rating、trends |
146
- | `docker` | `namespace/repo` | 不支持 | total(拉取数)、stars |
175
+ | 仓库 | 软件包格式 | 时间序列 | 可用数据 |
176
+ | ---------- | --------------- | ------------- | ---------------- |
177
+ | `npm` | `express`, `@scope/pkg` | 是 (549 天) | 最近一天、最近一周、最近一个月 |
178
+ | `pypi` | `requests` | 是 (180 天) | 最近一天、最近一周、最近一个月、总数 |
179
+ | `nuget` | `Newtonsoft.Json` | No | 总数 |
180
+ | `vscode` | `publisher.extension` | No | 总数(安装量)、评分、趋势 |
181
+ | `docker` | `namespace/repo` | No | 总数(拉取次数)、星级 |
147
182
 
148
183
  ## 内置可靠性
149
184
 
150
- - 429/5xx 错误的指数退避自动重试
151
- - 遵守 `Retry-After` 头部
185
+ - 自动重试,并在遇到 429/5xx 错误时采用指数退避策略
186
+ - 尊重 `Retry-After` 头部信息
152
187
  - 批量请求的并发限制
153
- - 可选的 TTL 缓存(可插拔 — 通过 `StatsCache` 接口使用 Redis/文件后端)
188
+ - 可选的 TTL 缓存(可插拔,通过 `StatsCache` 接口,您可以自定义 Redis 或文件后端)
154
189
 
155
190
  ## REST API 服务器
156
191
 
157
- 作为微服务运行,或嵌入到自己的服务器中:
192
+ 可以作为微服务运行,也可以嵌入到您自己的服务器中:
158
193
 
159
194
  ```bash
195
+ # CLI
160
196
  registry-stats serve --port 3000
161
197
  ```
162
198
 
163
199
  ```
164
- GET /stats/:package # 所有注册表
165
- GET /stats/:registry/:package # 单个注册表
200
+ GET /stats/:package # all registries
201
+ GET /stats/:registry/:package # single registry
166
202
  GET /compare/:package?registries=npm,pypi
167
203
  GET /range/:registry/:package?start=YYYY-MM-DD&end=YYYY-MM-DD&format=json|csv|chart
168
204
  ```
169
205
 
206
+ 用于自定义服务器或无服务器环境的编程用法:
207
+
170
208
  ```typescript
171
209
  import { createHandler, serve } from '@mcptoolshop/registry-stats';
172
210
 
173
- // 快速启动
211
+ // Option 1: Quick start
174
212
  serve({ port: 3000 });
175
213
 
176
- // 自定义服务器
214
+ // Option 2: Bring your own server
177
215
  import { createServer } from 'node:http';
178
216
  const handler = createHandler();
179
217
  createServer(handler).listen(3000);
180
218
  ```
181
219
 
182
- ## 自定义注册表
220
+ ## 自定义仓库
183
221
 
184
222
  ```typescript
185
223
  import { registerProvider, type RegistryProvider } from '@mcptoolshop/registry-stats';
@@ -202,6 +240,18 @@ registerProvider(cargo);
202
240
  await stats('cargo', 'serde');
203
241
  ```
204
242
 
243
+ ## 网站
244
+
245
+ 网站和主页位于 `site/` 目录下。
246
+
247
+ - 开发:`npm run site:dev`
248
+ - 构建:`npm run site:build`
249
+ - 预览:`npm run site:preview`
250
+
205
251
  ## 许可证
206
252
 
207
253
  MIT
254
+
255
+ ---
256
+
257
+ 由 <a href="https://mcp-tool-shop.github.io/">MCP Tool Shop</a> 构建。
package/assets/logo.png CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcptoolshop/registry-stats",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Multi-registry download stats for npm, PyPI, NuGet, VS Code Marketplace, and Docker Hub",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",