b9d96755ec
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * reformat all the things (prettier 3) * update tests to await calls to prettier.format() --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: chris48s <git@chris-shaw.dev>
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const { normalizeColor, toSvgColor } = require('./color')
|
|
const badgeRenderers = require('./badge-renderers')
|
|
const { stripXmlWhitespace } = require('./xml')
|
|
|
|
/*
|
|
note: makeBadge() is fairly thinly wrapped so if we are making changes here
|
|
it is likely this will impact on the package's public interface in index.js
|
|
*/
|
|
module.exports = function makeBadge({
|
|
format,
|
|
style = 'flat',
|
|
label,
|
|
message,
|
|
color,
|
|
labelColor,
|
|
logo,
|
|
logoPosition,
|
|
logoWidth,
|
|
links = ['', ''],
|
|
}) {
|
|
// String coercion and whitespace removal.
|
|
label = `${label}`.trim()
|
|
message = `${message}`.trim()
|
|
|
|
// This ought to be the responsibility of the server, not `makeBadge`.
|
|
if (format === 'json') {
|
|
return JSON.stringify({
|
|
label,
|
|
message,
|
|
logoWidth,
|
|
// Only call normalizeColor for the JSON case: this is handled
|
|
// internally by toSvgColor in the SVG case.
|
|
color: normalizeColor(color),
|
|
labelColor: normalizeColor(labelColor),
|
|
link: links,
|
|
name: label,
|
|
value: message,
|
|
})
|
|
}
|
|
|
|
const render = badgeRenderers[style]
|
|
if (!render) {
|
|
throw new Error(`Unknown badge style: '${style}'`)
|
|
}
|
|
|
|
logoWidth = +logoWidth || (logo ? 14 : 0)
|
|
|
|
return stripXmlWhitespace(
|
|
render({
|
|
label,
|
|
message,
|
|
links,
|
|
logo,
|
|
logoPosition,
|
|
logoWidth,
|
|
logoPadding: logo && label.length ? 3 : 0,
|
|
color: toSvgColor(color),
|
|
labelColor: toSvgColor(labelColor),
|
|
}),
|
|
)
|
|
}
|