MCPcopy
hub / github.com/deepops-ai/deepops / mapValueToText

Function mapValueToText

ui/src/utils/valueMapping.ts:4–31  ·  view source on GitHub ↗
(value: number | string, mapping: ValueMappingItem[])

Source from the content-addressed store, hash-verified

2import { isEmpty } from "./validate";
3
4export 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}

Callers 1

ComplexTable.tsxFile · 0.90

Calls 1

isEmptyFunction · 0.90

Tested by

no test coverage detected