@dgpholdings/greatoak-shared 1.2.52 → 1.2.53

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.
@@ -9,3 +9,4 @@ export { maskEmail, isAnonymousEmail, isEmail } from "./email.utils";
9
9
  export { NOOP } from "./noop.utils";
10
10
  export { calculateExerciseScoreV2, calculateTotalVolume } from "./scoring";
11
11
  export { scaleProPlan, calculateBMI, calculateDayPlanDuration, calculateExerciseDurationSecs } from "./adoptionEngine/scaleProPlan.util";
12
+ export * from "./metricConversions";
@@ -1,4 +1,18 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.calculateExerciseDurationSecs = exports.calculateDayPlanDuration = exports.calculateBMI = exports.scaleProPlan = exports.calculateTotalVolume = exports.calculateExerciseScoreV2 = exports.NOOP = exports.isEmail = exports.isAnonymousEmail = exports.maskEmail = exports.generatePlanCode = exports.toError = exports.slugifyText = exports.isDefinedNumber = exports.isDefined = exports.countryToCurrencyCode = exports.getDaysAndHoursDifference = exports.isUserAllowedToUpdate = exports.mmssToSecs = exports.toNumber = void 0;
4
18
  var number_util_1 = require("./number.util");
@@ -32,3 +46,4 @@ Object.defineProperty(exports, "scaleProPlan", { enumerable: true, get: function
32
46
  Object.defineProperty(exports, "calculateBMI", { enumerable: true, get: function () { return scaleProPlan_util_1.calculateBMI; } });
33
47
  Object.defineProperty(exports, "calculateDayPlanDuration", { enumerable: true, get: function () { return scaleProPlan_util_1.calculateDayPlanDuration; } });
34
48
  Object.defineProperty(exports, "calculateExerciseDurationSecs", { enumerable: true, get: function () { return scaleProPlan_util_1.calculateExerciseDurationSecs; } });
49
+ __exportStar(require("./metricConversions"), exports);
@@ -0,0 +1,7 @@
1
+ export declare const LBS_PER_KG = 2.20462;
2
+ export declare const INCHES_PER_CM = 0.393701;
3
+ export declare const formatWeight: (kg: number | undefined | null, isImperial: boolean) => string;
4
+ export declare const formatWeightValue: (kgStr: string | undefined | null, isImperial: boolean) => string;
5
+ export declare const parseWeightValue: (displayStr: string | undefined | null, isImperial: boolean) => string;
6
+ export declare const formatHeight: (cm: number | undefined | null, isImperial: boolean) => string;
7
+ export declare const calculateAge: (dob: Date | string | undefined | null) => number | null;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ // src/utils/metricConversions.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.calculateAge = exports.formatHeight = exports.parseWeightValue = exports.formatWeightValue = exports.formatWeight = exports.INCHES_PER_CM = exports.LBS_PER_KG = void 0;
5
+ exports.LBS_PER_KG = 2.20462;
6
+ exports.INCHES_PER_CM = 0.393701;
7
+ const formatWeight = (kg, isImperial) => {
8
+ if (!kg)
9
+ return "--";
10
+ if (isImperial) {
11
+ const lbs = Math.round(kg * exports.LBS_PER_KG);
12
+ return `${lbs} lbs`;
13
+ }
14
+ return `${Math.round(kg)} kg`;
15
+ };
16
+ exports.formatWeight = formatWeight;
17
+ // Returns just the converted numerical string rounded to nearest 0.25 (used in inputs)
18
+ const formatWeightValue = (kgStr, isImperial) => {
19
+ if (!kgStr)
20
+ return "";
21
+ const parsed = parseFloat(kgStr);
22
+ if (isNaN(parsed))
23
+ return "";
24
+ const ratio = isImperial ? exports.LBS_PER_KG : 1;
25
+ return (Math.round(parsed * ratio * 4) / 4).toString();
26
+ };
27
+ exports.formatWeightValue = formatWeightValue;
28
+ // Parses a display string (e.g. from a dial) back to base kg
29
+ const parseWeightValue = (displayStr, isImperial) => {
30
+ if (!displayStr)
31
+ return "";
32
+ const parsed = parseFloat(displayStr);
33
+ if (isNaN(parsed))
34
+ return "";
35
+ const ratio = isImperial ? exports.LBS_PER_KG : 1;
36
+ return isImperial ? (parsed / ratio).toFixed(2) : parsed.toString();
37
+ };
38
+ exports.parseWeightValue = parseWeightValue;
39
+ const formatHeight = (cm, isImperial) => {
40
+ if (!cm)
41
+ return "--";
42
+ if (isImperial) {
43
+ const totalInches = Math.round(cm * exports.INCHES_PER_CM);
44
+ const feet = Math.floor(totalInches / 12);
45
+ const inches = totalInches % 12;
46
+ return `${feet}'${inches}"`;
47
+ }
48
+ return `${Math.round(cm)} cm`;
49
+ };
50
+ exports.formatHeight = formatHeight;
51
+ const calculateAge = (dob) => {
52
+ if (!dob)
53
+ return null;
54
+ const birthDate = new Date(dob);
55
+ if (isNaN(birthDate.getTime()))
56
+ return null;
57
+ const today = new Date();
58
+ let age = today.getFullYear() - birthDate.getFullYear();
59
+ const m = today.getMonth() - birthDate.getMonth();
60
+ if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
61
+ age--;
62
+ }
63
+ return age;
64
+ };
65
+ exports.calculateAge = calculateAge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dgpholdings/greatoak-shared",
3
- "version": "1.2.52",
3
+ "version": "1.2.53",
4
4
  "description": "Shared TypeScript types and utilities for @dgpholdings projects",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",