badgen.net/endpoints/homebrew.ts

34 wiersze
778 B
TypeScript
Czysty Zwykły widok Historia

import got from '../libs/got'
import { version, versionColor } from '../libs/utils'
2019-05-26 04:38:30 +00:00
import {
badgenServe,
BadgenServeMeta as Meta,
BadgenServeHandlers as Handlers,
BadgenServeHandlerArgs as Args
} from '../libs/badgen-serve'
2019-05-26 04:38:30 +00:00
export const meta: Meta = {
2019-05-26 04:40:32 +00:00
title: 'Homebrew',
2019-05-26 04:38:30 +00:00
examples: {
'/homebrew/v/fish': 'version',
'/homebrew/v/cake': 'version'
}
}
2019-05-26 04:38:30 +00:00
export const handlers: Handlers = {
'/homebrew/v/:pkg': handler
}
2019-05-26 04:38:30 +00:00
async function handler ({ pkg }: Args) {
const endpoint = `https://formulae.brew.sh/api/formula/${pkg}.json`
const { versions } = await got(endpoint).then(res => res.body)
return {
subject: 'homebrew',
status: version(versions.stable),
color: versionColor(versions.stable)
}
}
2019-05-14 01:15:16 +00:00
export default badgenServe(handlers)