@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
57 lines (56 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatPercent = formatPercent;
var _formatCore = require("./formatCore.js");
var _decimals = require("./decimals.js");
function formatPercent(value, {
locale: inputLocale = null,
clean = false,
decimals = null,
rounding = null,
signDisplay = null,
options = null,
returnAria = false,
invalidAriaText = null,
cleanCopyValue = null
} = {}) {
value = (0, _formatCore.isAbsent)(value) ? _formatCore.ABSENT_VALUE_FORMAT : value;
const locale = (0, _formatCore.resolveLocale)(inputLocale);
const opts = (0, _formatCore.prepareFormatOptions)({
options,
signDisplay
});
if (clean) {
value = (0, _formatCore.cleanNumber)(value);
}
if (parseFloat(String(decimals)) >= 0) {
value = (0, _formatCore.formatDecimals)(value, decimals, rounding, opts);
}
if (decimals === null) {
if (typeof opts.maximumFractionDigits === 'undefined') {
decimals = (0, _decimals.countDecimals)(value);
}
value = (0, _formatCore.formatDecimals)(value, decimals, rounding, opts);
}
if (!opts.style) {
opts.style = 'percent';
}
const display = (0, _formatCore.formatNumberCore)(Number(value) / 100, locale, opts);
const aria = display;
if (!returnAria) {
return display;
}
return (0, _formatCore.buildReturn)({
value,
locale,
display,
aria,
type: 'number',
opts,
cleanCopyValue,
invalidAriaText
});
}
//# sourceMappingURL=formatPercent.js.map