mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
* add python typing badge * prettier * Update services/pypi/pypi-typing.service.js Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com> * address comments * rename * fix test * check Typing :: Stubs Only * change test package to typeshed --------- Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import PypiBase, { pypiGeneralParams } from './pypi-base.js'
|
|
|
|
export default class PypiTypes extends PypiBase {
|
|
static category = 'platform-support'
|
|
|
|
static route = this.buildRoute('pypi/types')
|
|
|
|
static openApi = {
|
|
'/pypi/types/{packageName}': {
|
|
get: {
|
|
summary: 'PyPI - Types',
|
|
description:
|
|
'Type information provided by the package, as indicated by the presence of the `Typing :: Typed` and `Typing :: Stubs Only` classifiers in the package metadata',
|
|
parameters: pypiGeneralParams,
|
|
},
|
|
},
|
|
}
|
|
|
|
static defaultBadgeData = { label: 'types' }
|
|
|
|
static render({ isTyped, isStubsOnly }) {
|
|
if (isTyped) {
|
|
return {
|
|
message: 'typed',
|
|
color: 'brightgreen',
|
|
}
|
|
} else if (isStubsOnly) {
|
|
return {
|
|
message: 'stubs',
|
|
color: 'brightgreen',
|
|
}
|
|
} else {
|
|
return {
|
|
message: 'untyped',
|
|
color: 'red',
|
|
}
|
|
}
|
|
}
|
|
|
|
async handle({ egg }, { pypiBaseUrl }) {
|
|
const packageData = await this.fetch({ egg, pypiBaseUrl })
|
|
const isTyped = packageData.info.classifiers.includes('Typing :: Typed')
|
|
const isStubsOnly = packageData.info.classifiers.includes(
|
|
'Typing :: Stubs Only',
|
|
)
|
|
return this.constructor.render({ isTyped, isStubsOnly })
|
|
}
|
|
}
|