kopia lustrzana https://github.com/badgen/badgen.net
Add npm download badge
rodzic
3215cba41a
commit
920a4832f7
|
@ -36,6 +36,15 @@ Available color names:
|
|||
|![](https://badgen.now.sh/badge/license/Apache-2.0/blue) | https://badgen.now.sh/badge/license/Apache-2.0/blue |
|
||||
|![](https://badgen.now.sh/list/platform/ios,macos,tvos/grey) | https://badgen.now.sh/list/platform/ios,macos,tvos/grey |
|
||||
|
||||
**Live Badge**
|
||||
|
||||
| Keyword | Preview | URL |
|
||||
| --- | --- | --- |
|
||||
| npm version | ![](https://badgen.now.sh/npm/v/express) | https://badgen.now.sh/npm/v/express |
|
||||
| npm downloads | ![](https://badgen.now.sh/npm/dd/express) | https://badgen.now.sh/npm/dd/express |
|
||||
| npm downloads | ![](https://badgen.now.sh/npm/dw/express) | https://badgen.now.sh/npm/dw/express |
|
||||
| npm downloads | ![](https://badgen.now.sh/npm/dm/express) | https://badgen.now.sh/npm/dm/express |
|
||||
|
||||
## License
|
||||
|
||||
ISC @ Amio
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
const r2 = require('r2')
|
||||
const millify = require('millify')
|
||||
|
||||
module.exports = async function (method, ...args) {
|
||||
switch (method) {
|
||||
case 'v':
|
||||
return v(args)
|
||||
case 'dd':
|
||||
return d('last-day', args)
|
||||
case 'dw':
|
||||
return d('last-week', args)
|
||||
case 'dm':
|
||||
return d('last-month', args)
|
||||
default:
|
||||
return {
|
||||
subject: 'npm',
|
||||
|
@ -13,6 +20,7 @@ module.exports = async function (method, ...args) {
|
|||
}
|
||||
}
|
||||
|
||||
// npm version
|
||||
async function v (args) {
|
||||
const version = await fetchVersion(args.join('%2F'), args[0][0] === '@')
|
||||
|
||||
|
@ -36,3 +44,14 @@ async function fetchVersion (pkg, scoped) {
|
|||
return (await r2(endpointLatest).json).version
|
||||
}
|
||||
}
|
||||
|
||||
// npm download
|
||||
async function d (period, args) {
|
||||
const endpoint = `https://api.npmjs.org/downloads/point/${period}/${args.join('/')}`
|
||||
const counts = await r2(endpoint).json
|
||||
return {
|
||||
subject: 'downloads',
|
||||
status: millify(counts.downloads) + period.replace('last-', '%2F'),
|
||||
color: 'green'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1117,6 +1117,11 @@
|
|||
"resolved": "https://registry.npmjs.org/marked/-/marked-0.4.0.tgz",
|
||||
"integrity": "sha512-tMsdNBgOsrUophCAFQl0XPe6Zqk/uy9gnue+jIIKhykO51hxyu6uNx7zBPy0+y/WKYVZZMspV9YeXLNdKk+iYw=="
|
||||
},
|
||||
"millify": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/millify/-/millify-2.0.1.tgz",
|
||||
"integrity": "sha1-PP3klrI5BLNXxiCucUCf/Y6v3QI="
|
||||
},
|
||||
"mimic-fn": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz",
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"badgen": "^1.0.1",
|
||||
"find-my-way": "^1.15.1",
|
||||
"lru-cache": "^4.1.3",
|
||||
"millify": "^2.0.1",
|
||||
"r2": "^2.0.1",
|
||||
"serve-marked": "0.0.1"
|
||||
},
|
||||
|
|
Ładowanie…
Reference in New Issue