aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-02-14 13:40:40 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2021-02-14 13:40:40 +0530
commit5970936c860285576848d170dd91bfcc488c941e (patch)
tree087d399c90f29743f0250cbf45616027f6bb191b /modern/src/common
parent3e5ef37008fd009821181b1d539622a44b8cd745 (diff)
downloadtrackermap-web-5970936c860285576848d170dd91bfcc488c941e.tar.gz
trackermap-web-5970936c860285576848d170dd91bfcc488c941e.tar.bz2
trackermap-web-5970936c860285576848d170dd91bfcc488c941e.zip
Code improvement and deduplication
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/converter.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js
index 930dba15..26e2a82b 100644
--- a/modern/src/common/converter.js
+++ b/modern/src/common/converter.js
@@ -1,4 +1,4 @@
-export const speedConverter = (value, unit, back = false) => {
+const speedConverter = (value, unit, back = false) => {
let factor;
switch (unit) {
case 'kmh':
@@ -11,10 +11,10 @@ export const speedConverter = (value, unit, back = false) => {
default:
factor = 1;
}
- return back ? (value / factor).toFixed(2):(value * factor).toFixed(2);
+ return back ? value / factor: value * factor;
};
-export const distanceConverter = (value, unit, back = false) => {
+const distanceConverter = (value, unit, back = false) => {
let factor;
switch (unit) {
case 'mi':
@@ -28,4 +28,20 @@ export const distanceConverter = (value, unit, back = false) => {
factor = 0.001;
}
return back ? value / factor : value * factor;
-} \ No newline at end of file
+}
+
+export const speedFromKnots = (value, unit) => {
+ return speedConverter(value, unit);
+}
+
+export const speedToKnots = (value, unit) => {
+ return speedConverter(value, unit, true);
+}
+
+export const distanceFromMeters = (value, unit) => {
+ return distanceConverter(value, unit);
+}
+
+export const distanceToMeters = (value, unit) => {
+ return distanceConverter(value, unit, true);
+}