diff --git a/services/version.js b/services/version.js index 8fa84bf71f2ae..cdbb90aec3b30 100644 --- a/services/version.js +++ b/services/version.js @@ -234,6 +234,7 @@ function rangeStart(v) { * @param {string} options.version - The version number to display on the badge * @param {string} [options.tag] - The tag to display on the badge, such as "alpha" or "beta" * @param {string} [options.defaultLabel] - The default label to display on the badge, such as "npm" or "github" + * @param {string} [options.prefix] - The prefix to display on the message, such as ">=", "v", overrides the default behavior of using addv * @param {string} [options.postfix] - The postfix to display on the message, such as "tested" * @param {Function} [options.versionFormatter=versionColor] - The function to use to format the color of the badge based on the version number * @returns {object} A badge object that has three properties: label, message, and color @@ -246,12 +247,15 @@ function renderVersionBadge({ version, tag, defaultLabel, + prefix, postfix, versionFormatter = versionColor, }) { return { label: tag ? `${defaultLabel}@${tag}` : defaultLabel, - message: addv(version) + (postfix ? ` ${postfix}` : ''), + message: + (prefix ? `${prefix}${version}` : addv(version)) + + (postfix ? ` ${postfix}` : ''), color: versionFormatter(version), } } diff --git a/services/version.spec.js b/services/version.spec.js index 66d1118b0b81f..251cfc892a6be 100644 --- a/services/version.spec.js +++ b/services/version.spec.js @@ -170,5 +170,49 @@ describe('Version helpers', function () { message: 'v1.2.3 tested', color: 'blue', }) + given({ version: '1.2.3', prefix: '^' }).expect({ + label: undefined, + message: '^1.2.3', + color: 'blue', + }) + given({ + version: '1.2.3', + tag: 'alpha', + defaultLabel: 'npm', + prefix: '^', + }).expect({ + label: 'npm@alpha', + message: '^1.2.3', + color: 'blue', + }) + given({ + version: '1.2.3', + defaultLabel: 'npm', + prefix: '^', + }).expect({ + label: 'npm', + message: '^1.2.3', + color: 'blue', + }) + given({ + version: '1.2.3', + prefix: '^', + postfix: 'tested', + }).expect({ + label: undefined, + message: '^1.2.3 tested', + color: 'blue', + }) + given({ + version: '1.2.3', + tag: 'beta', + defaultLabel: 'github', + prefix: '^', + postfix: 'tested', + }).expect({ + label: 'github@beta', + message: '^1.2.3 tested', + color: 'blue', + }) }) })