feat(shopping): unitFamily-Utility fuer Konsolidierung

Neue Hilfsfunktion `unitFamily` normalisiert Einheiten auf eine
Familien-Kennung ('weight', 'volume' oder lowercase-trim). Wird
in nachfolgenden Konsolidierungs-Schritten der Einkaufsliste
verwendet. Abgedeckt durch 5 Vitest-Unit-Tests (TDD).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 16:46:43 +02:00
parent 59b232c5fc
commit 29f0245ce0
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
export type UnitFamily = 'weight' | 'volume' | string;
const WEIGHT_UNITS = new Set(['g', 'kg']);
const VOLUME_UNITS = new Set(['ml', 'l']);
export function unitFamily(unit: string | null | undefined): UnitFamily {
const u = (unit ?? '').trim().toLowerCase();
if (WEIGHT_UNITS.has(u)) return 'weight';
if (VOLUME_UNITS.has(u)) return 'volume';
return u;
}