const leftColor = { HZ: "#008c5e", HL: "#008c5e", HO: "#008c5e", HF: "#008c5e", NZ: "#7f8c95", NL: "#7f8c95", NO: "#7f8c95", NF: "#7f8c95", } const rightTopColor = { HZ: "#008c5e", HL: "red", HO: "#7f8c95", HF: "#008c5e", NZ: "#008c5e", NL: "red", NO: "#7f8c95", NF: "#008c5e", } export function handleColor(data) { if (checkType(data) == "array") { data.map((item) => { if (!item.color) { item.leftColor = "#7b75ff"; item.rightTopColor = "#7b75ff"; return; } for (let key in leftColor) { if (item.color == key) { item.leftColor = leftColor[key]; item.rightTopColor = rightTopColor[key]; } } }); return data; } else if (checkType(data) == "object") { if (!data.color) { data.leftColor = "#7b75ff"; data.rightTopColor = "#7b75ff"; return; } for (let key in leftColor) { if (data.color == key) { data.leftColor = leftColor[key]; data.rightTopColor = rightTopColor[key]; } } return data; } else { return data; } } function checkType(value) { if (Array.isArray(value)) { return "array"; } else if (value !== null && typeof value === "object") { return "object"; } else { return "neither"; } }