@atlaskit/badge
Version:
A badge is a visual indicator for numeric values such as tallies and scores.
30 lines • 1.08 kB
JavaScript
function getSafeValueWithNegativeSupport() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var numericValue = +value;
// NOTE: Changing below code as this causes custom fields -ve number to show up as zero in activity timeline.
// This will ensure it renders correctly if it is a number otherwise renders 0
// If the value is NaN, return it as is (assuming it's a non-numeric string)
if (isNaN(numericValue)) {
return value;
}
// Return the numeric value, allowing negative numbers
return numericValue;
}
export function formatValueWithNegativeSupport(value, max) {
var safeValue = getSafeValueWithNegativeSupport(value);
var safeMax = getSafeValueWithNegativeSupport(max);
var hasSafeMaxValue = false;
if (max !== undefined) {
hasSafeMaxValue = true;
}
if (safeMax === Infinity && safeValue === Infinity) {
return '∞';
}
if (hasSafeMaxValue && safeMax < safeValue) {
return "".concat(safeMax, "+");
}
if (safeValue === Infinity) {
return '∞';
}
return safeValue.toString();
}