UNPKG

2.34 kBJavaScriptView Raw
1const la = require('lazy-ass')
2const is = require('check-more-types')
3
4// returns the badges themselves
5// like "[npm][npm-url]""
6function getBadges (options) {
7 const badges = []
8 if (options.npmBadge) {
9 badges.push('[![NPM][with-package-icon]][with-package-url]')
10 badges.push('')
11 }
12 if (options.travisBadge) {
13 badges.push('[![Build status][ci-image]][ci-url]')
14 }
15 if (options.semanticReleaseBadge) {
16 badges.push('[![semantic-release][semantic-image]][semantic-url]')
17 }
18 if (options.standardBadge) {
19 badges.push('[![standard][standard-image]][standard-url]')
20 }
21 if (options.renovateBadge) {
22 badges.push('[![renovate-app badge][renovate-badge]][renovate-app]')
23 }
24 const markdown = badges.join('\n')
25 return markdown
26}
27
28// returns badge url references, usually placed at the bottom of README
29function getBadgesUrls (options) {
30 const badges = []
31 if (options.npmBadge) {
32 la(is.unemptyString(options.name), 'missing package name', options)
33 badges.push(
34 `[npm-icon]: https://nodei.co/npm/${options.name}.svg?downloads=true`
35 )
36 badges.push(`[npm-url]: https://npmjs.org/package/${options.name}`)
37 }
38 if (options.travisBadge) {
39 la(is.unemptyString(options.username), 'missing username', options)
40 la(is.unemptyString(options.repoName), 'missing repo name', options)
41 const u = options.username
42 const r = options.repoName
43 badges.push(`[ci-image]: https://travis-ci.org/${u}/${r}.svg?branch=master`)
44 badges.push(`[ci-url]: https://travis-ci.org/${u}/${r}`)
45 }
46 if (options.semanticReleaseBadge) {
47 badges.push(
48 '[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg'
49 )
50 badges.push(
51 '[semantic-url]: https://github.com/semantic-release/semantic-release'
52 )
53 }
54 if (options.standardBadge) {
55 badges.push(
56 '[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg'
57 )
58 badges.push('[standard-url]: http://standardjs.com/')
59 }
60 if (options.renovateBadge) {
61 badges.push(
62 '[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg'
63 )
64 badges.push('[renovate-app]: https://renovateapp.com/')
65 }
66
67 const markdown = badges.join('\n')
68 return markdown
69}
70
71module.exports = {
72 getBadges,
73 getBadgesUrls
74}