diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-09-27 21:54:39 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-09-27 21:54:39 -0700 |
commit | 236b10503612706ed914678d942ac604f2973f47 (patch) | |
tree | e557381dbdc721002346a0fc64b1a679280fa3f1 /modern/src/common/formatter.js | |
parent | 96af05dbf2171c4e194cf67c3c93d134ef467e50 (diff) | |
download | trackermap-web-236b10503612706ed914678d942ac604f2973f47.tar.gz trackermap-web-236b10503612706ed914678d942ac604f2973f47.tar.bz2 trackermap-web-236b10503612706ed914678d942ac604f2973f47.zip |
Implement notification settings
Diffstat (limited to 'modern/src/common/formatter.js')
-rw-r--r-- | modern/src/common/formatter.js | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js index 8ad87e70..29108cec 100644 --- a/modern/src/common/formatter.js +++ b/modern/src/common/formatter.js @@ -1,7 +1,10 @@ import moment from 'moment'; import t from '../common/localization'; -const formatValue = (key, value) => { +export const formatPosition = (key, value) => { + if (value != null && typeof value == 'object') { + value = value[key]; + } switch (key) { case 'fixTime': return moment(value).format('LLL'); @@ -15,19 +18,19 @@ const formatValue = (key, value) => { return value + '%'; default: if (typeof value === 'number') { - return Number(value.toFixed(1)); + return formatNumber(value); } else if (typeof value === 'boolean') { - return value ? t('sharedYes') : t('sharedNo'); + return formatBoolean(value); } else { return value; } } } -export default (object, key) => { - if (object != null && typeof object == 'object') { - return formatValue(key, object[key]); - } else { - return formatValue(key, object); - } -}; +export const formatBoolean = (value) => { + return value ? t('sharedYes') : t('sharedNo'); +} + +export const formatNumber = (value, precision = 1) => { + return Number(value.toFixed(precision)); +} |