aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/converter.js
blob: 930dba153f1bfc6f462f5164213a90dcebf4be1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export const speedConverter = (value, unit, back = false) => {
  let factor;
  switch (unit) {
    case 'kmh':
      factor = 1.852;
      break;
    case 'mph':
      factor = 1.15078;
      break;
    case 'kn':
    default:
      factor = 1;
  }
  return back ? (value / factor).toFixed(2):(value * factor).toFixed(2);
};

export const distanceConverter = (value, unit, back = false) => {
  let factor;
  switch (unit) {
    case 'mi':
      factor = 0.000621371;
      break;
    case 'nmi':
      factor = 0.000539957;
      break;
    case 'km':
    default:
      factor = 0.001;
  }
  return back ? value / factor : value * factor;  
}