Commonly-used functions for formatting text in badge labels. Includes ordinal numbers, currency codes, star ratings, versions, etc.
- Source:
Methods
(inner) addv(version) → {string}
Add a starting v to the version unless it doesn't starts with a digit, is a date (yyyy-mm-dd), or is a commit hash. For example, addv("1.2.3") returns "v1.2.3", but addv("hello"), addv("2021-10-31"), addv("abcdef1"), returns "hello", "2021-10-31", and "abcdef1" respectively.
Parameters:
Name | Type | Description |
---|---|---|
version |
string | Version string |
- Source:
Returns:
Version string with the starting v
- Type
- string
(inner) currencyFromCode(code) → {string}
Converts the ISO 4217 code to the corresponding currency symbol. If the the symbol for the code is not found, then the code itself is returned.
Parameters:
Name | Type | Description |
---|---|---|
code |
string | ISO 4217 code |
- Source:
Returns:
Currency symbol for the code
- Type
- string
(inner) maybePluralize(singular, countable, plural) → {string}
Returns a string that is either the singular or the plural form of a word, depending on the length of the countable parameter.
Parameters:
Name | Type | Description |
---|---|---|
singular |
string | Singular form of the word |
countable |
Array.<string> | Array of values you want to count |
plural |
string | Plural form of the word |
- Source:
Returns:
Singular or plural form of the word
- Type
- string
(inner) metric(n) → {string}
Given a number (positive or negative), returns a string with appropriate unit in the metric system, SI. Note: numbers beyond the peta- cannot be represented as integers in JS. For example, if you call metric(1000), it will return "1k", which means one kilo or one thousand.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | Input number |
- Source:
Returns:
String with appropriate unit in the metric system, SI
- Type
- string
(inner) omitv(version) → {string}
Remove the starting v in a string if it exists. For example, omitv("v1.2.3") returns "1.2.3", but omitv("hello") returns "hello".
Parameters:
Name | Type | Description |
---|---|---|
version |
string | Version string |
- Source:
Returns:
Version string without the starting v
- Type
- string
(inner) ordinalNumber(n) → {string}
Calculates the ordinal number of the given number. For example, if the input is 1, the output is “1ˢᵗ”.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | Input number |
- Source:
Returns:
Ordinal number of the input number
- Type
- string
(inner) starRating(rating, maxopt) → {string}
Creates a string of stars and empty stars based on the rating. The number of stars is determined by the integer part of the rating. An additional star or a three-quarter star or a half star or a quarter star is added based on the decimal part of the rating. The remaining stars are empty stars until the maximum number of stars is reached.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rating |
number | Current rating |
||
max |
number |
<optional> |
5 | Maximum rating |
- Source:
Returns:
A string of stars and empty stars
- Type
- string