hevy-shared 1.0.762 → 1.0.763

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseExerciseTemplate, FormatAtText, Result, StrengthLevel, UserExerciseSet } from '.';
1
+ import { BaseExerciseTemplate, FormatAtText, Lookup, Result, StrengthLevel, UserExerciseSet } from '.';
2
2
  /**
3
3
  * Doesn't matter what you throw in the function it'll
4
4
  * always return a number. Non number values will return
@@ -226,4 +226,19 @@ export declare const isVersionAGreaterOrEqualToVersionB: (versionA: string, vers
226
226
  export declare const splitAtUsernamesAndLinks: (text: string) => FormatAtText[];
227
227
  export declare const validateYoutubeUrl: (url: string) => boolean;
228
228
  export declare const getYoutubeVideoId: (url: string) => string | undefined;
229
+ declare const _comparisonOperators: readonly ["<", ">", "!=", "=", "<=", ">="];
230
+ declare const _setValueContexts: readonly ["pr"];
231
+ declare const _setValueUnitTypes: readonly ["weight"];
232
+ type ComparisonOperator = Lookup<typeof _comparisonOperators>;
233
+ type SetValueContext = Lookup<typeof _setValueContexts>;
234
+ type SetValueUnitType = Lookup<typeof _setValueUnitTypes>;
235
+ /**
236
+ * Compares two floating point numbers to the precision given by the context in
237
+ * which they occur. Used to standardise calculations throughout the app, and
238
+ * produce consistent behaviour between the frontend and the backend.
239
+ */
240
+ export declare const compareSetValues: (lhs: number, operator: ComparisonOperator, rhs: number, options: {
241
+ context: SetValueContext;
242
+ unitType: SetValueUnitType;
243
+ }) => boolean;
229
244
  export {};
package/built/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.workoutSetCount = exports.userExerciseSetWeight = exports.workoutDistanceMeters = exports.workoutReps = exports.workoutDurationSeconds = exports.removeAccents = exports.getClosestDataPointAroundTargetDate = exports.getClosestDataPointBeforeTargetDate = 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;
3
+ exports.compareSetValues = 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.workoutSetCount = exports.userExerciseSetWeight = exports.workoutDistanceMeters = exports.workoutReps = exports.workoutDurationSeconds = exports.removeAccents = exports.getClosestDataPointAroundTargetDate = exports.getClosestDataPointBeforeTargetDate = 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;
4
+ const _1 = require(".");
4
5
  /**
5
6
  * Doesn't matter what you throw in the function it'll
6
7
  * always return a number. Non number values will return
@@ -673,3 +674,47 @@ const getYoutubeVideoId = (url) => {
673
674
  return match && match[1] && match[1].length === 11 ? match[1] : undefined;
674
675
  };
675
676
  exports.getYoutubeVideoId = getYoutubeVideoId;
677
+ const _comparisonOperators = [
678
+ '<', // significantly less than
679
+ '>', // significantly greater than
680
+ '!=', // significantly different from
681
+ '=', // approximately equal to
682
+ '<=', // not significantly greater than
683
+ '>=', // not significantly less than
684
+ ];
685
+ const _setValueContexts = ['pr'];
686
+ const _setValueUnitTypes = ['weight'];
687
+ /**
688
+ * For each combination of parameters, ignore any difference within the given
689
+ * range when comparing two values.
690
+ */
691
+ const _setValueRoundingPrecisionMap = {
692
+ weight: { pr: 0.0075 },
693
+ };
694
+ /**
695
+ * Compares two floating point numbers to the precision given by the context in
696
+ * which they occur. Used to standardise calculations throughout the app, and
697
+ * produce consistent behaviour between the frontend and the backend.
698
+ */
699
+ const compareSetValues = (lhs, operator, rhs, options) => {
700
+ const { context, unitType } = options;
701
+ const difference = Math.abs(lhs - rhs);
702
+ const isApproximatelyEqual = difference <= _setValueRoundingPrecisionMap[unitType][context];
703
+ switch (operator) {
704
+ case '<':
705
+ return lhs < rhs && !isApproximatelyEqual;
706
+ case '>':
707
+ return lhs > rhs && !isApproximatelyEqual;
708
+ case '!=':
709
+ return !isApproximatelyEqual;
710
+ case '=':
711
+ return isApproximatelyEqual;
712
+ case '<=':
713
+ return lhs < rhs || isApproximatelyEqual;
714
+ case '>=':
715
+ return lhs < rhs || isApproximatelyEqual;
716
+ default:
717
+ throw (0, _1.exhaustiveTypeException)(operator);
718
+ }
719
+ };
720
+ exports.compareSetValues = compareSetValues;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.762",
3
+ "version": "1.0.763",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",