1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/contributor-count.js
Prashant Rawat d3f1a55503
Docstrings for contributor-count and deprecation-helpers services (#8003)
* add docstrings for contributor-count service

* add docstrings for deprecation-helper service

* remove deprecation-helpers service as it is not used anywhere

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2022-05-29 17:48:04 +00:00

44 lines
1.2 KiB
JavaScript

/**
* Common functions and utilities for tasks related to contributor count.
*
* @module
*/
import { metric } from './text-formatters.js'
/**
* Determines the color used for a badge based on the contributor count.
* The color varies from red to bright green as the contributor count increases.
*
* @param {number} contributorCount Contributor count
* @returns {string} Badge color
*/
function contributorColor(contributorCount) {
if (contributorCount > 2) {
return 'brightgreen'
} else if (contributorCount === 2) {
return 'yellow'
} else {
return 'red'
}
}
/**
* Handles rendering concerns of badges that display contributor count.
* Determines the message and color of the badge according to the contributor count.
*
* @param {object} attrs Refer to individual attributes
* @param {string} [attrs.label] If provided then badge label is set to this value
* @param {number} attrs.contributorCount Contributor count
* @returns {object} Badge with label, message and color properties
*/
function renderContributorBadge({ label, contributorCount }) {
return {
label,
message: metric(contributorCount),
color: contributorColor(contributorCount),
}
}
export { contributorColor, renderContributorBadge }