You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
export enum Size {
|
|
Mobile = "mobile",
|
|
Tablet = "tablet",
|
|
Desktop = "desktop",
|
|
Any = "any",
|
|
}
|
|
|
|
export interface ValuesWithTime extends Values {
|
|
time: number
|
|
}
|
|
|
|
export interface Values {
|
|
time?: number
|
|
calories?: number
|
|
distance?: number
|
|
level?: number
|
|
}
|
|
|
|
export type ColorName = "gray" | "green" | "blue" | "red" | "yellow" | "indigo";
|
|
|
|
export function diffLinearValues<T extends Values>(a: Values, b: Values): T {
|
|
const c: Values = {};
|
|
if (a.time) c.time = a.time - (b.time || 0);
|
|
if (a.calories) c.calories = a.calories - (b.calories || 0);
|
|
if (a.distance) c.distance = a.distance - (b.distance || 0);
|
|
if (a.level) c.level = a.level;
|
|
|
|
return c as T;
|
|
}
|
|
|
|
export function formatValue(raw: number, type: keyof Values): string {
|
|
if (type === "time") {
|
|
const minutes = Math.floor(raw / 60).toString(10).padStart(2, "0");
|
|
const seconds = (raw % 60).toString(10).padStart(2, "0");
|
|
|
|
return `${minutes}'${seconds}"`;
|
|
}
|
|
if (type === "calories") {
|
|
return `${raw} kcal`;
|
|
}
|
|
if (type === "distance") {
|
|
if (raw >= 100) {
|
|
return `${(raw / 1000).toFixed(1)} km`
|
|
} else {
|
|
return `${raw} m`;
|
|
}
|
|
}
|
|
if (type === "level") {
|
|
return `Lvl. ${raw}`;
|
|
}
|
|
|
|
return "";
|
|
}
|