kopia lustrzana https://github.com/badgen/badgen.net
badge(npm): add types badge (#318)
* Removes the useless horizontal scrollbar. It appears due to `100vw` but since there is a vertical scrollbar it has only `100vw - scrollbar width` of width. * Badge indicating whether type definitions is included with package, in separate package or missing at all. * feat(types badge): Renamed typings to types; fix(types badge): Use branded TS color as the backing of badge;pull/322/head
rodzic
e826c53f56
commit
a270b70d2a
|
@ -27,7 +27,10 @@ export const meta: Meta = {
|
|||
'/npm/dt/express': 'total downloads',
|
||||
'/npm/license/lodash': 'license',
|
||||
'/npm/node/next': 'node version',
|
||||
'/npm/dependents/got': 'dependents'
|
||||
'/npm/dependents/got': 'dependents',
|
||||
'/npm/types/tslib': 'types',
|
||||
'/npm/types/react': 'types',
|
||||
'/npm/types/queri': 'types',
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +63,8 @@ async function handler ({ topic, scope, pkg, tag }: Args) {
|
|||
return download('last-year', npmName)
|
||||
case 'dependents':
|
||||
return dependents(npmName)
|
||||
case 'types':
|
||||
return typesDefinition(npmName, tag)
|
||||
default:
|
||||
return {
|
||||
subject: 'npm',
|
||||
|
@ -159,3 +164,30 @@ const parseDependents = html => {
|
|||
if (depLink.length !== 1) return -1
|
||||
return depLink.text().replace(/[^0-9]/g, '')
|
||||
}
|
||||
|
||||
async function typesDefinition(pkg: string, tag: string = 'latest') {
|
||||
const endpoint = `https://cdn.jsdelivr.net/npm/${ pkg }@${ tag }/package.json`
|
||||
let meta = await got(endpoint).then(res => res.body)
|
||||
|
||||
if (typeof meta.types === 'string' || typeof meta.typings === "string") {
|
||||
return {
|
||||
subject: 'types',
|
||||
status: 'included',
|
||||
color: '0074c1'
|
||||
}
|
||||
}
|
||||
|
||||
const typesPkg = '@types/' + (pkg.charAt(0) === "@" ? pkg.slice(1).replace('/', '__') : pkg)
|
||||
const typesEndpoint = `https://cdn.jsdelivr.net/npm/${ typesPkg }@latest/package.json`
|
||||
meta = await got(typesEndpoint).then(res => res.body).catch(err => false)
|
||||
|
||||
return meta && meta.name === typesPkg ? {
|
||||
subject: 'types',
|
||||
status: meta.name,
|
||||
color: 'cyan',
|
||||
} : {
|
||||
subject: 'types',
|
||||
status: 'missing',
|
||||
color: 'orange',
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue