hevy-shared 1.0.947 → 1.0.949
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/utils.d.ts +4 -0
- package/built/utils.js +26 -1
- package/package.json +1 -1
package/built/utils.d.ts
CHANGED
|
@@ -287,4 +287,8 @@ interface getSetValueParams {
|
|
|
287
287
|
}
|
|
288
288
|
export declare const formatSetValue: ({ exerciseType, set, units, lokalizedLabels, }: getSetValueParams) => string;
|
|
289
289
|
export declare const rawInstructionsToIndexedSteps: (rawInstructions: string) => ExerciseInstructionsStep[];
|
|
290
|
+
export declare const roundToKnownValue: (value: number, knownValues: number[]) => number | undefined;
|
|
291
|
+
export declare const indexByNearestValue: <T>(value: number, map: {
|
|
292
|
+
[key: number]: T;
|
|
293
|
+
}) => T | undefined;
|
|
290
294
|
export {};
|
package/built/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.calculateCurrentWeekStreak = exports.getYoutubeVideoId = exports.validateYoutubeUrl = exports.splitAtUsernamesAndLinks = exports.isVersionAGreaterOrEqualToVersionB = exports.generateUserGroupValue = exports.generateUserGroup = exports.isBaseExerciseTemplate = exports.getStrengthLevelFromPercentile = exports.numberToLocaleString = exports.numberWithCommas = exports.setVolume = exports.oneRepMax = exports.oneRepMaxPercentageMap = exports.getEstimatedExercisesDurationSeconds = exports.ESTIMATED_REST_TIMER_DURATION = exports.ESTIMATED_SET_DURATION = exports.UserFacingIndicatorToSetIndicator = exports.workoutSetCount = exports.userExerciseSetWeight = exports.workoutDistanceMeters = exports.workoutReps = exports.workoutDurationSeconds = exports.removeAccents = exports.getClosestDataPointAroundTargetDate = exports.getClosestDataPointBeforeTargetDate = exports.toFragmentedJSON = exports.findMapped = exports.stringToNumber = exports.forceStringToNumber = exports.formatDurationInput = exports.isValidFormattedTime = exports.isWholeNumber = exports.isNumber = exports.isValidUuid = exports.isValidPhoneNumber = exports.isValidWebUrl = exports.URL_REGEX = exports.isValidEmail = exports.secondsToWordFormatMinutes = exports.secondsToWordFormat = exports.secondsToClockFormat = exports.secondsToClockParts = exports.isValidUsername = exports.roundToWholeNumber = exports.roundToOneDecimal = exports.roundToTwoDecimal = exports.divide = exports.clampNumber = exports.num = void 0;
|
|
7
|
-
exports.rawInstructionsToIndexedSteps = exports.formatSetValue = exports.exerciseWeight = exports.distance = exports.weekdayNumberMap = exports.startOfWeek = void 0;
|
|
7
|
+
exports.indexByNearestValue = exports.roundToKnownValue = exports.rawInstructionsToIndexedSteps = exports.formatSetValue = exports.exerciseWeight = exports.distance = exports.weekdayNumberMap = exports.startOfWeek = void 0;
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
9
|
const _1 = require(".");
|
|
10
10
|
/**
|
|
@@ -903,3 +903,28 @@ const rawInstructionsToIndexedSteps = (rawInstructions) => {
|
|
|
903
903
|
return instructionsByStep;
|
|
904
904
|
};
|
|
905
905
|
exports.rawInstructionsToIndexedSteps = rawInstructionsToIndexedSteps;
|
|
906
|
+
const roundToKnownValue = (value, knownValues) => {
|
|
907
|
+
if (knownValues.length === 0)
|
|
908
|
+
return undefined;
|
|
909
|
+
const boundingValues = knownValues.reduce(([lower, upper], v) => {
|
|
910
|
+
return [
|
|
911
|
+
v > lower && v <= value ? v : lower,
|
|
912
|
+
v < upper && v >= value ? v : upper,
|
|
913
|
+
];
|
|
914
|
+
}, [-Infinity, Infinity]);
|
|
915
|
+
if (boundingValues[0] === -Infinity && boundingValues[1] === Infinity)
|
|
916
|
+
return undefined;
|
|
917
|
+
if (boundingValues[0] === -Infinity)
|
|
918
|
+
return boundingValues[1];
|
|
919
|
+
if (boundingValues[1] === Infinity)
|
|
920
|
+
return boundingValues[0];
|
|
921
|
+
return value - boundingValues[0] < boundingValues[1] - value
|
|
922
|
+
? boundingValues[0]
|
|
923
|
+
: boundingValues[1];
|
|
924
|
+
};
|
|
925
|
+
exports.roundToKnownValue = roundToKnownValue;
|
|
926
|
+
const indexByNearestValue = (value, map) => {
|
|
927
|
+
const index = (0, exports.roundToKnownValue)(value, Object.keys(map).map((e) => Number(e)));
|
|
928
|
+
return index ? map[index] : undefined;
|
|
929
|
+
};
|
|
930
|
+
exports.indexByNearestValue = indexByNearestValue;
|