Skip to content

Commit

Permalink
define static example for cdnjs
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Jun 17, 2018
1 parent 99ccdb4 commit 3bc8304
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions services/cdnjs/cdnjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const { version: versionColor} = require('../../lib/color-formatters');

module.exports = class Cdnjs extends BaseJsonService {
async handle({library}) {
const version = await this.getData(library);
return Cdnjs.formatBadge(version);
}

async getData(library) {
const apiUrl = 'https://api.cdnjs.com/libraries/' + library + '?fields=version';
const json = await this._requestJson(apiUrl);

Expand All @@ -15,8 +20,10 @@ module.exports = class Cdnjs extends BaseJsonService {
status code = 200, body = {} */
throw new NotFound();
}
const version = json.version || 0;
return json.version || 0;
}

static formatBadge(version) {
return {
message: versionText(version),
color: versionColor(version)
Expand All @@ -43,7 +50,8 @@ module.exports = class Cdnjs extends BaseJsonService {
static get examples() {
return [
{
previewUrl: 'jquery',
staticExample: this.formatBadge('1.5.2'),
exampleUrl: 'jquery',
keywords: [
'cdn',
'cdnjs'
Expand Down

0 comments on commit 3bc8304

Please sign in to comment.