Files
shields/services/librariesio/librariesio-sourcerank.service.js
dependabot-preview[bot] 294aa1e1df Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0; autofixes (#3671)
* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Autofixes
2019-07-08 12:13:46 -04:00

55 lines
1.1 KiB
JavaScript

'use strict'
const { colorScale } = require('../color-formatters')
const { fetchProject } = require('./librariesio-common')
const { BaseJsonService } = require('..')
const sourceRankColor = colorScale([10, 15, 20, 25, 30])
module.exports = class LibrariesIoSourcerank extends BaseJsonService {
static get category() {
return 'rating'
}
static get route() {
return {
base: 'librariesio/sourcerank',
pattern: ':platform/:packageName',
}
}
static get examples() {
return [
{
title: 'Libraries.io SourceRank',
namedParams: {
platform: 'npm',
packageName: 'got',
},
staticPreview: this.render({ rank: 25 }),
},
]
}
static get defaultBadgeData() {
return {
label: 'sourcerank',
}
}
static render({ rank }) {
return {
message: rank,
color: sourceRankColor(rank),
}
}
async handle({ platform, packageName }) {
const { rank } = await fetchProject(this, {
platform,
packageName,
})
return this.constructor.render({ rank })
}
}