aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/converter.js24
-rw-r--r--modern/src/common/deviceCategories.js2
-rw-r--r--modern/src/common/formatter.js54
-rw-r--r--modern/src/common/localization.js116
-rw-r--r--modern/src/common/preferences.js30
-rw-r--r--modern/src/common/stringUtils.js8
6 files changed, 102 insertions, 132 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js
index 9cdc6239..d45db5d6 100644
--- a/modern/src/common/converter.js
+++ b/modern/src/common/converter.js
@@ -1,4 +1,4 @@
-const speedConverter = unit => {
+const speedConverter = (unit) => {
switch (unit) {
case 'kmh':
return 1.852;
@@ -10,7 +10,7 @@ const speedConverter = unit => {
}
};
-const distanceConverter = unit => {
+const distanceConverter = (unit) => {
switch (unit) {
case 'mi':
return 0.000621371;
@@ -19,21 +19,13 @@ const distanceConverter = unit => {
case 'km':
default:
return 0.001;
- }
-}
+ }
+};
-export const speedFromKnots = (value, unit) => {
- return value * speedConverter(unit);
-}
+export const speedFromKnots = (value, unit) => value * speedConverter(unit);
-export const speedToKnots = (value, unit) => {
- return value / speedConverter(unit);
-}
+export const speedToKnots = (value, unit) => value / speedConverter(unit);
-export const distanceFromMeters = (value, unit) => {
- return value * distanceConverter(unit);
-}
+export const distanceFromMeters = (value, unit) => value * distanceConverter(unit);
-export const distanceToMeters = (value, unit) => {
- return value / distanceConverter(unit);
-}
+export const distanceToMeters = (value, unit) => value / distanceConverter(unit);
diff --git a/modern/src/common/deviceCategories.js b/modern/src/common/deviceCategories.js
index 1eda1902..f5d749aa 100644
--- a/modern/src/common/deviceCategories.js
+++ b/modern/src/common/deviceCategories.js
@@ -1,4 +1,4 @@
-export const deviceCategories = [
+export default [
'default',
'animal',
'bicycle',
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js
index 0d8ac4c9..3c0341b7 100644
--- a/modern/src/common/formatter.js
+++ b/modern/src/common/formatter.js
@@ -1,5 +1,11 @@
import moment from 'moment';
-import t from '../common/localization';
+import t from './localization';
+
+export const formatBoolean = (value) => (value ? t('sharedYes') : t('sharedNo'));
+
+export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision));
+
+export const formatDate = (value, format = 'YYYY-MM-DD HH:mm') => moment(value).format(format);
export const formatPosition = (value, key) => {
if (value != null && typeof value === 'object') {
@@ -18,30 +24,17 @@ export const formatPosition = (value, key) => {
case 'course':
return value.toFixed(1);
case 'batteryLevel':
- return value + '%';
+ return `${value}%`;
default:
if (typeof value === 'number') {
return formatNumber(value);
- } else if (typeof value === 'boolean') {
+ } if (typeof value === 'boolean') {
return formatBoolean(value);
- } else {
- return value;
}
+ return value;
}
};
-export const formatBoolean = (value) => {
- return value ? t('sharedYes') : t('sharedNo');
-};
-
-export const formatNumber = (value, precision = 1) => {
- return Number(value.toFixed(precision));
-};
-
-export const formatDate = (value, format = 'YYYY-MM-DD HH:mm') => {
- return moment(value).format(format);
-};
-
export const formatDistance = (value, unit) => {
switch (unit) {
case 'mi':
@@ -50,7 +43,7 @@ export const formatDistance = (value, unit) => {
return `${(value * 0.000539957).toFixed(2)} ${t('sharedNmi')}`;
case 'km':
default:
- return `${(value * 0.001).toFixed(2)} ${t('sharedKm')}`;
+ return `${(value * 0.001).toFixed(2)} ${t('sharedKm')}`;
}
};
@@ -62,8 +55,8 @@ export const formatSpeed = (value, unit) => {
return `${(value * 1.15078).toFixed(2)} ${t('sharedMph')}`;
case 'kn':
default:
- return `${(value * 1).toFixed(2)} ${t('sharedKn')}`;
- }
+ return `${(value * 1).toFixed(2)} ${t('sharedKn')}`;
+ }
};
export const formatVolume = (value, unit) => {
@@ -74,16 +67,15 @@ export const formatVolume = (value, unit) => {
return `${(value / 3.785).toFixed(2)} ${t('sharedGallonAbbreviation')}`;
case 'ltr':
default:
- return `${(value / 1).toFixed(2)} ${t('sharedLiterAbbreviation')}`;
- }
-}
-
-export const formatHours = (value) => {
- return moment.duration(value).humanize();
+ return `${(value / 1).toFixed(2)} ${t('sharedLiterAbbreviation')}`;
+ }
};
+export const formatHours = (value) => moment.duration(value).humanize();
+
export const formatCoordinate = (key, value, unit) => {
- var hemisphere, degrees, minutes, seconds;
+ let hemisphere; let degrees; let minutes; let
+ seconds;
if (key === 'latitude') {
hemisphere = value >= 0 ? 'N' : 'S';
} else {
@@ -95,14 +87,14 @@ export const formatCoordinate = (key, value, unit) => {
value = Math.abs(value);
degrees = Math.floor(value);
minutes = (value - degrees) * 60;
- return degrees + '° ' + minutes.toFixed(6) + '\' ' + hemisphere;
+ return `${degrees}° ${minutes.toFixed(6)}' ${hemisphere}`;
case 'dms':
value = Math.abs(value);
degrees = Math.floor(value);
minutes = Math.floor((value - degrees) * 60);
seconds = Math.round((value - degrees - minutes / 60) * 3600);
- return degrees + '° ' + minutes + '\' ' + seconds + '" ' + hemisphere;
+ return `${degrees}° ${minutes}' ${seconds}" ${hemisphere}`;
default:
- return value.toFixed(6) + '°';
- }
+ return `${value.toFixed(6)}°`;
+ }
};
diff --git a/modern/src/common/localization.js b/modern/src/common/localization.js
index cb1420bb..9e2123a9 100644
--- a/modern/src/common/localization.js
+++ b/modern/src/common/localization.js
@@ -54,60 +54,60 @@ import zh from '../../../web/l10n/zh.json';
import zh_TW from '../../../web/l10n/zh_TW.json';
const supportedLanguages = {
- 'af': { data: af, name: 'Afrikaans' },
- 'ar': { data: ar, name: 'العربية' },
- 'az': { data: az, name: 'Azərbaycanca' },
- 'bg': { data: bg, name: 'Български' },
- 'bn': { data: bn, name: 'বাংলা' },
- 'cs': { data: cs, name: 'Čeština' },
- 'de': { data: de, name: 'Deutsch' },
- 'da': { data: da, name: 'Dansk' },
- 'el': { data: el, name: 'Ελληνικά' },
- 'en': { data: en, name: 'English' },
- 'es': { data: es, name: 'Español' },
- 'fa': { data: fa, name: 'فارسی' },
- 'fi': { data: fi, name: 'Suomi' },
- 'fr': { data: fr, name: 'Français' },
- 'he': { data: he, name: 'עברית' },
- 'hi': { data: hi, name: 'हिन्दी' },
- 'hr': { data: hr, name: 'Hrvatski' },
- 'hu': { data: hu, name: 'Magyar' },
- 'id': { data: id, name: 'Bahasa Indonesia' },
- 'it': { data: it, name: 'Italiano' },
- 'ja': { data: ja, name: '日本語' },
- 'ka': { data: ka, name: 'ქართული' },
- 'kk': { data: kk, name: 'Қазақша' },
- 'ko': { data: ko, name: '한국어' },
- 'km': { data: km, name: 'ភាសាខ្មែរ' },
- 'lo': { data: lo, name: 'ລາວ' },
- 'lt': { data: lt, name: 'Lietuvių' },
- 'lv': { data: lv, name: 'Latviešu' },
- 'ml': { data: ml, name: 'മലയാളം' },
- 'mn': { data: mn, name: 'Монгол хэл' },
- 'ms': { data: ms, name: 'بهاس ملايو' },
- 'nb': { data: nb, name: 'Norsk bokmål' },
- 'ne': { data: ne, name: 'नेपाली' },
- 'nl': { data: nl, name: 'Nederlands' },
- 'nn': { data: nn, name: 'Norsk nynorsk' },
- 'pl': { data: pl, name: 'Polski' },
- 'pt': { data: pt, name: 'Português' },
- 'pt_BR': { data: pt_BR, name: 'Português (Brasil)' },
- 'ro': { data: ro, name: 'Română' },
- 'ru': { data: ru, name: 'Русский' },
- 'si': { data: si, name: 'සිංහල' },
- 'sk': { data: sk, name: 'Slovenčina' },
- 'sl': { data: sl, name: 'Slovenščina' },
- 'sq': { data: sq, name: 'Shqipëria' },
- 'sr': { data: sr, name: 'Srpski' },
- 'sv': { data: sv, name: 'Svenska' },
- 'ta': { data: ta, name: 'தமிழ்' },
- 'th': { data: th, name: 'ไทย' },
- 'tr': { data: tr, name: 'Türkçe' },
- 'uk': { data: uk, name: 'Українська' },
- 'uz': { data: uz, name: 'Oʻzbekcha' },
- 'vi': { data: vi, name: 'Tiếng Việt' },
- 'zh': { data: zh, name: '中文' },
- 'zh_TW': { data: zh_TW, name: '中文 (Taiwan)' }
+ af: { data: af, name: 'Afrikaans' },
+ ar: { data: ar, name: 'العربية' },
+ az: { data: az, name: 'Azərbaycanca' },
+ bg: { data: bg, name: 'Български' },
+ bn: { data: bn, name: 'বাংলা' },
+ cs: { data: cs, name: 'Čeština' },
+ de: { data: de, name: 'Deutsch' },
+ da: { data: da, name: 'Dansk' },
+ el: { data: el, name: 'Ελληνικά' },
+ en: { data: en, name: 'English' },
+ es: { data: es, name: 'Español' },
+ fa: { data: fa, name: 'فارسی' },
+ fi: { data: fi, name: 'Suomi' },
+ fr: { data: fr, name: 'Français' },
+ he: { data: he, name: 'עברית' },
+ hi: { data: hi, name: 'हिन्दी' },
+ hr: { data: hr, name: 'Hrvatski' },
+ hu: { data: hu, name: 'Magyar' },
+ id: { data: id, name: 'Bahasa Indonesia' },
+ it: { data: it, name: 'Italiano' },
+ ja: { data: ja, name: '日本語' },
+ ka: { data: ka, name: 'ქართული' },
+ kk: { data: kk, name: 'Қазақша' },
+ ko: { data: ko, name: '한국어' },
+ km: { data: km, name: 'ភាសាខ្មែរ' },
+ lo: { data: lo, name: 'ລາວ' },
+ lt: { data: lt, name: 'Lietuvių' },
+ lv: { data: lv, name: 'Latviešu' },
+ ml: { data: ml, name: 'മലയാളം' },
+ mn: { data: mn, name: 'Монгол хэл' },
+ ms: { data: ms, name: 'بهاس ملايو' },
+ nb: { data: nb, name: 'Norsk bokmål' },
+ ne: { data: ne, name: 'नेपाली' },
+ nl: { data: nl, name: 'Nederlands' },
+ nn: { data: nn, name: 'Norsk nynorsk' },
+ pl: { data: pl, name: 'Polski' },
+ pt: { data: pt, name: 'Português' },
+ pt_BR: { data: pt_BR, name: 'Português (Brasil)' },
+ ro: { data: ro, name: 'Română' },
+ ru: { data: ru, name: 'Русский' },
+ si: { data: si, name: 'සිංහල' },
+ sk: { data: sk, name: 'Slovenčina' },
+ sl: { data: sl, name: 'Slovenščina' },
+ sq: { data: sq, name: 'Shqipëria' },
+ sr: { data: sr, name: 'Srpski' },
+ sv: { data: sv, name: 'Svenska' },
+ ta: { data: ta, name: 'தமிழ்' },
+ th: { data: th, name: 'ไทย' },
+ tr: { data: tr, name: 'Türkçe' },
+ uk: { data: uk, name: 'Українська' },
+ uz: { data: uz, name: 'Oʻzbekcha' },
+ vi: { data: vi, name: 'Tiếng Việt' },
+ zh: { data: zh, name: '中文' },
+ zh_TW: { data: zh_TW, name: '中文 (Taiwan)' },
};
const languages = window.navigator.languages !== undefined ? window.navigator.languages.slice() : [];
@@ -130,10 +130,6 @@ for (let i = 0; i < languages.length; i++) {
const selectedLanguage = supportedLanguages[language];
-export const findStringKeys = (predicate) => {
- return Object.keys(selectedLanguage.data).filter(predicate);
-}
+export const findStringKeys = (predicate) => Object.keys(selectedLanguage.data).filter(predicate);
-export default key => {
- return selectedLanguage.data[key];
-};
+export default (key) => selectedLanguage.data[key];
diff --git a/modern/src/common/preferences.js b/modern/src/common/preferences.js
index 24fe389a..aba3c82c 100644
--- a/modern/src/common/preferences.js
+++ b/modern/src/common/preferences.js
@@ -1,21 +1,15 @@
import { useSelector } from 'react-redux';
-export const usePreference = (key, defaultValue) => {
- return useSelector(state => {
- if (state.session.server.forceSettings) {
- return state.session.server[key] || state.session.user[key] || defaultValue;
- } else {
- return state.session.user[key] || state.session.server[key] || defaultValue;
- }
- });
-};
+export const usePreference = (key, defaultValue) => useSelector((state) => {
+ if (state.session.server.forceSettings) {
+ return state.session.server[key] || state.session.user[key] || defaultValue;
+ }
+ return state.session.user[key] || state.session.server[key] || defaultValue;
+});
-export const useAttributePreference = (key, defaultValue) => {
- return useSelector(state => {
- if (state.session.server.forceSettings) {
- return state.session.server.attributes[key] || state.session.user.attributes[key] || defaultValue;
- } else {
- return state.session.user.attributes[key] || state.session.server.attributes[key] || defaultValue;
- }
- });
-};
+export const useAttributePreference = (key, defaultValue) => useSelector((state) => {
+ if (state.session.server.forceSettings) {
+ return state.session.server.attributes[key] || state.session.user.attributes[key] || defaultValue;
+ }
+ return state.session.user.attributes[key] || state.session.server.attributes[key] || defaultValue;
+});
diff --git a/modern/src/common/stringUtils.js b/modern/src/common/stringUtils.js
index 7bd68c85..fc997fe0 100644
--- a/modern/src/common/stringUtils.js
+++ b/modern/src/common/stringUtils.js
@@ -1,7 +1,3 @@
-export const prefixString = (prefix, value) => {
- return prefix + value.charAt(0).toUpperCase() + value.slice(1);
-}
+export const prefixString = (prefix, value) => prefix + value.charAt(0).toUpperCase() + value.slice(1);
-export const unprefixString = (prefix, value) => {
- return value.charAt(prefix.length).toLowerCase() + value.slice(prefix.length + 1);
-}
+export const unprefixString = (prefix, value) => value.charAt(prefix.length).toLowerCase() + value.slice(prefix.length + 1);