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:
11
src/lib/server/unit-consolidation.ts
Normal file
11
src/lib/server/unit-consolidation.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user