hevy-shared 1.0.962 → 1.0.964
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/README.md +17 -2
- package/built/API/APIClient.d.ts +157 -0
- package/built/API/APIClient.js +381 -0
- package/built/API/index.d.ts +2 -0
- package/built/API/index.js +18 -0
- package/built/API/types.d.ts +38 -0
- package/built/API/types.js +18 -0
- package/built/adjustEventTokens.d.ts +16 -0
- package/built/adjustEventTokens.js +18 -0
- package/built/adminPermissions.d.ts +4 -0
- package/built/adminPermissions.js +22 -0
- package/built/async.d.ts +50 -0
- package/built/async.js +170 -0
- package/built/chat.d.ts +25 -23
- package/built/coachPlans.d.ts +2 -1
- package/built/coachPlans.js +2 -2
- package/built/cue.d.ts +12 -0
- package/built/cue.js +22 -0
- package/built/exerciseLocaleUtils.d.ts +17 -0
- package/built/exerciseLocaleUtils.js +62 -0
- package/built/filterExercises.d.ts +19 -3
- package/built/filterExercises.js +72 -60
- package/built/hevyTrainer.d.ts +250 -0
- package/built/hevyTrainer.js +676 -0
- package/built/index.d.ts +1217 -304
- package/built/index.js +268 -75
- package/built/muscleHeatmaps.d.ts +31 -0
- package/built/muscleHeatmaps.js +68 -0
- package/built/muscleSplits.d.ts +36 -0
- package/built/muscleSplits.js +100 -0
- package/built/normalizedWorkoutUtils.d.ts +88 -0
- package/built/normalizedWorkoutUtils.js +112 -0
- package/built/notifications.d.ts +215 -0
- package/built/notifications.js +9 -0
- package/built/routineUtils.d.ts +14 -0
- package/built/routineUtils.js +186 -0
- package/built/setIndicatorUtils.d.ts +4 -3
- package/built/setIndicatorUtils.js +15 -1
- package/built/tests/async.test.d.ts +1 -0
- package/built/tests/async.test.js +49 -0
- package/built/tests/hevyTrainer.test.d.ts +1 -0
- package/built/tests/hevyTrainer.test.js +1199 -0
- package/built/tests/muscleSplit.test.d.ts +1 -0
- package/built/tests/muscleSplit.test.js +153 -0
- package/built/tests/routineUtils.test.d.ts +1 -0
- package/built/tests/routineUtils.test.js +745 -0
- package/built/tests/testUtils.d.ts +85 -0
- package/built/tests/testUtils.js +319 -0
- package/built/tests/utils.test.js +748 -0
- package/built/tests/workoutVolume.test.js +165 -49
- package/built/translations/index.d.ts +2 -0
- package/built/translations/index.js +18 -0
- package/built/translations/translationUtils.d.ts +2 -0
- package/built/translations/translationUtils.js +61 -0
- package/built/translations/types.d.ts +8 -0
- package/built/translations/types.js +20 -0
- package/built/typeUtils.d.ts +70 -0
- package/built/typeUtils.js +55 -0
- package/built/units.d.ts +14 -7
- package/built/units.js +24 -14
- package/built/utils.d.ts +192 -5
- package/built/utils.js +598 -85
- package/built/websocket.d.ts +14 -2
- package/built/workoutVolume.d.ts +24 -5
- package/built/workoutVolume.js +25 -34
- package/package.json +30 -9
- package/.eslintignore +0 -2
- package/.eslintrc +0 -21
- package/.github/workflows/ci.yml +0 -15
- package/.github/workflows/npm-publish.yml +0 -59
- package/.github/workflows/pr-auto-assign.yml +0 -15
- package/.prettierrc.js +0 -5
- package/jest.config.js +0 -4
- package/src/chat.ts +0 -130
- package/src/coachPlans.ts +0 -57
- package/src/constants.ts +0 -14
- package/src/filterExercises.ts +0 -222
- package/src/index.ts +0 -1576
- package/src/setIndicatorUtils.ts +0 -137
- package/src/tests/utils.test.ts +0 -156
- package/src/tests/workoutVolume.test.ts +0 -93
- package/src/units.ts +0 -41
- package/src/utils.ts +0 -516
- package/src/websocket.ts +0 -36
- package/src/workoutVolume.ts +0 -175
- package/tsconfig.json +0 -70
|
@@ -2,68 +2,184 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const workoutVolume_1 = require("../workoutVolume");
|
|
4
4
|
describe('workoutVolume', () => {
|
|
5
|
-
describe('
|
|
6
|
-
it('
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
weightKg: 100,
|
|
11
|
-
reps: 10,
|
|
12
|
-
distanceMeters: 0,
|
|
5
|
+
describe('estimatedWorkoutVolumeKg', () => {
|
|
6
|
+
it('calculates the correct workout volume', () => {
|
|
7
|
+
const emptyWorkout = {
|
|
8
|
+
exercises: [],
|
|
9
|
+
include_warmup_sets: true,
|
|
13
10
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const weightRepsWorkout = {
|
|
12
|
+
exercises: [
|
|
13
|
+
{
|
|
14
|
+
exercise_type: 'weight_reps',
|
|
15
|
+
exercise_template_id: 'asd',
|
|
16
|
+
volume_doubling_enabled: false,
|
|
17
|
+
hundred_percent_bodyweight_exercise: false,
|
|
18
|
+
sets: [
|
|
19
|
+
{
|
|
20
|
+
indicator: 'normal',
|
|
21
|
+
weight_kg: 100,
|
|
22
|
+
reps: 10,
|
|
23
|
+
distance_meters: 0,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
include_warmup_sets: true,
|
|
20
29
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const pullUpWorkout = {
|
|
31
|
+
exercises: [
|
|
32
|
+
{
|
|
33
|
+
exercise_type: 'reps_only',
|
|
34
|
+
exercise_template_id: '1B2B1E7C', // Pull Up
|
|
35
|
+
volume_doubling_enabled: false,
|
|
36
|
+
hundred_percent_bodyweight_exercise: true,
|
|
37
|
+
sets: [
|
|
38
|
+
{
|
|
39
|
+
indicator: 'normal',
|
|
40
|
+
weight_kg: 0,
|
|
41
|
+
reps: 10,
|
|
42
|
+
distance_meters: 0,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
include_warmup_sets: true,
|
|
27
48
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
const assistedPullUpWorkout = {
|
|
50
|
+
exercises: [
|
|
51
|
+
{
|
|
52
|
+
exercise_type: 'bodyweight_assisted_reps',
|
|
53
|
+
exercise_template_id: '2C37EC5E', // Pull Up (Assisted)
|
|
54
|
+
volume_doubling_enabled: false,
|
|
55
|
+
hundred_percent_bodyweight_exercise: true,
|
|
56
|
+
sets: [
|
|
57
|
+
{
|
|
58
|
+
indicator: 'normal',
|
|
59
|
+
weight_kg: 10,
|
|
60
|
+
reps: 10,
|
|
61
|
+
distance_meters: 0,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
include_warmup_sets: true,
|
|
34
67
|
};
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
68
|
+
const weightedPullUpWorkout = {
|
|
69
|
+
exercises: [
|
|
70
|
+
{
|
|
71
|
+
exercise_type: 'bodyweight_reps',
|
|
72
|
+
exercise_template_id: '729237D1', // Pull Up (Weighted)
|
|
73
|
+
volume_doubling_enabled: false,
|
|
74
|
+
hundred_percent_bodyweight_exercise: true,
|
|
75
|
+
sets: [
|
|
76
|
+
{
|
|
77
|
+
indicator: 'normal',
|
|
78
|
+
weight_kg: 10,
|
|
79
|
+
reps: 10,
|
|
80
|
+
distance_meters: 0,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
include_warmup_sets: true,
|
|
41
86
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
87
|
+
const shortDistanceWeightWorkout = {
|
|
88
|
+
exercises: [
|
|
89
|
+
{
|
|
90
|
+
exercise_type: 'short_distance_weight',
|
|
91
|
+
exercise_template_id: 'asd',
|
|
92
|
+
volume_doubling_enabled: false,
|
|
93
|
+
hundred_percent_bodyweight_exercise: false,
|
|
94
|
+
sets: [
|
|
95
|
+
{
|
|
96
|
+
indicator: 'normal',
|
|
97
|
+
weight_kg: 100,
|
|
98
|
+
reps: 0,
|
|
99
|
+
distance_meters: 10,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
include_warmup_sets: true,
|
|
105
|
+
};
|
|
106
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
107
|
+
bodyweightKg: 100,
|
|
108
|
+
workout: emptyWorkout,
|
|
109
|
+
})).toBe(0);
|
|
110
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
111
|
+
bodyweightKg: 100,
|
|
112
|
+
workout: weightRepsWorkout,
|
|
113
|
+
})).toBe(1000);
|
|
114
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
46
115
|
bodyweightKg: 100,
|
|
47
|
-
|
|
116
|
+
workout: pullUpWorkout,
|
|
117
|
+
})).toBe(1000);
|
|
118
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
119
|
+
bodyweightKg: 100,
|
|
120
|
+
workout: assistedPullUpWorkout,
|
|
48
121
|
})).toBe(900);
|
|
49
|
-
expect((0, workoutVolume_1.
|
|
122
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
50
123
|
bodyweightKg: 100,
|
|
51
|
-
|
|
124
|
+
workout: weightedPullUpWorkout,
|
|
52
125
|
})).toBe(1100);
|
|
53
|
-
expect((0, workoutVolume_1.
|
|
126
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
54
127
|
bodyweightKg: 100,
|
|
55
|
-
|
|
128
|
+
workout: shortDistanceWeightWorkout,
|
|
56
129
|
})).toBe(1000);
|
|
57
|
-
expect((0, workoutVolume_1.
|
|
130
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
58
131
|
bodyweightKg: 100,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
132
|
+
workout: {
|
|
133
|
+
exercises: [
|
|
134
|
+
...weightRepsWorkout.exercises,
|
|
135
|
+
...pullUpWorkout.exercises,
|
|
136
|
+
...assistedPullUpWorkout.exercises,
|
|
137
|
+
...weightedPullUpWorkout.exercises,
|
|
138
|
+
...shortDistanceWeightWorkout.exercises,
|
|
139
|
+
],
|
|
140
|
+
include_warmup_sets: true,
|
|
141
|
+
},
|
|
66
142
|
})).toBe(5000);
|
|
67
143
|
});
|
|
144
|
+
it('takes warmup sets into account only if `include_warmup_sets` === `true`', () => {
|
|
145
|
+
const workoutWithWarmupSets = {
|
|
146
|
+
exercises: [
|
|
147
|
+
{
|
|
148
|
+
exercise_type: 'weight_reps',
|
|
149
|
+
exercise_template_id: 'asd',
|
|
150
|
+
volume_doubling_enabled: false,
|
|
151
|
+
hundred_percent_bodyweight_exercise: false,
|
|
152
|
+
sets: [
|
|
153
|
+
{
|
|
154
|
+
indicator: 'warmup',
|
|
155
|
+
weight_kg: 100,
|
|
156
|
+
reps: 10,
|
|
157
|
+
distance_meters: 0,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
indicator: 'normal',
|
|
161
|
+
weight_kg: 100,
|
|
162
|
+
reps: 10,
|
|
163
|
+
distance_meters: 0,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
indicator: 'normal',
|
|
167
|
+
weight_kg: 100,
|
|
168
|
+
reps: 10,
|
|
169
|
+
distance_meters: 0,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
176
|
+
bodyweightKg: 100,
|
|
177
|
+
workout: Object.assign(Object.assign({}, workoutWithWarmupSets), { include_warmup_sets: false }),
|
|
178
|
+
})).toBe(2000);
|
|
179
|
+
expect((0, workoutVolume_1.estimatedWorkoutVolumeKg)({
|
|
180
|
+
bodyweightKg: 100,
|
|
181
|
+
workout: Object.assign(Object.assign({}, workoutWithWarmupSets), { include_warmup_sets: true }),
|
|
182
|
+
})).toBe(3000);
|
|
183
|
+
});
|
|
68
184
|
});
|
|
69
185
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./translationUtils"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { PositionalTextParams, NamedTextParams, PositionalReactParams, NamedReactParams } from './types';
|
|
2
|
+
export declare function interpolate<T extends string>(str: string, params: PositionalTextParams | NamedTextParams<T> | PositionalReactParams | NamedReactParams<T>): string | (string | number)[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolate = interpolate;
|
|
4
|
+
const hasReact = (params) => Object.values(params).some((v) => v !== null &&
|
|
5
|
+
v !== undefined &&
|
|
6
|
+
typeof v !== 'string' &&
|
|
7
|
+
typeof v !== 'number' &&
|
|
8
|
+
typeof v !== 'boolean');
|
|
9
|
+
function interpolate(str, params) {
|
|
10
|
+
if (Array.isArray(params)) {
|
|
11
|
+
const positionalParams = params;
|
|
12
|
+
const hasReactParams = hasReact(positionalParams);
|
|
13
|
+
const re = () => /(%s)/g;
|
|
14
|
+
let i = 0;
|
|
15
|
+
if (hasReactParams) {
|
|
16
|
+
return str
|
|
17
|
+
.split(/(%s)/g)
|
|
18
|
+
.filter((w) => !!w)
|
|
19
|
+
.map((w) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const [, key] = (_a = re().exec(w)) !== null && _a !== void 0 ? _a : [];
|
|
22
|
+
if (!key) {
|
|
23
|
+
return w;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return ((_b = positionalParams[i++]) !== null && _b !== void 0 ? _b : (console.error(`Missing param ${i} in the string "${str}"`), w));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return str.replace(re(), (_) => { var _a; return String((_a = positionalParams[i++]) !== null && _a !== void 0 ? _a : _); });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const namedParams = params;
|
|
36
|
+
const hasReactParams = hasReact(namedParams);
|
|
37
|
+
const re = () => /%{([^}]*)}/g;
|
|
38
|
+
if (hasReactParams) {
|
|
39
|
+
return str
|
|
40
|
+
.split(/(%{[^}]*})/g)
|
|
41
|
+
.filter((w) => !!w)
|
|
42
|
+
.map((w) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const [, key] = (_a = re().exec(w)) !== null && _a !== void 0 ? _a : [];
|
|
45
|
+
if (!key) {
|
|
46
|
+
if (key === '') {
|
|
47
|
+
console.error(`Empty param in the string "${str}"`);
|
|
48
|
+
}
|
|
49
|
+
return w;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return ((_b = namedParams[key]) !== null && _b !== void 0 ? _b : (console.error(`Missing param "${key}" in the string "${str}"`),
|
|
53
|
+
w));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return str.replace(re(), (_, key) => { var _a; return String((_a = namedParams[key]) !== null && _a !== void 0 ? _a : _); });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 type PositionalTextParams = (string | number)[];
|
|
6
|
+
export type NamedTextParams<T extends string> = Record<T, string | number>;
|
|
7
|
+
export type PositionalReactParams = (string | number | object)[];
|
|
8
|
+
export type NamedReactParams<T extends string> = Record<T, string | number | object>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type Lookup<T extends readonly unknown[]> = T[number];
|
|
2
|
+
export declare const isInArray: <T, ReadonlyArrayOfT extends readonly T[]>(value: T, array: ReadonlyArrayOfT) => value is Lookup<ReadonlyArrayOfT>;
|
|
3
|
+
export type DeepReadonly<T> = {
|
|
4
|
+
readonly [P in keyof T]: T[P] extends (...args: any[]) => any ? T[P] : DeepReadonly<T[P]>;
|
|
5
|
+
};
|
|
6
|
+
export declare const exhaustiveTypeCheck: (_: never) => undefined;
|
|
7
|
+
export declare const exhaustiveTypeException: (type: never) => Error;
|
|
8
|
+
export type Some<T> = {
|
|
9
|
+
hasValue: true;
|
|
10
|
+
value: T;
|
|
11
|
+
} | {
|
|
12
|
+
hasValue: false;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Please use this instead of using the 'as' keyword directly, so it's easier
|
|
16
|
+
* to screen for these ticking time bombs in the code from time to time. Or
|
|
17
|
+
* better yet, just implement validation for your types straight away.
|
|
18
|
+
*
|
|
19
|
+
* If you would think twice before using this, then by pure logic you should
|
|
20
|
+
* likewise also think twice - no, make it at least thrice - before making the
|
|
21
|
+
* decision to opt into undefined behaviour by letting the compile-time TS type
|
|
22
|
+
* diverge from the runtime JS value.
|
|
23
|
+
*
|
|
24
|
+
* This is your last chance to turn back.
|
|
25
|
+
*
|
|
26
|
+
* You have been warned.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const someData = await AsyncStorage.getItem(SOME_KEY);
|
|
31
|
+
* const parsedData = JSON.parse(someData);
|
|
32
|
+
* const data = dangerousUncheckedTypeCast<SomeDataType>(parsedData);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const dangerousUncheckedTypeCast: <T = void, U extends T = T>(value: unknown) => U;
|
|
36
|
+
/**
|
|
37
|
+
* Wrapper for TypeScript's non-nullish assertion operator (`!`). Use this
|
|
38
|
+
* instead of the operator directly so it's easier to spot. And, again, only
|
|
39
|
+
* use this if you 100% know what you're doing. If you're not sure, then don't!
|
|
40
|
+
*/
|
|
41
|
+
export declare const assertNonNullish: <T>(value: T) => T & {};
|
|
42
|
+
/**
|
|
43
|
+
* What it's not: "I don't know what type this value may be."
|
|
44
|
+
* What it is: "I don't **CARE** about the type of this value."
|
|
45
|
+
* What it is: "Disable the type system for this variable."
|
|
46
|
+
*
|
|
47
|
+
* Alias for `any` that makes it more clear what's going on. Avoid using this,
|
|
48
|
+
* and absolutely avoid using `any` directly even harder! Instead, you may want
|
|
49
|
+
* to use one of the following:
|
|
50
|
+
*
|
|
51
|
+
* - `unknown` // any value, can be nullish or not - need to use type guards
|
|
52
|
+
* - `unknown[]` // same as above, but we know it's an array of these unknowns,
|
|
53
|
+
* // so we allow array functions to be used on it
|
|
54
|
+
* - `object` // any value where `typeof value === 'object'` - except `null`
|
|
55
|
+
* - `{}` // any non-nullish value, object or not; ignore the lint error
|
|
56
|
+
* - `never` // no value; not `undefined` or `null`, but _unreachable code_
|
|
57
|
+
*/
|
|
58
|
+
export type UNSAFE_Untyped = any;
|
|
59
|
+
/**
|
|
60
|
+
* Safer alternative to `JSON.parse`. Returns `unknown` instead of `any`.
|
|
61
|
+
*
|
|
62
|
+
* @see JSON.parse
|
|
63
|
+
*/
|
|
64
|
+
export declare const parseJSON: (...args: Parameters<typeof JSON.parse>) => unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Same as `array[index]`, but adds `undefined` to the return type. Maybe some
|
|
67
|
+
* fine day we will enable `noUncheckedIndexedAccess` in all our projects. 🤞
|
|
68
|
+
*/
|
|
69
|
+
export declare const typeSafeIndex: <T>(array: T[], index: number) => T | undefined;
|
|
70
|
+
export declare const TODO: (message?: string) => never;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TODO = exports.typeSafeIndex = exports.parseJSON = exports.assertNonNullish = exports.dangerousUncheckedTypeCast = exports.exhaustiveTypeException = exports.exhaustiveTypeCheck = exports.isInArray = void 0;
|
|
4
|
+
const isInArray = (value, array) => array.includes(value);
|
|
5
|
+
exports.isInArray = isInArray;
|
|
6
|
+
const exhaustiveTypeCheck = (_) => void _;
|
|
7
|
+
exports.exhaustiveTypeCheck = exhaustiveTypeCheck;
|
|
8
|
+
const exhaustiveTypeException = (type) => new Error(`Assertion failed: "unreachable" code reached with unknown type: ${typeof type === 'object' ? JSON.stringify(type) : String(type)}`);
|
|
9
|
+
exports.exhaustiveTypeException = exhaustiveTypeException;
|
|
10
|
+
/**
|
|
11
|
+
* Please use this instead of using the 'as' keyword directly, so it's easier
|
|
12
|
+
* to screen for these ticking time bombs in the code from time to time. Or
|
|
13
|
+
* better yet, just implement validation for your types straight away.
|
|
14
|
+
*
|
|
15
|
+
* If you would think twice before using this, then by pure logic you should
|
|
16
|
+
* likewise also think twice - no, make it at least thrice - before making the
|
|
17
|
+
* decision to opt into undefined behaviour by letting the compile-time TS type
|
|
18
|
+
* diverge from the runtime JS value.
|
|
19
|
+
*
|
|
20
|
+
* This is your last chance to turn back.
|
|
21
|
+
*
|
|
22
|
+
* You have been warned.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const someData = await AsyncStorage.getItem(SOME_KEY);
|
|
27
|
+
* const parsedData = JSON.parse(someData);
|
|
28
|
+
* const data = dangerousUncheckedTypeCast<SomeDataType>(parsedData);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const dangerousUncheckedTypeCast = (value) => value;
|
|
32
|
+
exports.dangerousUncheckedTypeCast = dangerousUncheckedTypeCast;
|
|
33
|
+
/**
|
|
34
|
+
* Wrapper for TypeScript's non-nullish assertion operator (`!`). Use this
|
|
35
|
+
* instead of the operator directly so it's easier to spot. And, again, only
|
|
36
|
+
* use this if you 100% know what you're doing. If you're not sure, then don't!
|
|
37
|
+
*/
|
|
38
|
+
const assertNonNullish = (value) => value;
|
|
39
|
+
exports.assertNonNullish = assertNonNullish;
|
|
40
|
+
/**
|
|
41
|
+
* Safer alternative to `JSON.parse`. Returns `unknown` instead of `any`.
|
|
42
|
+
*
|
|
43
|
+
* @see JSON.parse
|
|
44
|
+
*/
|
|
45
|
+
exports.parseJSON = JSON.parse;
|
|
46
|
+
/**
|
|
47
|
+
* Same as `array[index]`, but adds `undefined` to the return type. Maybe some
|
|
48
|
+
* fine day we will enable `noUncheckedIndexedAccess` in all our projects. 🤞
|
|
49
|
+
*/
|
|
50
|
+
const typeSafeIndex = (array, index) => array[index];
|
|
51
|
+
exports.typeSafeIndex = typeSafeIndex;
|
|
52
|
+
const TODO = (message) => {
|
|
53
|
+
throw new Error(message !== null && message !== void 0 ? message : 'Not implemented');
|
|
54
|
+
};
|
|
55
|
+
exports.TODO = TODO;
|
package/built/units.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
export declare const POUNDS_IN_KG = 2.20462;
|
|
2
2
|
export declare const CM_IN_INCH = 2.54;
|
|
3
|
-
export declare const METERS_IN_YARD = 0.9144;
|
|
4
|
-
export declare const KILOMETERS_IN_MILE = 1.60934;
|
|
5
|
-
export declare const YARDS_IN_A_MILE = 1760;
|
|
6
3
|
export declare const METERS_IN_MILE = 1609.34;
|
|
7
|
-
export declare const roundToTwoDecimal: (value: number) => number;
|
|
8
|
-
export declare const roundToOneDecimal: (value: number) => number;
|
|
9
|
-
export declare const roundToWholeNumber: (value: number) => number;
|
|
10
4
|
export declare const exactLbsToKg: (value: number) => number;
|
|
11
5
|
export declare const exactKgtoLbs: (value: number) => number;
|
|
12
6
|
export declare const exactInchtoCm: (value: number) => number;
|
|
13
7
|
export declare const exactCmtoInch: (value: number) => number;
|
|
14
|
-
export declare const exactMetersToYards: (value: number) => number;
|
|
15
8
|
export declare const exactMilesToMeters: (value: number) => number;
|
|
16
9
|
export declare const exactMetersToMiles: (meters: number) => number;
|
|
10
|
+
export interface FtIn {
|
|
11
|
+
ft: number;
|
|
12
|
+
in: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const roundedCmToFtIn: (cm: number) => {
|
|
15
|
+
ft: number;
|
|
16
|
+
in: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const exactFtInToCm: (ftIn: FtIn) => number;
|
|
19
|
+
/**
|
|
20
|
+
* Round kilo- to deci- (e.g. kilograms/kg to decigrams/dg). Used for comparing
|
|
21
|
+
* weight values in kg which may have originated in lbs.
|
|
22
|
+
*/
|
|
23
|
+
export declare const roundKtoD: (value: number) => number;
|
package/built/units.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.roundKtoD = exports.exactFtInToCm = exports.roundedCmToFtIn = exports.exactMetersToMiles = exports.exactMilesToMeters = exports.exactCmtoInch = exports.exactInchtoCm = exports.exactKgtoLbs = exports.exactLbsToKg = exports.METERS_IN_MILE = exports.CM_IN_INCH = exports.POUNDS_IN_KG = void 0;
|
|
4
4
|
exports.POUNDS_IN_KG = 2.20462;
|
|
5
5
|
exports.CM_IN_INCH = 2.54;
|
|
6
|
-
exports.METERS_IN_YARD = 0.9144;
|
|
7
|
-
exports.KILOMETERS_IN_MILE = 1.60934;
|
|
8
|
-
exports.YARDS_IN_A_MILE = 1760;
|
|
9
6
|
exports.METERS_IN_MILE = 1609.34;
|
|
10
|
-
const roundToTwoDecimal = (value) => Math.round(value * 100) / 100;
|
|
11
|
-
exports.roundToTwoDecimal = roundToTwoDecimal;
|
|
12
|
-
const roundToOneDecimal = (value) => Math.round(value * 10) / 10;
|
|
13
|
-
exports.roundToOneDecimal = roundToOneDecimal;
|
|
14
|
-
const roundToWholeNumber = (value) => Math.round(value);
|
|
15
|
-
exports.roundToWholeNumber = roundToWholeNumber;
|
|
16
7
|
const exactLbsToKg = (value) => {
|
|
17
8
|
return value / exports.POUNDS_IN_KG;
|
|
18
9
|
};
|
|
@@ -29,10 +20,6 @@ const exactCmtoInch = (value) => {
|
|
|
29
20
|
return value / exports.CM_IN_INCH;
|
|
30
21
|
};
|
|
31
22
|
exports.exactCmtoInch = exactCmtoInch;
|
|
32
|
-
const exactMetersToYards = (value) => {
|
|
33
|
-
return value / exports.METERS_IN_YARD;
|
|
34
|
-
};
|
|
35
|
-
exports.exactMetersToYards = exactMetersToYards;
|
|
36
23
|
const exactMilesToMeters = (value) => {
|
|
37
24
|
return value * exports.METERS_IN_MILE;
|
|
38
25
|
};
|
|
@@ -41,3 +28,26 @@ const exactMetersToMiles = (meters) => {
|
|
|
41
28
|
return meters / exports.METERS_IN_MILE;
|
|
42
29
|
};
|
|
43
30
|
exports.exactMetersToMiles = exactMetersToMiles;
|
|
31
|
+
const roundedCmToFtIn = (cm) => {
|
|
32
|
+
const totalInches = (0, exports.exactCmtoInch)(cm);
|
|
33
|
+
const feet = Math.floor(totalInches / 12);
|
|
34
|
+
const inches = Math.round(totalInches % 12);
|
|
35
|
+
if (inches === 12) {
|
|
36
|
+
return { ft: feet + 1, in: 0 };
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return { ft: feet, in: inches };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.roundedCmToFtIn = roundedCmToFtIn;
|
|
43
|
+
const exactFtInToCm = (ftIn) => {
|
|
44
|
+
const totalInches = ftIn.ft * 12 + ftIn.in;
|
|
45
|
+
return Math.round((0, exports.exactInchtoCm)(totalInches));
|
|
46
|
+
};
|
|
47
|
+
exports.exactFtInToCm = exactFtInToCm;
|
|
48
|
+
/**
|
|
49
|
+
* Round kilo- to deci- (e.g. kilograms/kg to decigrams/dg). Used for comparing
|
|
50
|
+
* weight values in kg which may have originated in lbs.
|
|
51
|
+
*/
|
|
52
|
+
const roundKtoD = (value) => Math.round(value * 10000);
|
|
53
|
+
exports.roundKtoD = roundKtoD;
|