Files
shields/services/librariesio/librariesio-common.js
chris48s 504015c0ba migrate hapi/joi to joi (#5624)
* update joi + joi-extension-semver

* @hapi/joi --> joi

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-30 17:51:02 +00:00

27 lines
752 B
JavaScript

'use strict'
const Joi = require('joi')
const { nonNegativeInteger, anyInteger } = require('../validators')
// API doc: https://libraries.io/api#project
const projectSchema = Joi.object({
platform: Joi.string().required(),
dependents_count: nonNegativeInteger,
dependent_repos_count: nonNegativeInteger,
rank: anyInteger,
}).required()
async function fetchProject(serviceInstance, { platform, scope, packageName }) {
return serviceInstance._requestJson({
schema: projectSchema,
url: `https://libraries.io/api/${encodeURIComponent(platform)}/${
scope ? encodeURIComponent(`${scope}/`) : ''
}${encodeURIComponent(packageName)}`,
errorMessages: { 404: 'package not found' },
})
}
module.exports = {
fetchProject,
}