hevy-shared 1.0.877 → 1.0.878

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.
@@ -712,10 +712,13 @@ describe('utils', () => {
712
712
  weight: 'kg',
713
713
  distance: 'kilometers',
714
714
  },
715
- labels: {
716
- weight: 'kg',
717
- distance: ' km',
718
- shortDistance: ' m',
715
+ lokalizedLabels: {
716
+ kg: 'kg',
717
+ lbs: 'lbs',
718
+ km: 'km',
719
+ mi: 'mi',
720
+ m: 'm',
721
+ yd: 'yd',
719
722
  steps: 'Steps',
720
723
  floors: 'Floors',
721
724
  },
@@ -745,6 +748,58 @@ describe('utils', () => {
745
748
  it('formats weight with duration', () => {
746
749
  expect((0, utils_1.formatSetValue)(Object.assign(Object.assign({}, baseParams), { exerciseType: 'weight_duration' }))).toBe('100 kg - 1min 30s');
747
750
  });
751
+ it('formats weights in kg', () => {
752
+ expect((0, utils_1.formatSetValue)({
753
+ set: {
754
+ weight_kg: 100,
755
+ reps: 12,
756
+ duration_seconds: null,
757
+ distance_meters: null,
758
+ custom_metric: null,
759
+ },
760
+ units: {
761
+ weight: 'kg',
762
+ distance: 'kilometers',
763
+ },
764
+ lokalizedLabels: {
765
+ kg: 'kg',
766
+ lbs: 'lbs',
767
+ km: 'km',
768
+ mi: 'mi',
769
+ m: 'm',
770
+ yd: 'yd',
771
+ steps: 'Steps',
772
+ floors: 'Floors',
773
+ },
774
+ exerciseType: 'weight_reps',
775
+ })).toBe('100 kg x 12');
776
+ });
777
+ it('formats weights logged in lbs', () => {
778
+ expect((0, utils_1.formatSetValue)({
779
+ set: {
780
+ weight_kg: 50,
781
+ reps: 12,
782
+ duration_seconds: null,
783
+ distance_meters: null,
784
+ custom_metric: null,
785
+ },
786
+ units: {
787
+ weight: 'lbs',
788
+ distance: 'kilometers',
789
+ },
790
+ lokalizedLabels: {
791
+ kg: 'kg',
792
+ lbs: 'lbs',
793
+ km: 'km',
794
+ mi: 'mi',
795
+ m: 'm',
796
+ yd: 'yd',
797
+ steps: 'Steps',
798
+ floors: 'Floors',
799
+ },
800
+ exerciseType: 'weight_reps',
801
+ })).toBe('110.23 lbs x 12');
802
+ });
748
803
  it('formats floors with duration', () => {
749
804
  expect((0, utils_1.formatSetValue)(Object.assign(Object.assign({}, baseParams), { exerciseType: 'floors_duration' }))).toBe('15 Floors - 1min 30s');
750
805
  });
package/built/utils.d.ts CHANGED
@@ -264,14 +264,17 @@ interface getSetValueParams {
264
264
  weight: WeightUnit;
265
265
  distance: DistanceUnit;
266
266
  };
267
- labels: {
268
- weight: string;
269
- distance: string;
270
- shortDistance: string;
267
+ lokalizedLabels: {
268
+ kg: string;
269
+ lbs: string;
270
+ km: string;
271
+ mi: string;
272
+ m: string;
273
+ yd: string;
271
274
  steps: string;
272
275
  floors: string;
273
276
  };
274
277
  }
275
- export declare const formatSetValue: ({ exerciseType, set, units, labels, }: getSetValueParams) => string;
278
+ export declare const formatSetValue: ({ exerciseType, set, units, lokalizedLabels, }: getSetValueParams) => string;
276
279
  export declare const rawInstructionsToIndexedSteps: (rawInstructions: string) => ExerciseInstructionsStep[];
277
280
  export {};
package/built/utils.js CHANGED
@@ -791,43 +791,56 @@ const exerciseWeight = (value, weightUnit) => {
791
791
  return (0, exports.roundToTwoDecimal)(value);
792
792
  };
793
793
  exports.exerciseWeight = exerciseWeight;
794
- const formatSetValue = ({ exerciseType, set, units, labels, }) => {
794
+ const formatSetValue = ({ exerciseType, set, units, lokalizedLabels, }) => {
795
795
  var _a, _b, _c;
796
+ const unitToLabelMap = {
797
+ kg: lokalizedLabels.kg,
798
+ lbs: lokalizedLabels.lbs,
799
+ km: lokalizedLabels.km,
800
+ mi: lokalizedLabels.mi,
801
+ m: lokalizedLabels.m,
802
+ yd: lokalizedLabels.yd,
803
+ steps: lokalizedLabels.steps,
804
+ floors: lokalizedLabels.floors,
805
+ };
796
806
  switch (exerciseType) {
797
807
  case 'weight_reps':
798
808
  case 'bodyweight_reps': {
799
- const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${labels.weight}`;
809
+ const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${unitToLabelMap[units.weight]}`;
800
810
  const reps = `${(_a = set.reps) !== null && _a !== void 0 ? _a : 0}`;
801
811
  return `${weight} x ${reps}`;
802
812
  }
803
813
  case 'bodyweight_assisted_reps': {
804
- const weight = `-${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${labels.weight}`;
814
+ const weight = `-${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${unitToLabelMap[units.weight]}`;
805
815
  const reps = `${(_b = set.reps) !== null && _b !== void 0 ? _b : 0}`;
806
816
  return `${weight} x ${reps}`;
807
817
  }
808
818
  case 'reps_only':
809
819
  return `${(_c = set.reps) !== null && _c !== void 0 ? _c : 0}`;
810
820
  case 'distance_duration': {
811
- const distanceValue = `${(0, exports.distance)(set.distance_meters || 0, units.distance)}${labels.distance}`;
821
+ const distanceUnitShort = units.distance === 'kilometers' ? 'km' : 'mi';
822
+ const distanceValue = `${(0, exports.distance)(set.distance_meters || 0, units.distance)} ${unitToLabelMap[distanceUnitShort]}`;
812
823
  const duration = `${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
813
824
  return `${distanceValue} - ${duration}`;
814
825
  }
815
826
  case 'duration':
816
827
  return (0, exports.secondsToWordFormat)(Number(set.duration_seconds));
817
828
  case 'short_distance_weight': {
818
- const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${labels.weight}`;
829
+ const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${unitToLabelMap[units.weight]}`;
819
830
  const shortDistance = (0, exports.roundToTwoDecimal)(set.distance_meters || 0);
820
- return `${weight} - ${shortDistance}${labels.shortDistance}`;
831
+ const shortDistanceUnitShort = units.distance === 'kilometers' ? 'm' : 'yd';
832
+ const shortDistanceUnitShortLabel = unitToLabelMap[shortDistanceUnitShort];
833
+ return `${weight} - ${shortDistance} ${shortDistanceUnitShortLabel}`;
821
834
  }
822
835
  case 'weight_duration': {
823
- const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${labels.weight}`;
836
+ const weight = `${(0, exports.exerciseWeight)(set.weight_kg || 0, units.weight)} ${unitToLabelMap[units.weight]}`;
824
837
  const duration = `${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
825
838
  return `${weight} - ${duration}`;
826
839
  }
827
840
  case 'floors_duration':
828
- return `${set.custom_metric ? (0, exports.roundToWholeNumber)(set.custom_metric) : 0} ${labels.floors} - ${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
841
+ return `${set.custom_metric ? (0, exports.roundToWholeNumber)(set.custom_metric) : 0} ${unitToLabelMap.floors} - ${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
829
842
  case 'steps_duration':
830
- return `${set.custom_metric ? (0, exports.roundToWholeNumber)(set.custom_metric) : 0} ${labels.steps} - ${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
843
+ return `${set.custom_metric ? (0, exports.roundToWholeNumber)(set.custom_metric) : 0} ${unitToLabelMap.steps} - ${(0, exports.secondsToWordFormat)(Number(set.duration_seconds))}`;
831
844
  default:
832
845
  (0, _1.exhaustiveTypeCheck)(exerciseType);
833
846
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.877",
3
+ "version": "1.0.878",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",