diff --git a/apps/web/src/lib/ingredientUnits.test.ts b/apps/web/src/lib/ingredientUnits.test.ts
new file mode 100644
index 0000000..5225266
--- /dev/null
+++ b/apps/web/src/lib/ingredientUnits.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from 'vitest';
+import { INGREDIENT_UNITS, normalizeUnit, unitLabel } from './ingredientUnits';
+
+describe('ingredient units', () => {
+ it('translates legacy Norwegian units to English', () => {
+ expect(normalizeUnit('ss')).toBe('tbsp');
+ expect(normalizeUnit('ts')).toBe('tsp');
+ expect(normalizeUnit('STK')).toBe('pcs');
+ expect(unitLabel('ss')).toBe('tbsp');
+ });
+
+ it('keeps English and custom units as stored', () => {
+ expect(normalizeUnit('g')).toBe('g');
+ expect(unitLabel('dl')).toBe('dL');
+ expect(unitLabel('cloves')).toBe('cloves');
+ expect(unitLabel('')).toBe('');
+ });
+
+ it('offers no Norwegian units in the editor', () => {
+ const values: string[] = INGREDIENT_UNITS.map((unit) => unit.value);
+ for (const legacy of ['ss', 'ts', 'stk'])
+ expect(values).not.toContain(legacy);
+ });
+
+ it.each(['__proto__', 'constructor', 'toString', 'hasOwnProperty'])(
+ 'keeps the free-text unit "%s" as typed, not an inherited property',
+ (unit) => {
+ expect(normalizeUnit(unit)).toBe(unit);
+ expect(unitLabel(unit)).toBe(unit);
+ },
+ );
+});
diff --git a/apps/web/src/lib/ingredientUnits.ts b/apps/web/src/lib/ingredientUnits.ts
new file mode 100644
index 0000000..54caa28
--- /dev/null
+++ b/apps/web/src/lib/ingredientUnits.ts
@@ -0,0 +1,45 @@
+/**
+ * Ingredient units offered in the recipe editor, stored by `value` and shown
+ * by `label`. Units are free text in the API, so recipes may also contain
+ * other units (e.g. "cloves"); those are kept and shown as stored.
+ */
+export const INGREDIENT_UNITS = [
+ { value: '', label: 'No unit' },
+ { value: 'g', label: 'g' },
+ { value: 'kg', label: 'kg' },
+ { value: 'ml', label: 'ml' },
+ { value: 'dl', label: 'dL' },
+ { value: 'l', label: 'L' },
+ { value: 'tsp', label: 'tsp' },
+ { value: 'tbsp', label: 'tbsp' },
+ { value: 'cup', label: 'cup' },
+ { value: 'pcs', label: 'pcs' },
+] as const;
+
+/*
+ * Earlier versions of the editor stored Norwegian abbreviations. They are
+ * translated when a recipe is shown or opened for editing, so existing
+ * recipes keep working without a data migration; saving stores English.
+ */
+const LEGACY_UNITS: Record = {
+ ss: 'tbsp', // spiseskje
+ ts: 'tsp', // teskje
+ stk: 'pcs', // stykk
+};
+
+/** The stored value to use for a unit, translating legacy Norwegian units. */
+export function normalizeUnit(unit: string) {
+ const key = unit.trim().toLowerCase();
+ // Units are free text: only the mappings defined above count, never
+ // inherited object properties such as "__proto__" or "constructor".
+ return Object.hasOwn(LEGACY_UNITS, key) ? LEGACY_UNITS[key]! : unit;
+}
+
+/** How a stored unit is displayed next to an amount ('' for no unit). */
+export function unitLabel(unit: string) {
+ const value = normalizeUnit(unit);
+ if (!value) return '';
+ return (
+ INGREDIENT_UNITS.find((option) => option.value === value)?.label ?? value
+ );
+}