hevy-shared 1.0.877 → 1.0.879
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/index.d.ts +2 -3
- package/built/index.js +3 -18
- package/built/tests/utils.test.js +59 -4
- package/built/translationUtils.d.ts +5 -0
- package/built/translationUtils.js +30 -0
- package/built/utils.d.ts +8 -5
- package/built/utils.js +22 -9
- package/package.json +1 -1
package/built/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WorkoutDurationMinutes } from './hevyTrainer';
|
|
2
|
+
import { Language } from './translationUtils';
|
|
2
3
|
import { Lookup } from './typeUtils';
|
|
3
4
|
export * from './constants';
|
|
4
5
|
export * from './utils';
|
|
@@ -20,9 +21,7 @@ export * from './async';
|
|
|
20
21
|
export * from './adminPermissions';
|
|
21
22
|
export * from './adjustEventTokens';
|
|
22
23
|
export * from './hevyTrainer';
|
|
23
|
-
export
|
|
24
|
-
export type Language = Lookup<typeof supportedLanguages>;
|
|
25
|
-
export declare const isLanguage: (x: string) => x is Language;
|
|
24
|
+
export * from './translationUtils';
|
|
26
25
|
export type WeightUnit = 'kg' | 'lbs';
|
|
27
26
|
export declare const isWeightUnit: (x: string) => x is WeightUnit;
|
|
28
27
|
export type DistanceUnit = 'kilometers' | 'miles';
|
package/built/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.isHeartRateSamples = exports.isPublicWorkout = exports.isSetType = exports.isRPE = exports.validRpeValues = exports.isSetPersonalRecordType = exports.supportedInstructionsLanguages = exports.weeklyTrainingFrequencies = exports.hevyTrainerProgramEquipments = exports.exerciseCategories = exports.trainingLevels = exports.trainingGoals = exports.isCustomExerciseType = exports.customExericseTypes = exports.isExerciseType = exports.exerciseTypes = exports.isExerciseRepType = exports.exerciseRepTypes = exports.isEquipmentFilter = exports.equipmentFilters = exports.isEquipment = exports.equipments = exports.simplifiedMuscleGroupToMuscleGroups = exports.isMuscleGroupFilter = exports.muscleGroupFilters = exports.isMuscleGroup = exports.muscleGroups = exports.isSimplifiedMuscleGroup = exports.simplifiedMuscleGroups = exports.miscellaneousMuscles = exports.chestMuscles = exports.backMuscles = exports.legMuscles = exports.armMuscles = exports.shoulderMuscles = exports.coreMuscles = exports.DefaultClientConfiguration = exports.parseClientAuthTokenResponse = exports.isCoachRole = exports.isErrorResponse = exports.isLivePRVolumeOption = exports.isTimerVolumeOption = exports.isWeekday = exports.orderedWeekdays = exports.isBodyMeasurementUnit = exports.isDistanceUnitShort = exports.isDistanceUnit = exports.isWeightUnit =
|
|
18
|
-
exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList =
|
|
17
|
+
exports.isHevyTrainerRoutine = exports.isWorkoutBiometrics = exports.isHeartRateSamples = exports.isPublicWorkout = exports.isSetType = exports.isRPE = exports.validRpeValues = exports.isSetPersonalRecordType = exports.supportedInstructionsLanguages = exports.weeklyTrainingFrequencies = exports.hevyTrainerProgramEquipments = exports.exerciseCategories = exports.trainingLevels = exports.trainingGoals = exports.isCustomExerciseType = exports.customExericseTypes = exports.isExerciseType = exports.exerciseTypes = exports.isExerciseRepType = exports.exerciseRepTypes = exports.isEquipmentFilter = exports.equipmentFilters = exports.isEquipment = exports.equipments = exports.simplifiedMuscleGroupToMuscleGroups = exports.isMuscleGroupFilter = exports.muscleGroupFilters = exports.isMuscleGroup = exports.muscleGroups = exports.isSimplifiedMuscleGroup = exports.simplifiedMuscleGroups = exports.miscellaneousMuscles = exports.chestMuscles = exports.backMuscles = exports.legMuscles = exports.armMuscles = exports.shoulderMuscles = exports.coreMuscles = exports.DefaultClientConfiguration = exports.parseClientAuthTokenResponse = exports.isCoachRole = exports.isErrorResponse = exports.isLivePRVolumeOption = exports.isTimerVolumeOption = exports.isWeekday = exports.orderedWeekdays = exports.isBodyMeasurementUnit = exports.isDistanceUnitShort = exports.isDistanceUnit = exports.isWeightUnit = void 0;
|
|
18
|
+
exports.isSuggestedUserSource = exports.isValidUserWorkoutMetricsType = exports.isBodyMeasurementKey = exports.measurementsList = void 0;
|
|
19
19
|
const typeUtils_1 = require("./typeUtils");
|
|
20
20
|
__exportStar(require("./constants"), exports);
|
|
21
21
|
__exportStar(require("./utils"), exports);
|
|
@@ -37,22 +37,7 @@ __exportStar(require("./async"), exports);
|
|
|
37
37
|
__exportStar(require("./adminPermissions"), exports);
|
|
38
38
|
__exportStar(require("./adjustEventTokens"), exports);
|
|
39
39
|
__exportStar(require("./hevyTrainer"), exports);
|
|
40
|
-
exports
|
|
41
|
-
'en',
|
|
42
|
-
'es',
|
|
43
|
-
'de',
|
|
44
|
-
'fr',
|
|
45
|
-
'it',
|
|
46
|
-
'pt',
|
|
47
|
-
'tr',
|
|
48
|
-
'zh_CN',
|
|
49
|
-
'zh_TW',
|
|
50
|
-
'ru',
|
|
51
|
-
'ja',
|
|
52
|
-
'ko',
|
|
53
|
-
];
|
|
54
|
-
const isLanguage = (x) => (0, typeUtils_1.isInArray)(x, exports.supportedLanguages);
|
|
55
|
-
exports.isLanguage = isLanguage;
|
|
40
|
+
__exportStar(require("./translationUtils"), exports);
|
|
56
41
|
const isWeightUnit = (x) => {
|
|
57
42
|
return x === 'kg' || x === 'lbs';
|
|
58
43
|
};
|
|
@@ -712,10 +712,13 @@ describe('utils', () => {
|
|
|
712
712
|
weight: 'kg',
|
|
713
713
|
distance: 'kilometers',
|
|
714
714
|
},
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
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
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Lookup } from './typeUtils';
|
|
2
|
+
export declare const supportedLanguages: readonly ["en", "es", "de", "fr", "it", "pt", "tr", "zh_CN", "zh_TW", "ru", "ja", "ko"];
|
|
3
|
+
export type Language = Lookup<typeof supportedLanguages>;
|
|
4
|
+
export declare const isLanguage: (x: string) => x is Language;
|
|
5
|
+
export declare const interpolate: (str: string, params: any[]) => string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolate = exports.isLanguage = exports.supportedLanguages = void 0;
|
|
4
|
+
const typeUtils_1 = require("./typeUtils");
|
|
5
|
+
exports.supportedLanguages = [
|
|
6
|
+
'en',
|
|
7
|
+
'es',
|
|
8
|
+
'de',
|
|
9
|
+
'fr',
|
|
10
|
+
'it',
|
|
11
|
+
'pt',
|
|
12
|
+
'tr',
|
|
13
|
+
'zh_CN',
|
|
14
|
+
'zh_TW',
|
|
15
|
+
'ru',
|
|
16
|
+
'ja',
|
|
17
|
+
'ko',
|
|
18
|
+
];
|
|
19
|
+
const isLanguage = (x) => (0, typeUtils_1.isInArray)(x, exports.supportedLanguages);
|
|
20
|
+
exports.isLanguage = isLanguage;
|
|
21
|
+
const interpolate = (str, params) => {
|
|
22
|
+
let i = 0;
|
|
23
|
+
return str
|
|
24
|
+
.replace(/%s/g, () => {
|
|
25
|
+
i += 1;
|
|
26
|
+
return params[i - 1];
|
|
27
|
+
})
|
|
28
|
+
.replace(/%{([\w-]*)}/g, (__, key) => params[0][key]);
|
|
29
|
+
};
|
|
30
|
+
exports.interpolate = interpolate;
|
package/built/utils.d.ts
CHANGED
|
@@ -264,14 +264,17 @@ interface getSetValueParams {
|
|
|
264
264
|
weight: WeightUnit;
|
|
265
265
|
distance: DistanceUnit;
|
|
266
266
|
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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,
|
|
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,
|
|
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)} ${
|
|
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)} ${
|
|
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
|
|
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)} ${
|
|
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
|
-
|
|
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)} ${
|
|
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} ${
|
|
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} ${
|
|
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 '';
|