The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement. We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs. I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'use strict'
|
|
|
|
const { metric } = require('../../lib/text-formatters')
|
|
const LibrariesIoBase = require('./librariesio-base')
|
|
|
|
// https://libraries.io/api#project-dependents
|
|
class LibrariesIoDependents extends LibrariesIoBase {
|
|
static get category() {
|
|
return 'other'
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'dependents',
|
|
}
|
|
}
|
|
|
|
static get route() {
|
|
return this.buildRoute('librariesio/dependents')
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Dependents (via libraries.io)',
|
|
exampleUrl: 'npm/got',
|
|
urlPattern: ':platform/:library',
|
|
staticExample: this.render({ dependentCount: 2000 }),
|
|
},
|
|
]
|
|
}
|
|
|
|
static render({ dependentCount }) {
|
|
return {
|
|
message: metric(dependentCount),
|
|
color: dependentCount === 0 ? 'orange' : 'brightgreen',
|
|
}
|
|
}
|
|
|
|
async handle({ platform, packageName }) {
|
|
const { dependents_count: dependentCount } = await this.fetch(
|
|
{
|
|
platform,
|
|
packageName,
|
|
},
|
|
{ allowPackages: true }
|
|
)
|
|
return this.constructor.render({ dependentCount })
|
|
}
|
|
}
|
|
|
|
module.exports = LibrariesIoDependents
|