devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
93 lines (91 loc) • 4.33 kB
JavaScript
/**
* DevExtreme (cjs/__internal/core/localization/globalize/currency.js)
* Version: 25.2.7
* Build date: Tue May 05 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
require("../../../core/localization/globalize/core");
require("../../../core/localization/globalize/number");
require("../../../core/localization/currency");
require("globalize/currency");
var _config = _interopRequireDefault(require("../../../../core/config"));
var _number2 = _interopRequireDefault(require("../../../core/localization/number"));
var _open_xml_currency_format = _interopRequireDefault(require("../../../core/localization/open_xml_currency_format"));
var _globalize = _interopRequireDefault(require("globalize"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const CURRENCY_STYLES = ["symbol", "accounting"];
if (null !== _globalize.default && void 0 !== _globalize.default && _globalize.default.formatCurrency) {
if ("en" === _globalize.default.locale().locale) {
_globalize.default.locale("en")
}
const formattersCache = {};
const getFormatter = (currency, format) => {
let formatter;
let formatCacheKey;
if ("object" === typeof format) {
formatCacheKey = `${_globalize.default.locale().locale}:${currency}:${JSON.stringify(format)}`
} else {
formatCacheKey = `${_globalize.default.locale().locale}:${currency}:${format}`
}
formatter = formattersCache[formatCacheKey];
if (!formatter) {
formatter = _globalize.default.currencyFormatter(currency, format);
formattersCache[formatCacheKey] = formatter
}
return formatter
};
const globalizeCurrencyLocalization = {
_formatNumberCore(value, format, formatConfig) {
if ("currency" === format) {
const currency = (null === formatConfig || void 0 === formatConfig ? void 0 : formatConfig.currency) ?? (0, _config.default)().defaultCurrency;
return getFormatter(currency, this._normalizeFormatConfig(format, formatConfig, value))(value)
}
return this.callBase.apply(this, [value, format, formatConfig])
},
_normalizeFormatConfig(format, formatConfig, value) {
const normalizedConfig = this.callBase.apply(this, [format, formatConfig, value]);
if ("currency" === format) {
const useAccountingStyle = formatConfig.useCurrencyAccountingStyle ?? (0, _config.default)().defaultUseCurrencyAccountingStyle;
normalizedConfig.style = CURRENCY_STYLES[+useAccountingStyle]
}
return normalizedConfig
},
format(value, format) {
if ("number" !== typeof value) {
return value
}
format = this._normalizeFormat(format);
if (format) {
if ("default" === format.currency) {
format.currency = (0, _config.default)().defaultCurrency
}
if ("currency" === format.type) {
return this._formatNumber(value, this._parseNumberFormatString("currency"), format)
}
if (!format.type && format.currency) {
return getFormatter(format.currency, format)(value)
}
}
return this.callBase.apply(this, [value, format])
},
getCurrencySymbol(currency) {
if (!currency) {
currency = (0, _config.default)().defaultCurrency
}
return _globalize.default.cldr.main(`numbers/currencies/${currency}`)
},
getOpenXmlCurrencyFormat(currency) {
const currencySymbol = this.getCurrencySymbol(currency).symbol;
const accountingFormat = _globalize.default.cldr.main("numbers/currencyFormats-numberSystem-latn").accounting;
return (0, _open_xml_currency_format.default)(currencySymbol, accountingFormat)
}
};
_number2.default.inject(globalizeCurrencyLocalization)
}