Vitest: - Workspace at root (vitest.workspace.ts) running per-package configs - packages/shared/vitest.config.ts with v8 coverage and 70% thresholds - Root scripts: test / test:watch / test:coverage Nutrition module in @ketopath/shared: - calculateBmr (Mifflin-St Jeor) + calculateTdee with activity multipliers - ACTIVITY_MULTIPLIERS constants matching CLAUDE.md domain knowledge - 14 unit tests covering Michele/Laura PRD personas, all sex variants, every activity level, and input validation (100% coverage on src/nutrition) Playwright in apps/web: - chromium-only project, webServer auto-boot of pnpm dev - e2e/home.spec.ts smoke test asserts Italian copy and disclaimer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
28 lines
750 B
TypeScript
28 lines
750 B
TypeScript
import type { Gender } from './types.js';
|
|
|
|
export interface BmrInput {
|
|
weightKg: number;
|
|
heightCm: number;
|
|
ageYears: number;
|
|
gender: Gender;
|
|
}
|
|
|
|
// Mifflin-St Jeor equation. For Gender 'OTHER' we use the average of the
|
|
// male and female sex-specific constants (-78), as a neutral approximation.
|
|
export function calculateBmr({ weightKg, heightCm, ageYears, gender }: BmrInput): number {
|
|
if (weightKg <= 0 || heightCm <= 0 || ageYears <= 0) {
|
|
throw new RangeError('weightKg, heightCm and ageYears must be positive');
|
|
}
|
|
|
|
const base = 10 * weightKg + 6.25 * heightCm - 5 * ageYears;
|
|
|
|
switch (gender) {
|
|
case 'MALE':
|
|
return base + 5;
|
|
case 'FEMALE':
|
|
return base - 161;
|
|
case 'OTHER':
|
|
return base - 78;
|
|
}
|
|
}
|