UNPKG

@airia-in/run-app-data-format

Version:

Shared data formatting library for Airia fitness platform

101 lines (100 loc) 3.91 kB
/** * Data Format Library * Centralized formatting functions for time, distance, pace, HR, and other fitness metrics */ /** * Converts speed from meters/second to minutes/km. * @param ms Speed in meters/second * @returns Pace in minutes/km (as a string "mm:ss") */ export declare function msToMinPerKm(ms: number | string): string; /** * Converts distance from meters to kilometers or meters based on value. * @param meters Distance in meters * @returns Formatted distance string with unit */ export declare function mToKm(meters: number | string): string; /** * Formats duration from seconds to various time formats. * @param seconds Duration in seconds * @param format Format type: 'hh:mm:ss', 'mm:ss', 'humanReadable' * @returns Formatted duration string */ export declare function formatDuration(seconds: number | string, format?: 'hh:mm:ss' | 'mm:ss' | 'humanReadable'): string; /** * Formats heart rate value. * @param hr Heart rate value * @param includeUnit Whether to include 'bpm' unit * @returns Formatted heart rate string */ export declare function formatHeartRate(hr: number | string, includeUnit?: boolean): string; /** * Calculates and formats heart rate zones based on max HR. * @param currentHR Current heart rate * @param maxHR Maximum heart rate (if not provided, uses 220 - age) * @param age User's age (used if maxHR not provided) * @returns Object with zone information */ export declare function getHeartRateZone(currentHR: number, maxHR?: number, age?: number): { zone: number; zoneName: string; percentage: number; description: string; }; /** * Formats speed value to km/h or m/s. * @param metersPerSecond Speed in m/s * @param unit Output unit: 'kmh' or 'ms' * @returns Formatted speed string with unit */ export declare function formatSpeed(metersPerSecond: number | string, unit?: 'kmh' | 'ms'): string; /** * Formats elevation/altitude values. * @param meters Elevation in meters * @param unit Output unit: 'm' or 'ft' * @returns Formatted elevation string with unit */ export declare function formatElevation(meters: number | string, unit?: 'm' | 'ft'): string; /** * Formats power output (for cycling). * @param watts Power in watts * @param includeUnit Whether to include 'W' unit * @returns Formatted power string */ export declare function formatPower(watts: number | string, includeUnit?: boolean): string; /** * Formats cadence (steps/min for running, rpm for cycling). * @param cadence Cadence value * @param type Activity type: 'running' or 'cycling' * @returns Formatted cadence string with appropriate unit */ export declare function formatCadence(cadence: number | string, type?: 'running' | 'cycling'): string; /** * Formats temperature values. * @param celsius Temperature in Celsius * @param unit Output unit: 'C' or 'F' * @returns Formatted temperature string with unit */ export declare function formatTemperature(celsius: number | string, unit?: 'C' | 'F'): string; /** * Formats date to various formats. * @param date Date string or Date object * @param format Format type: 'short', 'long', 'iso', 'relative' * @returns Formatted date string */ export declare function formatDate(date: string | Date, format?: 'short' | 'long' | 'iso' | 'relative'): string; /** * Formats calories burned. * @param calories Calories value * @param includeUnit Whether to include 'cal' unit * @returns Formatted calories string */ export declare function formatCalories(calories: number | string, includeUnit?: boolean): string; /** * Converts and formats pace between different units. * @param value Pace value * @param fromUnit Input unit: 'min/km', 'min/mi', 's/m' * @param toUnit Output unit: 'min/km', 'min/mi', 's/m' * @returns Formatted pace string */ export declare function convertPace(value: number, fromUnit: 'min/km' | 'min/mi' | 's/m', toUnit: 'min/km' | 'min/mi' | 's/m'): string;