"npx prettier" pass on the files changed in this PR
Does not include changes to `website/src/lib/db.ts`, because there would otherwise be lots of unrelated formatting changes
This commit is contained in:
parent
7db43d3e35
commit
62da9b7f37
3 changed files with 249 additions and 230 deletions
|
|
@ -23,18 +23,18 @@
|
||||||
|
|
||||||
<span class={$$props.class}>
|
<span class={$$props.class}>
|
||||||
{#if type === 'distance'}
|
{#if type === 'distance'}
|
||||||
{ getConvertedDistance(value, $distanceUnits).toFixed(decimals ?? 2) }
|
{getConvertedDistance(value, $distanceUnits).toFixed(decimals ?? 2)}
|
||||||
{ showUnits ? getDistanceUnits($distanceUnits) : '' }
|
{showUnits ? getDistanceUnits($distanceUnits) : ''}
|
||||||
{:else if type === 'elevation'}
|
{:else if type === 'elevation'}
|
||||||
{ getConvertedElevation(value, $distanceUnits).toFixed(decimals ?? 2) }
|
{getConvertedElevation(value, $distanceUnits).toFixed(decimals ?? 2)}
|
||||||
{ showUnits ? getElevationUnits($distanceUnits) : '' }
|
{showUnits ? getElevationUnits($distanceUnits) : ''}
|
||||||
{:else if type === 'speed'}
|
{:else if type === 'speed'}
|
||||||
{#if $velocityUnits === 'speed'}
|
{#if $velocityUnits === 'speed'}
|
||||||
{ getConvertedVelocity(value, $velocityUnits, $distanceUnits).toFixed(decimals ?? 2) }
|
{getConvertedVelocity(value, $velocityUnits, $distanceUnits).toFixed(decimals ?? 2)}
|
||||||
{ showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : '' }
|
{showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : ''}
|
||||||
{:else}
|
{:else}
|
||||||
{ secondsToHHMMSS(getConvertedVelocity(value, $velocityUnits, $distanceUnits)) }
|
{secondsToHHMMSS(getConvertedVelocity(value, $velocityUnits, $distanceUnits))}
|
||||||
{ showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : '' }
|
{showUnits ? getVelocityUnits($velocityUnits, $distanceUnits) : ''}
|
||||||
{/if}
|
{/if}
|
||||||
{:else if type === 'temperature'}
|
{:else if type === 'temperature'}
|
||||||
{#if $temperatureUnits === 'celsius'}
|
{#if $temperatureUnits === 'celsius'}
|
||||||
|
|
@ -43,6 +43,6 @@
|
||||||
{celsiusToFahrenheit(value)} {showUnits ? $_('units.fahrenheit') : ''}
|
{celsiusToFahrenheit(value)} {showUnits ? $_('units.fahrenheit') : ''}
|
||||||
{/if}
|
{/if}
|
||||||
{:else if type === 'time'}
|
{:else if type === 'time'}
|
||||||
{ secondsToHHMMSS(value) }
|
{secondsToHHMMSS(value)}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -1,129 +1,141 @@
|
||||||
import { PUBLIC_MAPBOX_TOKEN } from "$env/static/public";
|
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
||||||
import { basemaps } from "$lib/assets/layers";
|
import { basemaps } from '$lib/assets/layers';
|
||||||
|
|
||||||
export type EmbeddingOptions = {
|
export type EmbeddingOptions = {
|
||||||
token: string;
|
token: string;
|
||||||
files: string[];
|
files: string[];
|
||||||
basemap: string;
|
basemap: string;
|
||||||
elevation: {
|
elevation: {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
height: number,
|
height: number;
|
||||||
controls: boolean,
|
controls: boolean;
|
||||||
fill: 'slope' | 'surface' | undefined,
|
fill: 'slope' | 'surface' | undefined;
|
||||||
speed: boolean,
|
speed: boolean;
|
||||||
hr: boolean,
|
hr: boolean;
|
||||||
cad: boolean,
|
cad: boolean;
|
||||||
temp: boolean,
|
temp: boolean;
|
||||||
power: boolean,
|
power: boolean;
|
||||||
},
|
};
|
||||||
distanceMarkers: boolean,
|
distanceMarkers: boolean;
|
||||||
directionMarkers: boolean,
|
directionMarkers: boolean;
|
||||||
distanceUnits: 'metric' | 'imperial' | 'nautical',
|
distanceUnits: 'metric' | 'imperial' | 'nautical';
|
||||||
velocityUnits: 'speed' | 'pace',
|
velocityUnits: 'speed' | 'pace';
|
||||||
temperatureUnits: 'celsius' | 'fahrenheit',
|
temperatureUnits: 'celsius' | 'fahrenheit';
|
||||||
theme: 'system' | 'light' | 'dark',
|
theme: 'system' | 'light' | 'dark';
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultEmbeddingOptions = {
|
export const defaultEmbeddingOptions = {
|
||||||
token: '',
|
token: '',
|
||||||
files: [],
|
files: [],
|
||||||
basemap: 'mapboxOutdoors',
|
basemap: 'mapboxOutdoors',
|
||||||
elevation: {
|
elevation: {
|
||||||
show: true,
|
show: true,
|
||||||
height: 170,
|
height: 170,
|
||||||
controls: true,
|
controls: true,
|
||||||
fill: undefined,
|
fill: undefined,
|
||||||
speed: false,
|
speed: false,
|
||||||
hr: false,
|
hr: false,
|
||||||
cad: false,
|
cad: false,
|
||||||
temp: false,
|
temp: false,
|
||||||
power: false,
|
power: false
|
||||||
},
|
},
|
||||||
distanceMarkers: false,
|
distanceMarkers: false,
|
||||||
directionMarkers: false,
|
directionMarkers: false,
|
||||||
distanceUnits: 'metric',
|
distanceUnits: 'metric',
|
||||||
velocityUnits: 'speed',
|
velocityUnits: 'speed',
|
||||||
temperatureUnits: 'celsius',
|
temperatureUnits: 'celsius',
|
||||||
theme: 'system',
|
theme: 'system'
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getDefaultEmbeddingOptions(): EmbeddingOptions {
|
export function getDefaultEmbeddingOptions(): EmbeddingOptions {
|
||||||
return JSON.parse(JSON.stringify(defaultEmbeddingOptions));
|
return JSON.parse(JSON.stringify(defaultEmbeddingOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMergedEmbeddingOptions(options: any, defaultOptions: any = defaultEmbeddingOptions): EmbeddingOptions {
|
export function getMergedEmbeddingOptions(
|
||||||
const mergedOptions = JSON.parse(JSON.stringify(defaultOptions));
|
options: any,
|
||||||
for (const key in options) {
|
defaultOptions: any = defaultEmbeddingOptions
|
||||||
if (typeof options[key] === 'object' && options[key] !== null && !Array.isArray(options[key])) {
|
): EmbeddingOptions {
|
||||||
mergedOptions[key] = getMergedEmbeddingOptions(options[key], defaultOptions[key]);
|
const mergedOptions = JSON.parse(JSON.stringify(defaultOptions));
|
||||||
} else {
|
for (const key in options) {
|
||||||
mergedOptions[key] = options[key];
|
if (typeof options[key] === 'object' && options[key] !== null && !Array.isArray(options[key])) {
|
||||||
}
|
mergedOptions[key] = getMergedEmbeddingOptions(options[key], defaultOptions[key]);
|
||||||
}
|
} else {
|
||||||
return mergedOptions;
|
mergedOptions[key] = options[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mergedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCleanedEmbeddingOptions(options: any, defaultOptions: any = defaultEmbeddingOptions): any {
|
export function getCleanedEmbeddingOptions(
|
||||||
const cleanedOptions = JSON.parse(JSON.stringify(options));
|
options: any,
|
||||||
for (const key in cleanedOptions) {
|
defaultOptions: any = defaultEmbeddingOptions
|
||||||
if (typeof cleanedOptions[key] === 'object' && cleanedOptions[key] !== null && !Array.isArray(cleanedOptions[key])) {
|
): any {
|
||||||
cleanedOptions[key] = getCleanedEmbeddingOptions(cleanedOptions[key], defaultOptions[key]);
|
const cleanedOptions = JSON.parse(JSON.stringify(options));
|
||||||
if (Object.keys(cleanedOptions[key]).length === 0) {
|
for (const key in cleanedOptions) {
|
||||||
delete cleanedOptions[key];
|
if (
|
||||||
}
|
typeof cleanedOptions[key] === 'object' &&
|
||||||
} else if (JSON.stringify(cleanedOptions[key]) === JSON.stringify(defaultOptions[key])) {
|
cleanedOptions[key] !== null &&
|
||||||
delete cleanedOptions[key];
|
!Array.isArray(cleanedOptions[key])
|
||||||
}
|
) {
|
||||||
}
|
cleanedOptions[key] = getCleanedEmbeddingOptions(cleanedOptions[key], defaultOptions[key]);
|
||||||
return cleanedOptions;
|
if (Object.keys(cleanedOptions[key]).length === 0) {
|
||||||
|
delete cleanedOptions[key];
|
||||||
|
}
|
||||||
|
} else if (JSON.stringify(cleanedOptions[key]) === JSON.stringify(defaultOptions[key])) {
|
||||||
|
delete cleanedOptions[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const allowedEmbeddingBasemaps = Object.keys(basemaps).filter(basemap => !['ordnanceSurvey'].includes(basemap));
|
export const allowedEmbeddingBasemaps = Object.keys(basemaps).filter(
|
||||||
|
(basemap) => !['ordnanceSurvey'].includes(basemap)
|
||||||
|
);
|
||||||
|
|
||||||
export function getURLForGoogleDriveFile(fileId: string): string {
|
export function getURLForGoogleDriveFile(fileId: string): string {
|
||||||
return `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=AIzaSyA2ZadQob_hXiT2VaYIkAyafPvz_4ZMssk`;
|
return `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=AIzaSyA2ZadQob_hXiT2VaYIkAyafPvz_4ZMssk`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
||||||
let newOptions: any = {
|
let newOptions: any = {
|
||||||
token: PUBLIC_MAPBOX_TOKEN,
|
token: PUBLIC_MAPBOX_TOKEN,
|
||||||
files: [],
|
files: []
|
||||||
};
|
};
|
||||||
if (options.has('state')) {
|
if (options.has('state')) {
|
||||||
let state = JSON.parse(options.get('state')!);
|
let state = JSON.parse(options.get('state')!);
|
||||||
if (state.ids) {
|
if (state.ids) {
|
||||||
newOptions.files.push(...state.ids.map(getURLForGoogleDriveFile));
|
newOptions.files.push(...state.ids.map(getURLForGoogleDriveFile));
|
||||||
}
|
}
|
||||||
if (state.urls) {
|
if (state.urls) {
|
||||||
newOptions.files.push(...state.urls);
|
newOptions.files.push(...state.urls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.has('source')) {
|
if (options.has('source')) {
|
||||||
let basemap = options.get('source')!;
|
let basemap = options.get('source')!;
|
||||||
if (basemap === 'satellite') {
|
if (basemap === 'satellite') {
|
||||||
newOptions.basemap = 'mapboxSatellite';
|
newOptions.basemap = 'mapboxSatellite';
|
||||||
} else if (basemap === 'otm') {
|
} else if (basemap === 'otm') {
|
||||||
newOptions.basemap = 'openTopoMap';
|
newOptions.basemap = 'openTopoMap';
|
||||||
} else if (basemap === 'ohm') {
|
} else if (basemap === 'ohm') {
|
||||||
newOptions.basemap = 'openHikingMap';
|
newOptions.basemap = 'openHikingMap';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.has('imperial')) {
|
if (options.has('imperial')) {
|
||||||
newOptions.distanceUnits = 'imperial';
|
newOptions.distanceUnits = 'imperial';
|
||||||
}
|
}
|
||||||
if (options.has('running')) {
|
if (options.has('running')) {
|
||||||
newOptions.velocityUnits = 'pace';
|
newOptions.velocityUnits = 'pace';
|
||||||
}
|
}
|
||||||
if (options.has('distance')) {
|
if (options.has('distance')) {
|
||||||
newOptions.distanceMarkers = true;
|
newOptions.distanceMarkers = true;
|
||||||
}
|
}
|
||||||
if (options.has('direction')) {
|
if (options.has('direction')) {
|
||||||
newOptions.directionMarkers = true;
|
newOptions.directionMarkers = true;
|
||||||
}
|
}
|
||||||
if (options.has('slope')) {
|
if (options.has('slope')) {
|
||||||
newOptions.elevation = {
|
newOptions.elevation = {
|
||||||
fill: 'slope',
|
fill: 'slope'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return newOptions;
|
return newOptions;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,192 +5,199 @@ import { _ } from 'svelte-i18n';
|
||||||
const { distanceUnits, velocityUnits, temperatureUnits } = settings;
|
const { distanceUnits, velocityUnits, temperatureUnits } = settings;
|
||||||
|
|
||||||
export function kilometersToMiles(value: number) {
|
export function kilometersToMiles(value: number) {
|
||||||
return value * 0.621371;
|
return value * 0.621371;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function milesToKilometers(value: number) {
|
export function milesToKilometers(value: number) {
|
||||||
return value * 1.60934;
|
return value * 1.60934;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function metersToFeet(value: number) {
|
export function metersToFeet(value: number) {
|
||||||
return value * 3.28084;
|
return value * 3.28084;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function kilometersToNauticalMiles(value: number) {
|
export function kilometersToNauticalMiles(value: number) {
|
||||||
return value * 0.539957;
|
return value * 0.539957;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nauticalMilesToKilometers(value: number) {
|
export function nauticalMilesToKilometers(value: number) {
|
||||||
return value * 1.852;
|
return value * 1.852;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function celsiusToFahrenheit(value: number) {
|
export function celsiusToFahrenheit(value: number) {
|
||||||
return value * 1.8 + 32;
|
return value * 1.8 + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function distancePerHourToSecondsPerDistance(value: number) {
|
export function distancePerHourToSecondsPerDistance(value: number) {
|
||||||
if (value === 0) {
|
if (value === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 3600 / value;
|
return 3600 / value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function secondsToHHMMSS(value: number) {
|
export function secondsToHHMMSS(value: number) {
|
||||||
var hours = Math.floor(value / 3600);
|
var hours = Math.floor(value / 3600);
|
||||||
var minutes = Math.floor(value / 60) % 60;
|
var minutes = Math.floor(value / 60) % 60;
|
||||||
var seconds = Math.min(59, Math.round(value % 60));
|
var seconds = Math.min(59, Math.round(value % 60));
|
||||||
|
|
||||||
return [hours, minutes, seconds]
|
return [hours, minutes, seconds]
|
||||||
.map((v) => (v < 10 ? '0' + v : v))
|
.map((v) => (v < 10 ? '0' + v : v))
|
||||||
.filter((v, i) => v !== '00' || i > 0)
|
.filter((v, i) => v !== '00' || i > 0)
|
||||||
.join(':');
|
.join(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a string representation of the value with units
|
// Get a string representation of the value with units
|
||||||
export function getDistanceWithUnits(value: number, convert: boolean = true) {
|
export function getDistanceWithUnits(value: number, convert: boolean = true) {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
return getConvertedDistance(value).toFixed(2) + ' ' + getDistanceUnits();
|
return getConvertedDistance(value).toFixed(2) + ' ' + getDistanceUnits();
|
||||||
} else {
|
} else {
|
||||||
return value.toFixed(2) + ' ' + getDistanceUnits();
|
return value.toFixed(2) + ' ' + getDistanceUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getVelocityWithUnits(value: number, convert: boolean = true) {
|
export function getVelocityWithUnits(value: number, convert: boolean = true) {
|
||||||
if (get(velocityUnits) === 'speed') {
|
if (get(velocityUnits) === 'speed') {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
return getConvertedVelocity(value).toFixed(2) + ' ' + getVelocityUnits();
|
return getConvertedVelocity(value).toFixed(2) + ' ' + getVelocityUnits();
|
||||||
} else {
|
} else {
|
||||||
return value.toFixed(2) + ' ' + getVelocityUnits();
|
return value.toFixed(2) + ' ' + getVelocityUnits();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
return secondsToHHMMSS(getConvertedVelocity(value)) + ' ' + getVelocityUnits();
|
return secondsToHHMMSS(getConvertedVelocity(value)) + ' ' + getVelocityUnits();
|
||||||
} else {
|
} else {
|
||||||
return secondsToHHMMSS(value) + ' ' + getVelocityUnits();
|
return secondsToHHMMSS(value) + ' ' + getVelocityUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getElevationWithUnits(value: number, convert: boolean = true) {
|
export function getElevationWithUnits(value: number, convert: boolean = true) {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
return getConvertedElevation(value).toFixed(0) + ' ' + getElevationUnits();
|
return getConvertedElevation(value).toFixed(0) + ' ' + getElevationUnits();
|
||||||
} else {
|
} else {
|
||||||
return value.toFixed(0) + ' ' + getElevationUnits();
|
return value.toFixed(0) + ' ' + getElevationUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHeartRateWithUnits(value: number) {
|
export function getHeartRateWithUnits(value: number) {
|
||||||
return value.toFixed(0) + ' ' + getHeartRateUnits();
|
return value.toFixed(0) + ' ' + getHeartRateUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCadenceWithUnits(value: number) {
|
export function getCadenceWithUnits(value: number) {
|
||||||
return value.toFixed(0) + ' ' + getCadenceUnits();
|
return value.toFixed(0) + ' ' + getCadenceUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPowerWithUnits(value: number) {
|
export function getPowerWithUnits(value: number) {
|
||||||
return value.toFixed(0) + ' ' + getPowerUnits();
|
return value.toFixed(0) + ' ' + getPowerUnits();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTemperatureWithUnits(value: number, convert: boolean = true) {
|
export function getTemperatureWithUnits(value: number, convert: boolean = true) {
|
||||||
if (convert) {
|
if (convert) {
|
||||||
return getConvertedTemperature(value).toFixed(0) + ' ' + getTemperatureUnits();
|
return getConvertedTemperature(value).toFixed(0) + ' ' + getTemperatureUnits();
|
||||||
} else {
|
} else {
|
||||||
return value.toFixed(0) + ' ' + getTemperatureUnits();
|
return value.toFixed(0) + ' ' + getTemperatureUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the units
|
// Get the units
|
||||||
export function getDistanceUnits(targetDistanceUnits = get(distanceUnits)) {
|
export function getDistanceUnits(targetDistanceUnits = get(distanceUnits)) {
|
||||||
switch (targetDistanceUnits) {
|
switch (targetDistanceUnits) {
|
||||||
case 'metric':
|
case 'metric':
|
||||||
return get(_)('units.kilometers');
|
return get(_)('units.kilometers');
|
||||||
case 'imperial':
|
case 'imperial':
|
||||||
return get(_)('units.miles');
|
return get(_)('units.miles');
|
||||||
case 'nautical':
|
case 'nautical':
|
||||||
return get(_)('units.nautical_miles');
|
return get(_)('units.nautical_miles');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getVelocityUnits(targetVelocityUnits = get(velocityUnits), targetDistanceUnits = get(distanceUnits)) {
|
export function getVelocityUnits(
|
||||||
if (targetVelocityUnits === 'speed') {
|
targetVelocityUnits = get(velocityUnits),
|
||||||
switch (targetDistanceUnits) {
|
targetDistanceUnits = get(distanceUnits)
|
||||||
case 'metric':
|
) {
|
||||||
return get(_)('units.kilometers_per_hour');
|
if (targetVelocityUnits === 'speed') {
|
||||||
case 'imperial':
|
switch (targetDistanceUnits) {
|
||||||
return get(_)('units.miles_per_hour');
|
case 'metric':
|
||||||
case 'nautical':
|
return get(_)('units.kilometers_per_hour');
|
||||||
return get(_)('units.knots');
|
case 'imperial':
|
||||||
}
|
return get(_)('units.miles_per_hour');
|
||||||
} else {
|
case 'nautical':
|
||||||
switch (targetDistanceUnits) {
|
return get(_)('units.knots');
|
||||||
case 'metric':
|
}
|
||||||
return get(_)('units.minutes_per_kilometer');
|
} else {
|
||||||
case 'imperial':
|
switch (targetDistanceUnits) {
|
||||||
return get(_)('units.minutes_per_mile');
|
case 'metric':
|
||||||
case 'nautical':
|
return get(_)('units.minutes_per_kilometer');
|
||||||
return get(_)('units.minutes_per_nautical_mile');
|
case 'imperial':
|
||||||
}
|
return get(_)('units.minutes_per_mile');
|
||||||
}
|
case 'nautical':
|
||||||
|
return get(_)('units.minutes_per_nautical_mile');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getElevationUnits(targetDistanceUnits = get(distanceUnits)) {
|
export function getElevationUnits(targetDistanceUnits = get(distanceUnits)) {
|
||||||
return targetDistanceUnits === 'metric' ? get(_)('units.meters') : get(_)('units.feet');
|
return targetDistanceUnits === 'metric' ? get(_)('units.meters') : get(_)('units.feet');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHeartRateUnits() {
|
export function getHeartRateUnits() {
|
||||||
return get(_)('units.heartrate');
|
return get(_)('units.heartrate');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCadenceUnits() {
|
export function getCadenceUnits() {
|
||||||
return get(_)('units.cadence');
|
return get(_)('units.cadence');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPowerUnits() {
|
export function getPowerUnits() {
|
||||||
return get(_)('units.power');
|
return get(_)('units.power');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTemperatureUnits() {
|
export function getTemperatureUnits() {
|
||||||
return get(temperatureUnits) === 'celsius' ? get(_)('units.celsius') : get(_)('units.fahrenheit');
|
return get(temperatureUnits) === 'celsius' ? get(_)('units.celsius') : get(_)('units.fahrenheit');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert only the value
|
// Convert only the value
|
||||||
export function getConvertedDistance(value: number, targetDistanceUnits = get(distanceUnits)) {
|
export function getConvertedDistance(value: number, targetDistanceUnits = get(distanceUnits)) {
|
||||||
switch (targetDistanceUnits) {
|
switch (targetDistanceUnits) {
|
||||||
case 'metric':
|
case 'metric':
|
||||||
return value;
|
return value;
|
||||||
case 'imperial':
|
case 'imperial':
|
||||||
return kilometersToMiles(value);
|
return kilometersToMiles(value);
|
||||||
case 'nautical':
|
case 'nautical':
|
||||||
return kilometersToNauticalMiles(value);
|
return kilometersToNauticalMiles(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConvertedElevation(value: number, targetDistanceUnits = get(distanceUnits)) {
|
export function getConvertedElevation(value: number, targetDistanceUnits = get(distanceUnits)) {
|
||||||
return targetDistanceUnits === 'metric' ? value : metersToFeet(value);
|
return targetDistanceUnits === 'metric' ? value : metersToFeet(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConvertedVelocity(value: number, targetVelocityUnits = get(velocityUnits), targetDistanceUnits = get(distanceUnits)) {
|
export function getConvertedVelocity(
|
||||||
if (targetVelocityUnits === 'speed') {
|
value: number,
|
||||||
switch (targetDistanceUnits) {
|
targetVelocityUnits = get(velocityUnits),
|
||||||
case 'metric':
|
targetDistanceUnits = get(distanceUnits)
|
||||||
return value;
|
) {
|
||||||
case 'imperial':
|
if (targetVelocityUnits === 'speed') {
|
||||||
return kilometersToMiles(value);
|
switch (targetDistanceUnits) {
|
||||||
case 'nautical':
|
case 'metric':
|
||||||
return kilometersToNauticalMiles(value);
|
return value;
|
||||||
}
|
case 'imperial':
|
||||||
} else {
|
return kilometersToMiles(value);
|
||||||
switch (targetDistanceUnits) {
|
case 'nautical':
|
||||||
case 'metric':
|
return kilometersToNauticalMiles(value);
|
||||||
return distancePerHourToSecondsPerDistance(value);
|
}
|
||||||
case 'imperial':
|
} else {
|
||||||
return distancePerHourToSecondsPerDistance(kilometersToMiles(value));
|
switch (targetDistanceUnits) {
|
||||||
case 'nautical':
|
case 'metric':
|
||||||
return distancePerHourToSecondsPerDistance(kilometersToNauticalMiles(value));
|
return distancePerHourToSecondsPerDistance(value);
|
||||||
}
|
case 'imperial':
|
||||||
}
|
return distancePerHourToSecondsPerDistance(kilometersToMiles(value));
|
||||||
|
case 'nautical':
|
||||||
|
return distancePerHourToSecondsPerDistance(kilometersToNauticalMiles(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConvertedTemperature(value: number) {
|
export function getConvertedTemperature(value: number) {
|
||||||
return get(temperatureUnits) === 'celsius' ? value : celsiusToFahrenheit(value);
|
return get(temperatureUnits) === 'celsius' ? value : celsiusToFahrenheit(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue