import { Dayjs } from 'dayjs'; import { BaseExerciseTemplate, DistanceUnit, ExerciseInstructionsStep, ExerciseType, FormatAtText, Result, SetType, StrengthLevel, UserExerciseSet, UserFacingSetIndicator, Weekday, WeightUnit } from '.'; /** * Doesn't matter what you throw in the function it'll * always return a number. Non number values will return * 0. */ export declare const num: (value?: any) => number; export declare const clampNumber: (value: number, limits: { min?: number; max?: number; }) => number; export declare const divide: (numerator: number, denominator: number) => number; export declare const roundToTwoDecimal: (value: number) => number; export declare const roundToOneDecimal: (value: number) => number; export declare const roundToWholeNumber: (value: number) => number; export declare const isValidUsername: (username: string) => boolean; export declare const secondsToClockParts: (totalSeconds: number) => { hours: number; minutes: number; seconds: number; }; /** * 01:25 * 02:25:36 */ export declare const secondsToClockFormat: (seconds: number) => string; /** * 10s * 1min 10s * 2h 4min 45s */ export declare const secondsToWordFormat: (seconds: number) => string; /** * 14min * 2h 4min * 2h 0min */ export declare const secondsToWordFormatMinutes: (seconds: number) => string; export declare const isValidEmail: (email: string) => boolean; /** * Matches strings with a base format of `domain.tld`. * - `domain` may contain letters, digits and dashes, but it can't begin or * end with a dash * - `domain` may be prefixed once or multiple times with another `domain.` * - `tld` may be followed by `/path-to-page` * - the entire string may be prefixed by `https://` or `http://` */ export declare const URL_REGEX: RegExp; export declare const isValidWebUrl: (url: string) => boolean; /** * Check if a string is a valid phone number. A valid phone number is a string * that starts with a '+' followed by 9-15 digits with no spaces. This is the * format that we store in the database as well as what the Twilio API expects. * * @example * // valid: * +123456789 * +123456789012345 * * // not valid: * +1 23456789 * 123456789 * +1234567890123456 */ export declare const isValidPhoneNumber: (phoneNumber: string) => boolean; /** * Matches all UUID types, case-insensitive (matches both uppercase and * lowercase hexadecimal digits). */ export declare const isValidUuid: (uuid: string) => boolean; export declare const isNumber: (x: any) => x is number; export declare const isWholeNumber: (value: number) => boolean; /** * Return true is value is of format: NN:NN or NN:NN:NN */ export declare const isValidFormattedTime: (value: string) => boolean; export declare const formatDurationInput: (value: string) => string | undefined; /** * Will always return a number. Ivalid strings return 0 */ export declare const forceStringToNumber: (value?: string) => number; /** * Returns a number or undefined */ export declare const stringToNumber: (value?: string) => number | undefined; /** * Returns the first non-undefined value produced by transform function being * applied to elements of the array in iteration order, or `undefined` if no * such value was produced. Equivalent to `firstNotNullOfOrNull` in Kotlin. */ export declare const findMapped: (array: T[], transform: (element: T) => R) => R | undefined; /** * converts any array into an array of JSON chunks with a maximum given length * @param data an array of objects or primitives to be split into chunks * @param maxLength maximum length of any single returned JSON string * @returns an array of JSON strings, each one no longer than `maxLength` * @throws an error if fragmentation is impossible due to input data structure */ export declare const toFragmentedJSON: (data: T[], maxLength: number, options?: { lengthIn: "utf8bytes" | "characters"; }) => string[]; /** * Finds the closest data point that occurs before or at the target date using binary search. * Assumes input array is sorted by date in ascending order. * * @param data - Array of items containing dates in ascending order * @param dateExtractor - Function to extract Date from each item * @param targetDate - Target date to search for * @returns The closest item before or at the target date, or undefined if not found * * @example * const data = [ * { id: 1, date: dayjs('2023-01-01').toDate() }, * { id: 2, date: dayjs('2023-04-01').toDate() } * ]; * const result = getClosestDataPointBeforeTargetDate( * data, * item => item.date, * dayjs('2023-03-15').toDate(), * ); // Returns { id: 1, date: Date('2023-01-01') } */ export declare const getClosestDataPointBeforeTargetDate: (data: T[], dateExtractor: (item: T) => Date, targetDate: Date) => T | undefined; /** * Finds the closest data point to the target date. * * @param data - Array of items containing dates * @param dateExtractor - Function to extract Date from each item * @param targetDate - Target date to search for * @returns The closest item to the target date, or undefined if array is empty * * @example * const data = [ * { id: 1, date: dayjs('2023-01-01').toDate() }, * { id: 2, date: dayjs('2023-04-01').toDate() } * ]; * const result = getClosestDataPoint( * data, * item => item.date, * dayjs('2023-03-15').toDate(), * ); // Returns { id: 2, date: Date('2023-04-01') } */ export declare const getClosestDataPointAroundTargetDate: (data: T[], dateExtractor: (item: T) => Date, targetDate: Date) => T | undefined; export declare const removeAccents: (str: string) => string; /** * Calculate the total duration of a workout in seconds */ export interface DurationCalculatetableWorkout { end_time: number; start_time: number; } export declare const workoutDurationSeconds: (workout: DurationCalculatetableWorkout) => number; /** * Calculate the total reps in a workout */ export interface TotalRepsCalculatetableWorkout { exercises: Array<{ sets: Array<{ reps?: number | null; }>; }>; } export declare const workoutReps: (workout: TotalRepsCalculatetableWorkout) => number; /** * Calculate the total distance in a workout in meters */ export interface TotalDistanceCalculatetableWorkout { exercises: Array<{ sets: Array<{ distance_meters?: number | null; }>; }>; } export declare const workoutDistanceMeters: (workout: TotalDistanceCalculatetableWorkout) => number; /** * Calculate the total set count in a workout */ export interface TotalSetCountWorkout { exercises: Array<{ sets: Array; }>; } /** * Calculate the set weight for a given user exercise set * to be used in the exercise stats calculations on the web and coach app */ export declare const userExerciseSetWeight: (set: UserExerciseSet, exerciseStore: BaseExerciseTemplate[], hundredPercentBodyweightExercise: boolean) => number; export declare const workoutSetCount: (w: TotalSetCountWorkout) => number; export declare const UserFacingIndicatorToSetIndicator: (indicator: UserFacingSetIndicator) => SetType; interface GetEstimatedExercisesDuration { exercises: { rest_seconds: number | null; exercise_type: ExerciseType; sets: { duration_seconds?: number | null; indicator: SetType; }[]; }[]; } export declare const ESTIMATED_SET_DURATION = 45; export declare const ESTIMATED_REST_TIMER_DURATION = 90; export declare const getEstimatedExercisesDurationSeconds: ({ exercises, }: GetEstimatedExercisesDuration) => number; export declare const oneRepMaxPercentageMap: { [s: number]: number; }; export declare const oneRepMax: (weight: number, reps: number) => number; export declare const setVolume: (weight: number, reps: number) => number; /** @deprecated use `numberToLocaleString` */ export declare const numberWithCommas: (x: number) => string; /** * Formats a number into a string, accounting for the system locale. * * @example * numberToLocaleString(1234.567) === '1,234.567' // English (UK / US) * numberToLocaleString(1234.567) === '1.234,567' // German (Germany) * numberToLocaleString(1234.567) === '1 234,567' // French (France) */ export declare const numberToLocaleString: (value: number, options?: { maximumFractionDigits?: number; }) => string; export declare const getStrengthLevelFromPercentile: (percentile: number) => StrengthLevel; export declare const isBaseExerciseTemplate: (x: any) => x is BaseExerciseTemplate; type GenerateUserGroupError = 'invalid-number-of-groups' | 'invalid-uuid' | 'uuid-not-v4' | 'invalid-variant'; /** * Generates a subsample or test group given a user id. Technically, it just * calculates a trivial checksum of the last (random) part of a v4 UUID. * @param userId a v4 UUID; _must_ be v4 to ensure random distribution * @param numGroups number of possible groups, from 2 to 2^32 * @returns a number in the `[0, numGroups)` range, always equal for a given * `(userId, numGroups)` pair, or an error, inside a Result object */ export declare const generateUserGroup: (userId: string, numGroups: number) => Result; /** * Get the user group value for a given user id and number of groups. * @param userId a v4 UUID; _must_ be v4 to ensure random distribution * @param numGroups number of possible groups, from 2 to 2^32 * @returns User group value (A, B, C, etc.), or undefined if the user id is not a v4 UUID * or if an error occurs. */ export declare const generateUserGroupValue: (userId: string, numGroups: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) => "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | undefined; /** * @example * isVersionAGreaterOrEqualToVersionB('1.2.3', '1.2') // true * isVersionAGreaterOrEqualToVersionB('1.2.3', '1.2.2') // true * isVersionAGreaterOrEqualToVersionB('1.2.3', '1.2.3') // true * * isVersionAGreaterOrEqualToVersionB('1.2.3', '1.2.4') // false * isVersionAGreaterOrEqualToVersionB('1.2.3', '1.3') // false */ export declare const isVersionAGreaterOrEqualToVersionB: (versionA: string, versionB: string) => boolean; export declare const splitAtUsernamesAndLinks: (text: string) => FormatAtText[]; export declare const validateYoutubeUrl: (url: string) => boolean; export declare const getYoutubeVideoId: (url: string) => string | undefined; /**@param workouts must be sorted descending by start_time */ export declare const calculateCurrentWeekStreak: (workouts: { start_time: number; }[], firstWeekday: Weekday, untilUnix?: number) => number; export declare const startOfWeek: (d: Dayjs, firstDayOfWeek: Weekday) => Dayjs; export declare const weekdayNumberMap: { [key in Weekday]: number; }; export declare const distance: (value: number, distanceUnit: DistanceUnit) => number; export declare const exerciseWeight: (value: number, weightUnit: WeightUnit) => number; interface getSetValueParams { exerciseType: ExerciseType; set: { weight_kg: number | null; reps: number | null; duration_seconds: number | null; distance_meters: number | null; custom_metric: number | null; }; units: { weight: WeightUnit; distance: DistanceUnit; }; lokalizedLabels: { kg: string; lbs: string; km: string; mi: string; m: string; yd: string; steps: string; floors: string; }; } export declare const formatSetValue: ({ exerciseType, set, units, lokalizedLabels, }: getSetValueParams) => string; export declare const rawInstructionsToIndexedSteps: (rawInstructions: string) => ExerciseInstructionsStep[]; export declare const roundToKnownValue: (value: number, knownValues: number[]) => number | undefined; export declare const indexByNearestValue: (value: number, map: { [key: number]: T; }) => T | undefined; export {};