feat(recipe): scale ingredient quantities (½×, 1×, 2×, 3×)#309
Merged
spe1020 merged 1 commit intozapcooking:mainfrom Apr 19, 2026
Merged
feat(recipe): scale ingredient quantities (½×, 1×, 2×, 3×)#309spe1020 merged 1 commit intozapcooking:mainfrom
spe1020 merged 1 commit intozapcooking:mainfrom
Conversation
7 tasks
c047017 to
1c1c04d
Compare
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.
1c1c04d to
bfebead
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsutility handles the common ingredient-line shapes:2,0.5,1/2,1 1/2,½2-3 cloves,1/2 to 1 cupNon-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
2 cups flour4 cups flour6 cups flour1/2 tsp salt1 tsp salt1 ½ tsp salt1 1/2 cups milk3 cups milk4 ½ cups milk1/3 cup sugar⅔ cup sugar1 cup sugar2-3 cloves garlic4–6 cloves garlic6–9 cloves garlicsalt to tasteNotes
ingredientScaling.tsplus a small Ingredients.svelte header update.Test plan
2-3 cloves) — both ends scale.salt to taste,pinch of cinnamon) — those pass through unchanged.PrintRecipeModalreads fromevent.contentdirectly).