From d69bb2b2c3053c2c61e4e5d7029751debcfb0dd9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 25 Jul 2020 12:36:19 -0700 Subject: Implement simple route report --- modern/src/common/formatter.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 modern/src/common/formatter.js (limited to 'modern/src/common') diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js new file mode 100644 index 00000000..ce46c6cf --- /dev/null +++ b/modern/src/common/formatter.js @@ -0,0 +1,23 @@ +import moment from 'moment'; + +const formatValue = (key, value) => { + switch (key) { + case 'fixTime': + return moment(value).format('LLL'); + case 'latitude': + case 'longitude': + return value.toFixed(5); + case 'speed': + return value.toFixed(1); + default: + return value; + } +} + +export default (object, key) => { + if (object != null && typeof object == 'object') { + return formatValue(key, object[key]); + } else { + return formatValue(key, object); + } +}; -- cgit v1.2.3