| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /**
- * DevExtreme (localization/globalize/currency.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- function _typeof(obj) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
- return typeof obj
- } : function(obj) {
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
- }, _typeof(obj)
- }
- require("./core");
- require("./number");
- require("../currency");
- require("globalize/currency");
- var enCurrencyUSD = {
- main: {
- en: {
- identity: {
- version: {
- _cldrVersion: "28",
- _number: "$Revision: 11972 $"
- },
- language: "en"
- },
- numbers: {
- currencies: {
- USD: {
- displayName: "US Dollar",
- "displayName-count-one": "US dollar",
- "displayName-count-other": "US dollars",
- symbol: "$",
- "symbol-alt-narrow": "$"
- }
- }
- }
- }
- }
- };
- var currencyData = {
- supplemental: {
- version: {
- _cldrVersion: "28",
- _unicodeVersion: "8.0.0",
- _number: "$Revision: 11969 $"
- },
- currencyData: {
- fractions: {
- DEFAULT: {
- _rounding: "0",
- _digits: "2"
- }
- }
- }
- }
- };
- var Globalize = require("globalize");
- var config = require("../../core/config");
- var numberLocalization = require("../number");
- if (Globalize && Globalize.formatCurrency) {
- if ("en" === Globalize.locale().locale) {
- Globalize.load(enCurrencyUSD, currencyData);
- Globalize.locale("en")
- }
- var formattersCache = {};
- var getFormatter = function(currency, format) {
- var formatter;
- var formatCacheKey;
- if ("object" === _typeof(format)) {
- formatCacheKey = Globalize.locale().locale + ":" + currency + ":" + JSON.stringify(format)
- } else {
- formatCacheKey = Globalize.locale().locale + ":" + currency + ":" + format
- }
- formatter = formattersCache[formatCacheKey];
- if (!formatter) {
- formatter = formattersCache[formatCacheKey] = Globalize.currencyFormatter(currency, format)
- }
- return formatter
- };
- var globalizeCurrencyLocalization = {
- _formatNumberCore: function(value, format, formatConfig) {
- if ("currency" === format) {
- var currency = formatConfig && formatConfig.currency || config().defaultCurrency;
- return getFormatter(currency, this._normalizeFormatConfig(format, formatConfig, value))(value)
- }
- return this.callBase.apply(this, arguments)
- },
- _normalizeFormatConfig: function(format, formatConfig, value) {
- var config = this.callBase(format, formatConfig, value);
- if ("currency" === format) {
- config.style = "accounting"
- }
- return config
- },
- format: function(value, _format) {
- if ("number" !== typeof value) {
- return value
- }
- _format = this._normalizeFormat(_format);
- if (_format) {
- if ("default" === _format.currency) {
- _format.currency = config().defaultCurrency
- }
- if ("currency" === _format.type) {
- return this._formatNumber(value, this._parseNumberFormatString("currency"), _format)
- } else {
- if (!_format.type && _format.currency) {
- return getFormatter(_format.currency, _format)(value)
- }
- }
- }
- return this.callBase.apply(this, arguments)
- },
- getCurrencySymbol: function(currency) {
- if (!currency) {
- currency = config().defaultCurrency
- }
- return Globalize.cldr.main("numbers/currencies/" + currency)
- },
- getOpenXmlCurrencyFormat: function(currency) {
- var currencySymbol = this.getCurrencySymbol(currency).symbol;
- var currencyFormat = Globalize.cldr.main("numbers/currencyFormats-numberSystem-latn");
- var i;
- var result;
- var symbol;
- var encodeSymbols;
- if (currencyFormat.accounting) {
- encodeSymbols = {
- ".00": "{0}",
- "'": "\\'",
- "\\(": "\\(",
- "\\)": "\\)",
- " ": "\\ ",
- '"': """,
- "\\\xa4": currencySymbol
- };
- result = currencyFormat.accounting.split(";");
- for (i = 0; i < result.length; i++) {
- for (symbol in encodeSymbols) {
- if (Object.prototype.hasOwnProperty.call(encodeSymbols, symbol)) {
- result[i] = result[i].replace(new RegExp(symbol, "g"), encodeSymbols[symbol])
- }
- }
- }
- return 2 === result.length ? result[0] + "_);" + result[1] : result[0]
- }
- }
- };
- numberLocalization.inject(globalizeCurrencyLocalization)
- }
|