Module: services/color-formatters

Commonly-used functions for determining the colour to use for a badge, including colours based off download count, version number, etc.

Source:

Methods

(inner) age(date, reversed) → {string}

Determines the color used for a badge according to the age. Age is calculated as days elapsed till current date. The color varies from bright green to red as the age increases or the other way around if reverse is given true.

Parameters:
Name Type Default Description
date string

Date string

reversed boolean false

Reverse the color scale a.k.a. the older, the better

Source:
Returns:

Badge color

Type
string

(inner) colorScale(steps, colors, reversed) → {function}

Creates a callback function that determines badge color from the colors array. If the colors array is provided then for n steps, there should be n + 1 color. If the colors array is not provided then it is chosen from the default colors array according to the size of the steps array.

Parameters:
Name Type Description
steps Array.<number>

Steps array

colors Array.<string>

Colors array. If provided, should be of length steps.length + 1

reversed boolean

If true then the colors array will be considered in reverse order

Source:
Returns:

Function that finds the step index by comparing value with steps array and returns color from colors array for the corresponding step index

Type
function

(inner) coveragePercentage(percentage) → {string}

Determines the color used for a badge by comparing percentage and floor values. The color varies from red to bright green as the percentage increases.

Parameters:
Name Type Description
percentage number

Percentage value

Source:
Returns:

Badge color

Type
string

(inner) downloadCount(downloads) → {string}

Determines the color used for a badge by comparing the download count and floor values. The color varies from red to bright green as the download count increases.

Parameters:
Name Type Description
downloads number

Download count

Source:
Returns:

Badge color

Type
string

(inner) floorCount(value, yellow, yellowgreen, green) → {string}

Determines the color used for a badge by comparing the value and floor count values. The color can vary from red to bright green depending on the range the value lies in. Decreasing the value will shift the color towards red. Increasing the value will shift the color towards bright green.

Parameters:
Name Type Description
value number

Current value

yellow number

Yellow color threshold, should be greater than 0

yellowgreen number

Yellowgreen color threshold, should be greater than yellow

green number

Green color threshold, should be greater than yellowgreen

Source:
Returns:

Badge color

Type
string

(inner) letterScore(score) → {string}

Determines the color used for a badge by matching score with grade values. The color varies from bright green to red as the score decreases. The score can be one of the following grade value: ['A', 'B', 'C', 'D', 'E']. The color defaults to red if the score does not matches with any of the grade values.

Parameters:
Name Type Description
score string

Score value

Source:
Returns:

Badge color

Type
string

(inner) pep440VersionColor(version) → {string}

Determines the color used for a badge based on PEP440 versioning.

Parameters:
Name Type Description
version string | number

Version used for determining badge color

Source:
Returns:

Badge color

Type
string

(inner) version(version) → {string}

Determines the color used for a badge based on version.

Parameters:
Name Type Description
version string | number

Version used for determining badge color

Source:
Returns:

Badge color

Type
string