(value, config, timezone)
| 5 | const checkNumbersOnly = /^\d+$/; |
| 6 | |
| 7 | function formatValue(value, config, timezone) { |
| 8 | if (!config || !config.type || !value) return value; |
| 9 | |
| 10 | if (config.type === "date" && determineType(value) === "date" && config.format) { |
| 11 | const isTimestamp = value.toString().length === 10 && `${value}`.match(checkNumbersOnly); |
| 12 | const momentObj = isTimestamp ? moment.utc(value, "X") : moment.utc(value); |
| 13 | return timezone |
| 14 | ? momentObj.tz(timezone).format(config.format) |
| 15 | : momentObj.format(config.format); |
| 16 | } else if ((config.type === "number" || config.type === "currency") |
| 17 | && (determineType(value) === "number" || `${value}`.match(checkNumbersOnly)) |
| 18 | ) { |
| 19 | let finalNumber = value; |
| 20 | if (config.decimals > -1) { |
| 21 | finalNumber = Number(value).toFixed(config.decimals); |
| 22 | } |
| 23 | if (config.thousandsSeparator) { |
| 24 | finalNumber = finalNumber.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 25 | } |
| 26 | if (config.type === "currency" && config.symbol) { |
| 27 | finalNumber = `${config.symbol}${finalNumber}`; |
| 28 | } |
| 29 | return finalNumber; |
| 30 | } |
| 31 | |
| 32 | // value mapping |
| 33 | if (config.display?.format === "mapping" && config.display?.rules) { |
| 34 | const rule = config.display.rules.find((rule) => rule.value === value); |
| 35 | if (rule) { |
| 36 | return rule.label; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return value; |
| 41 | } |
| 42 | |
| 43 | class TableView { |
| 44 | getTableData(data, chartData, timezone = "") { |
no test coverage detected