Skip to content

Commit

Permalink
Align label and message props of coalesceBadge() with internal …
Browse files Browse the repository at this point in the history
…`makeBadge()`

Part of #3370, and also helps with #4950.

This is cherry-picked from #4980 but stops short of the mor substantive changes of that PR.

Also rewrites most of the tests of `coalesceBadge()` to use `.includes()`, providing IMO a slight improvement in readability.
  • Loading branch information
paulmelnikow committed Oct 16, 2020
1 parent 43f7adb commit 356a9a4
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 148 deletions.
6 changes: 3 additions & 3 deletions badge-maker/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function _clean(format) {
}
})

// Legacy.
cleaned.label = cleaned.label || ''

// convert "public" format to "internal" format
cleaned.text = [cleaned.label || '', cleaned.message]
delete cleaned.label
delete cleaned.message
if ('style' in cleaned) {
cleaned.template = cleaned.style
delete cleaned.style
Expand Down
8 changes: 4 additions & 4 deletions badge-maker/lib/make-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ it is likely this will impact on the package's public interface in index.js
module.exports = function makeBadge({
format,
template = 'flat',
text,
label,
message,
color,
labelColor,
logo,
Expand All @@ -19,9 +20,8 @@ module.exports = function makeBadge({
links = ['', ''],
}) {
// String coercion and whitespace removal.
text = text.map(value => `${value}`.trim())

const [label, message] = text
label = `${label}`.trim()
message = `${message}`.trim()

// This ought to be the responsibility of the server, not `makeBadge`.
if (format === 'json') {
Expand Down
Loading

0 comments on commit 356a9a4

Please sign in to comment.