Skip to content

Commit

Permalink
chore: fix type errors in chrome-web-store badge
Browse files Browse the repository at this point in the history
  • Loading branch information
amio committed Jul 9, 2024
1 parent 36513b3 commit f897706
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api-legacy/opencollective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function handler ({ topic, slug }: PathArgs) {
const endpoint = `https://opencollective.com/${slug}.json`

const details = await got(endpoint).json<any>()
const localeOptions = {
const localeOptions: Intl.NumberFormatOptions = {
style: 'currency',
currency: details.currency
}
Expand Down
27 changes: 18 additions & 9 deletions pages/api/chrome-web-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default createBadgenHandler({
examples: {
'/chrome-web-store/v/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'version',
'/chrome-web-store/users/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'users',
'/chrome-web-store/price/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'price',
// '/chrome-web-store/price/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'price', // deprecated
'/chrome-web-store/stars/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'stars',
'/chrome-web-store/rating/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'rating',
'/chrome-web-store/rating-count/ckkdlimhmcjmikdlpkmbgfkaikojcbjk': 'rating count',
Expand All @@ -19,10 +19,18 @@ export default createBadgenHandler({
})

async function handler ({ topic, id }: PathArgs) {
const chromeWebStore = await ChromeWebStore.load({ id, qs: { hl: 'en' } })
const result = await ChromeWebStore.load({ id, qs: { hl: 'en' } }).catch(console.error)

if (!result) {
return {
subject: 'chrome web store',
status: 'not found',
color: 'grey',
}
}
switch (topic) {
case 'v': {
const v = chromeWebStore.version()
const v = result.version()
return {
subject: 'chrome web store',
status: version(v),
Expand All @@ -32,31 +40,32 @@ async function handler ({ topic, id }: PathArgs) {
case 'users':
return {
subject: 'users',
status: millify(chromeWebStore.users()),
status: result.users(),
color: 'green'
}
case 'price':
return {
subject: 'price',
status: `${chromeWebStore.price()} ${chromeWebStore.priceCurrency()}`,
color: 'green'
// status: `${result.price()} ${result.priceCurrency()}`,
status: 'deprecated',
color: 'gray'
}
case 'rating':
return {
subject: 'rating',
status: `${chromeWebStore.ratingValue().toFixed(2)}/5`,
status: `${Number(result.ratingValue())?.toFixed(1) || '-'}/5`,
color: 'green'
}
case 'stars':
return {
subject: 'stars',
status: stars(chromeWebStore.ratingValue()),
status: stars(result.ratingValue()),
color: 'green'
}
case 'rating-count':
return {
subject: 'rating count',
status: `${chromeWebStore.ratingCount()} total`,
status: `${result.ratingCount()} total`,
color: 'green'
}
default:
Expand Down

0 comments on commit f897706

Please sign in to comment.