mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
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>
This commit is contained in:
parent
bc533c694b
commit
d3f1a55503
@ -1,5 +1,18 @@
|
||||
/**
|
||||
* 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'
|
||||
@ -10,6 +23,15 @@ function contributorColor(contributorCount) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
@ -1,9 +0,0 @@
|
||||
import { Deprecated } from './index.js'
|
||||
|
||||
function enforceDeprecation(effectiveDate) {
|
||||
if (Date.now() >= effectiveDate.getTime()) {
|
||||
throw new Deprecated()
|
||||
}
|
||||
}
|
||||
|
||||
export { enforceDeprecation }
|
@ -1,15 +0,0 @@
|
||||
import { expect } from 'chai'
|
||||
import { Deprecated } from '../core/base-service/errors.js'
|
||||
import { enforceDeprecation } from './deprecation-helpers.js'
|
||||
|
||||
describe('enforceDeprecation', function () {
|
||||
it('throws Deprecated for a date in the past', function () {
|
||||
expect(() => enforceDeprecation(new Date())).to.throw(Deprecated)
|
||||
})
|
||||
|
||||
it('does not throw for a date in the future', function () {
|
||||
expect(() =>
|
||||
enforceDeprecation(new Date(Date.now() + 10000))
|
||||
).not.to.throw()
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user