(value:number, thresholds: ThresholdsConfig, max?:number)
| 1 | import { Threshold, ThresholdsConfig } from "types/threshold"; |
| 2 | |
| 3 | export const getThreshold = (value:number, thresholds: ThresholdsConfig, max?:number): Threshold => { |
| 4 | let t; |
| 5 | if (!thresholds) { |
| 6 | return t |
| 7 | } |
| 8 | if (thresholds.mode == 'absolute') { |
| 9 | t = thresholds.thresholds.find(s => s.value <= value) |
| 10 | } else { |
| 11 | if (max == undefined || max == null) { |
| 12 | console.error("max is required when thresholds mode is percentage") |
| 13 | return null |
| 14 | } |
| 15 | |
| 16 | const percentage = value / max * 100 |
| 17 | t = thresholds.thresholds.find(s => s.value <= percentage) |
| 18 | } |
| 19 | |
| 20 | if (!t && thresholds.thresholds.length > 0) { |
| 21 | // use base one |
| 22 | t = thresholds.thresholds[thresholds.thresholds.length - 1] |
| 23 | } |
| 24 | |
| 25 | return t |
| 26 | } |
no test coverage detected