Skip to content

feat(recipe): scale ingredient quantities (½×, 1×, 2×, 3×)#309

Merged
spe1020 merged 1 commit intozapcooking:mainfrom
dmnyc:feat/recipe-ingredient-scaling
Apr 19, 2026
Merged

feat(recipe): scale ingredient quantities (½×, 1×, 2×, 3×)#309
spe1020 merged 1 commit intozapcooking:mainfrom
dmnyc:feat/recipe-ingredient-scaling

Conversation

@dmnyc
Copy link
Copy Markdown
Collaborator

@dmnyc dmnyc commented Apr 19, 2026

Summary

Add a scale selector to the recipe's Ingredients section so cooks can double, triple, or halve a recipe on the fly. Chosen scale persists per-recipe in localStorage (recipe_ingredients_scale:<id>) and only appears in the UI when ≠ 1×; when active a caption notes that directions and cook times are unchanged (they don't scale linearly with batch size).

Parsing

The new $lib/ingredientScaling.ts utility handles the common ingredient-line shapes:

  • whole / decimal / fraction / mixed number / unicode fraction — 2, 0.5, 1/2, 1 1/2, ½
  • optional range — 2-3 cloves, 1/2 to 1 cup

Non-parseable lines pass through unchanged so entries like "salt to taste" or "a pinch of cinnamon" are never mangled. Output reformats to nice unicode fractions (½, ⅓, ⅔, ¼, ¾, ⅛, ⅜, ⅝, ⅞) when the scaled value lands within tolerance, else a short decimal.

Examples

Original
2 cups flour 4 cups flour 6 cups flour
1/2 tsp salt 1 tsp salt 1 ½ tsp salt
1 1/2 cups milk 3 cups milk 4 ½ cups milk
1/3 cup sugar ⅔ cup sugar 1 cup sugar
2-3 cloves garlic 4–6 cloves garlic 6–9 cloves garlic
salt to taste unchanged unchanged

Notes

Test plan

  • Set scale to 2× / 3× / ½× → quantities update in place; unicode fractions render correctly.
  • Reload — chosen scale persists per recipe.
  • Switch recipes — scale is recipe-specific, not shared.
  • Scale a recipe with a ranged ingredient (2-3 cloves) — both ends scale.
  • Scale a recipe containing non-numeric entries (salt to taste, pinch of cinnamon) — those pass through unchanged.
  • Printing still shows the original (unscaled) ingredient list (PrintRecipeModal reads from event.content directly).

@dmnyc dmnyc force-pushed the feat/recipe-ingredient-scaling branch 2 times, most recently from c047017 to 1c1c04d Compare April 19, 2026 17:56
Add a scale selector to the Ingredients header so cooks can double,
triple, or halve a recipe on the fly. Chosen scale persists per-recipe
in localStorage (`recipe_ingredients_scale:<id>`) and only appears when
≠ 1×; when active a caption notes that directions and cook times are
unchanged (they don't scale linearly with batch size).

Parsing handles the common ingredient-line shapes:

- whole / decimal / fraction / mixed number / unicode fraction
  (`2`, `0.5`, `1/2`, `1 1/2`, `½`)
- optional range (`2-3`, `1/2 to 1`)

Non-parseable lines pass through unchanged so entries like
"salt to taste" or "a pinch of cinnamon" are never mangled. Output
reformats to nice unicode fractions (½, ⅓, ⅔, ¼, ¾, ⅛, ⅜, ⅝, ⅞) when
the scaled value lands within tolerance, else a short decimal.

The parser lives in a pure utility at `$lib/ingredientScaling.ts` so
future surfaces (print modal, grocery list) can reuse it.
@dmnyc dmnyc force-pushed the feat/recipe-ingredient-scaling branch from 1c1c04d to bfebead Compare April 19, 2026 18:08
@spe1020 spe1020 merged commit f7292bc into zapcooking:main Apr 19, 2026
1 check passed
@dmnyc dmnyc deleted the feat/recipe-ingredient-scaling branch April 19, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants