(value: number | string, mapping: ValueMappingItem[])
| 2 | import { isEmpty } from "./validate"; |
| 3 | |
| 4 | export const mapValueToText = (value: number | string, mapping: ValueMappingItem[]) => { |
| 5 | let text; |
| 6 | let color; |
| 7 | for (const m of mapping) { |
| 8 | if (isEmpty(m.text)) { |
| 9 | continue |
| 10 | } |
| 11 | if (m.type == "value" && m.value == value) { |
| 12 | text = m.text |
| 13 | color = m.color |
| 14 | break |
| 15 | } else if (m.type == "range" && value >= m.value.from && value <= m.value.to) { |
| 16 | text = m.text |
| 17 | color = m.color |
| 18 | break |
| 19 | } else if (m.type == "null" && isEmpty(value)) { |
| 20 | text = m.text |
| 21 | color = m.color |
| 22 | break |
| 23 | } else if (m.type == "regex" && value?.toString().match(m.value)) { |
| 24 | text = m.text |
| 25 | color = m.color |
| 26 | break |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return [text, color] |
| 31 | } |
no test coverage detected