@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
65 lines (64 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatNumber = formatNumber;
var _formatCore = require("./formatCore.js");
function formatNumber(value, {
locale: inputLocale = null,
clean = false,
compact = null,
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);
}
value = (0, _formatCore.applyDecimalsForPlain)({
value,
decimals,
rounding,
opts
});
(0, _formatCore.handleCompactBeforeDisplay)({
value,
locale,
compact,
decimals,
opts
});
let display = (0, _formatCore.formatNumberCore)(value, locale, opts);
display = (0, _formatCore.prepareMinus)(display, locale);
(0, _formatCore.handleCompactBeforeAria)({
value,
compact,
opts
});
let aria = (0, _formatCore.formatNumberCore)(value, locale, opts);
aria = (0, _formatCore.enhanceSR)(value, aria, locale);
if (!returnAria) {
return display;
}
return (0, _formatCore.buildReturn)({
value,
locale,
display,
aria,
type: 'number',
opts,
cleanCopyValue,
invalidAriaText
});
}
//# sourceMappingURL=formatNumber.js.map