UNPKG

1.27 kBJavaScriptView Raw
1// @flow
2
3/*::
4import { Package } from './package';
5
6export type BadgeBuilder = (packageData: Package) => string;
7*/
8
9class Badges {
10 static isBadgeUrl(url /*: string */) /*: boolean */ {
11 return !!url;
12 }
13
14 static nodeico(packageData /*: Package */) /*: string */ {
15 // TODO: do something sensible with the flags
16 return [
17 '[',
18 '![NPM]',
19 `(https://nodei.co/npm/${packageData.name}.png)]`,
20 `(https://nodei.co/npm/${packageData.name}/)`,
21 ].join('');
22 }
23
24 static travis(packageData /*: Package */) /*: string */ {
25 const repository = packageData.getRepositry();
26 return repository ? [
27 '[',
28 '![Build Status]',
29 `(https://api.travis-ci.org/${repository.path}.svg?branch=master)`,
30 `](https://travis-ci.org/${repository.path})`
31 ].join('') : '';
32 }
33
34 static bithound(packageData /*: Package */) /*: string */ {
35 const repository = packageData.getRepositry();
36 const host = repository && repository.host.split('.')[0];
37
38 return repository && host ? [
39 '[',
40 '![bitHound Score]',
41 `(https://www.bithound.io/${host}/${repository.path}/badges/score.svg)`,
42 `](https://www.bithound.io/${host}/${repository.path})`
43 ].join('') : '';
44 }
45}
46
47module.exports = {
48 Badges
49};