forked from badgen/badgen.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrates.js
36 lines (34 loc) · 911 Bytes
/
crates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const got = require('../got.js')
const millify = require('millify')
const semColor = require('../utils/sem-color.js')
const v = require('../utils/version-formatter.js')
module.exports = async (topic, pkg) => {
const endpoint = `https://crates.io/api/v1/crates/${pkg}`
const { crate } = await got(endpoint).then(res => res.body)
switch (topic) {
case 'v':
return {
subject: 'crates.io',
status: v(crate.max_version),
color: semColor(crate.max_version)
}
case 'd':
return {
subject: 'downloads',
status: millify(crate.downloads),
color: 'green'
}
case 'dl':
return {
subject: 'downloads',
status: millify(crate.recent_downloads) + ' latest version',
color: 'green'
}
default:
return {
subject: 'crates',
status: 'unknown',
color: 'grey'
}
}
}