feat: add packagephobia live badge

pull/32/head
Amio 2018-07-24 22:55:14 +08:00
rodzic 1bcfef284d
commit 14d3bd38da
5 zmienionych plików z 79 dodań i 0 usunięć

Wyświetl plik

@ -78,6 +78,8 @@ Available color names:
| david-dm dev dependencies | ![](/david/dev/zeit/pkg) | [/david/dev/zeit/pkg](/david/dev/zeit/pkg)
| david-dm peer dependencies | ![](/david/peer/epoberezkin/ajv-keywords) | [/david/peer/epoberezkin/ajv-keywords](/david/peer/epoberezkin/ajv-keywords)
| david-dm optional dependencies | ![](/david/optional/epoberezkin/ajv-keywords) | [/david/optional/epoberezkin/ajv-keywords](/david/optional/epoberezkin/ajv-keywords)
| packagephobia publish size | ![](/packagephobia/publish/webpack) | [/packagephobia/publish/webpack](/packagephobia/publish/webpack)
| packagephobia install size | ![](/packagephobia/install/webpack) | [/packagephobia/install/webpack](/packagephobia/install/webpack)
| uptime robot status | ![](/uptime-robot/status/m780731617-a9e038618dc1aee36a44c4af) | [/uptime-robot/status/m780731617-a9e038618dc1aee36a44c4af](/uptime-robot/status/m780731617-a9e038618dc1aee36a44c4af)
| uptime robot uptime (day) | ![](/uptime-robot/day/m780731617-a9e038618dc1aee36a44c4af) | [/uptime-robot/lasy-day/m780731617-a9e038618dc1aee36a44c4af](/uptime-robot/day/m780731617-a9e038618dc1aee36a44c4af)
| uptime robot uptime (week) | ![](/uptime-robot/week/m780731617-a9e038618dc1aee36a44c4af) | [/uptime-robot/lasy-week/m780731617-a9e038618dc1aee36a44c4af](/uptime-robot/week/m780731617-a9e038618dc1aee36a44c4af)

Wyświetl plik

@ -9,6 +9,7 @@ module.exports = {
'github': require('./github.js'),
'homebrew': require('./homebrew.js'),
'npm': require('./npm.js'),
'packagephobia': require('./packagephobia.js'),
'travis': require('./travis.js'),
'uptime-robot': require('./uptime-robot.js')
}

Wyświetl plik

@ -0,0 +1,70 @@
const axios = require('../axios.js')
const prettyBytes = require('pretty-bytes')
module.exports = async function (topic, pkg) {
const endpoint = `https://packagephobia.now.sh/api.json?p=${pkg}`
const { data } = await axios(endpoint)
const { installSize, publishSize } = data
switch (topic) {
case 'publish':
return {
subject: 'publish size',
status: prettyBytes(publishSize),
color: getHexColor(publishSize)
}
case 'install':
return {
subject: 'install size',
status: prettyBytes(installSize),
color: getHexColor(installSize)
}
default:
return {
subject: 'packagephobia',
status: 'unknown topic',
color: 'grey'
}
}
}
/**
* Color schema from
* https://github.com/styfle/packagephobia/blob/master/src/util/npm-parser.ts
*/
const KB = 1024
const oneHundredKb = 100 * KB
const megabyte = 1024 * KB
const fiveMb = 5 * megabyte
const thirtyMb = 30 * megabyte
const oneHundredMb = 100 * megabyte
const fiveHundredMb = 500 * megabyte
const color = {
brightgreen: '44CC11',
limegreen: '97CA00',
yellow: 'DFB317',
orange: 'FE7D37',
red: 'E05D44',
blue: '007EC6',
pink: 'FF69B4'
}
function getHexColor (bytes) {
if (bytes < oneHundredKb) {
return color.brightgreen
} else if (bytes < megabyte) {
return color.limegreen
} else if (bytes < fiveMb) {
return color.blue
} else if (bytes < thirtyMb) {
return color.yellow
} else if (bytes < oneHundredMb) {
return color.orange
} else if (bytes < fiveHundredMb) {
return color.red
} else {
return color.pink
}
}

5
package-lock.json wygenerowano
Wyświetl plik

@ -3249,6 +3249,11 @@
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=",
"dev": true
},
"pretty-bytes": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.1.0.tgz",
"integrity": "sha512-wa5+qGVg9Yt7PB6rYm3kXlKzgzgivYTLRandezh43jjRqgyDyP+9YxfJpJiLs9yKD1WeU8/OvtToWpW7255FtA=="
},
"pretty-error": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-2.1.1.tgz",

Wyświetl plik

@ -19,6 +19,7 @@
"micro": "^9.3.2",
"micro-fork": "^0.1.0",
"millify": "^2.0.1",
"pretty-bytes": "^5.1.0",
"serve-marked": "0.3.0"
},
"devDependencies": {