@atlaskit/badge
Version:
A badge is a visual indicator for numeric values such as tallies and scores.
36 lines (35 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatValueWithNegativeSupport = formatValueWithNegativeSupport;
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;
}
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();
}