aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/formatter.js
blob: 8ad87e70f855f0629b5fe6f711e2d4b6ecd428ef (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
32
33
import moment from 'moment';
import t from '../common/localization';

const formatValue = (key, value) => {
  switch (key) {
    case 'fixTime':
      return moment(value).format('LLL');
    case 'latitude':
    case 'longitude':
      return value.toFixed(5);
    case 'speed':
    case 'course':
      return value.toFixed(1);
    case 'batteryLevel':
      return value + '%';
    default:
      if (typeof value === 'number') {
        return Number(value.toFixed(1));
      } else if (typeof value === 'boolean') {
        return value ? t('sharedYes') : t('sharedNo');
      } else {
        return value;
      }
  }
}

export default (object, key) => {
  if (object != null && typeof object == 'object') {
    return formatValue(key, object[key]);
  } else {
    return formatValue(key, object);
  }
};