kopia lustrzana https://github.com/badgen/badgen.net
rodzic
3baec6ab22
commit
d7fd3011d7
|
@ -212,9 +212,10 @@ module.exports = {
|
|||
['arbitrary url', '/badgesize/normal/https://unpkg.com/snarkdown/dist/snarkdown.js']
|
||||
],
|
||||
jsdelivr: [
|
||||
['hits (per month)', '/jsdelivr/stats/gh/jquery/jquery'],
|
||||
['hits (per month)', '/jsdelivr/stats/npm/lodash'],
|
||||
['rank', '/jsdelivr/rank/npm/lodash']
|
||||
['hits (per month)', '/jsdelivr/hits/gh/jquery/jquery'],
|
||||
['hits (per month)', '/jsdelivr/hits/npm/lodash'],
|
||||
['rank', '/jsdelivr/rank/npm/lodash'],
|
||||
['version', '/jsdelivr/v/npm/lodash']
|
||||
],
|
||||
/* utilities */
|
||||
'opencollective': [
|
||||
|
|
|
@ -277,9 +277,10 @@ Advanced usage (for badge makers):
|
|||
['arbitrary url', '/badgesize/normal/https://unpkg.com/snarkdown/dist/snarkdown.js']
|
||||
],
|
||||
jsdelivr: [
|
||||
['hits (per month)', '/jsdelivr/stats/gh/jquery/jquery'],
|
||||
['hits (per month)', '/jsdelivr/stats/npm/lodash'],
|
||||
['hits (per month)', '/jsdelivr/hits/gh/jquery/jquery'],
|
||||
['hits (per month)', '/jsdelivr/hits/npm/lodash'],
|
||||
['rank', '/jsdelivr/rank/npm/lodash'],
|
||||
['version', '/jsdelivr/v/npm/lodash'],
|
||||
],
|
||||
/* utilities */
|
||||
'opencollective': [
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
const got = require('../got.js')
|
||||
const millify = require('millify')
|
||||
const semColor = require('../utils/sem-color.js')
|
||||
|
||||
module.exports = async (topic, type, ...name) => {
|
||||
if (!['stats', 'rank'].includes(topic)) {
|
||||
if (!['hits', 'rank', 'v'].includes(topic)) {
|
||||
return {
|
||||
subject: 'jsDelivr',
|
||||
status: 'unknown topic',
|
||||
|
@ -11,11 +12,23 @@ module.exports = async (topic, type, ...name) => {
|
|||
}
|
||||
|
||||
const pkg = name.join('/')
|
||||
const endpoint = `https://data.jsdelivr.com/v1/package/${type}/${pkg}/stats`
|
||||
const { total, rank } = await got(endpoint).then(res => res.body)
|
||||
|
||||
switch (topic) {
|
||||
case 'stats':
|
||||
case 'hits':
|
||||
return stats('hits', type, pkg)
|
||||
case 'rank':
|
||||
return stats('rank', type, pkg)
|
||||
case 'v':
|
||||
return version(pkg)
|
||||
}
|
||||
}
|
||||
|
||||
const stats = async (metric, type, name) => {
|
||||
const endpoint = `https://data.jsdelivr.com/v1/package/${type}/${name}/stats`
|
||||
const { total, rank } = await got(endpoint).then(res => res.body)
|
||||
|
||||
switch (metric) {
|
||||
case 'hits':
|
||||
return {
|
||||
subject: 'jsDelivr',
|
||||
status: `${millify(total)}/month`,
|
||||
|
@ -24,8 +37,18 @@ module.exports = async (topic, type, ...name) => {
|
|||
case 'rank':
|
||||
return {
|
||||
subject: 'jsDelivr rank',
|
||||
status: rank || 'none',
|
||||
status: rank ? `#${rank}` : 'none',
|
||||
color: rank ? 'blue' : 'grey'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const version = async (name) => {
|
||||
const endpoint = `https://cdn.jsdelivr.net/npm/${name}/package.json`
|
||||
const { version } = await got(endpoint).then(res => res.body)
|
||||
return {
|
||||
subject: 'jsDelivr',
|
||||
status: `v${version}`,
|
||||
color: semColor(version)
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue