Scale a recipe, convert its units, and build a shopping list #4

Closed
opened 2026-10-17 02:57:40 -04:00 by cmoriarty · 1 comment
Owner

A cook pastes a recipe, says how many servings they want and whether they cook in metric or US units, and gets the recipe back scaled and converted. They can add several recipes to a shopping list.

  1. Reading a recipe (src/recipe.ts, tested in test/recipe.test.ts). A recipe is plain text: a first line Serves N, then one ingredient a line, <quantity> [unit] <name>. A quantity is a whole number, a decimal, a fraction (1/2) or a mixed number (1 1/2). Units: g kg ml l tsp tbsp cup oz lb, or none (2 eggs). A line that does not read is reported with its line number, and the other lines are still read.
  2. Scaling (src/scale.ts, tested in test/scale.test.ts). To M servings, every quantity is multiplied by M/N. Spoons and cups show the nearest quarter or third (1 1/3 cup); grams and millilitres show whole numbers from 10 up and one decimal below.
  3. Converting (src/convert.ts, tested in test/convert.test.ts). Metric ↔ US: g ↔ oz, kg ↔ lb, ml ↔ tsp/tbsp/cup, l ↔ cup. The unit chosen keeps the number between 1/4 and 1000 (1,500 g shows as 1.5 kg). An ingredient without a unit stays as it is.
  4. The shopping list (src/shopping.ts, tested in test/shopping.test.ts). From up to five recipes, the same ingredient (by name, ignoring case and a plural s) with the same unit is added up; the same ingredient in different units is listed once per unit; the list is sorted by name.
  5. The page (/recipes: its routes in src/server.ts, its HTML in src/pages.ts, tested in test/ with vitest and in e2e/recipes.spec.ts with Playwright). Paste a recipe, enter the servings, choose Metric or US, and see the result; add it to the list, and see the shopping list. A line that did not read is shown beside its line number. Shortcut has web pages, so this is a page rather than a command.

Each part comes with its tests, in the project's own test setup (vitest under test/, Playwright under e2e/), and CHANGELOG.md names the change for the release-notes check.

A cook pastes a recipe, says how many servings they want and whether they cook in metric or US units, and gets the recipe back scaled and converted. They can add several recipes to a shopping list. 1. **Reading a recipe** (`src/recipe.ts`, tested in `test/recipe.test.ts`). A recipe is plain text: a first line `Serves N`, then one ingredient a line, `<quantity> [unit] <name>`. A quantity is a whole number, a decimal, a fraction (`1/2`) or a mixed number (`1 1/2`). Units: `g kg ml l tsp tbsp cup oz lb`, or none (`2 eggs`). A line that does not read is reported with its line number, and the other lines are still read. 2. **Scaling** (`src/scale.ts`, tested in `test/scale.test.ts`). To M servings, every quantity is multiplied by M/N. Spoons and cups show the nearest quarter or third (`1 1/3 cup`); grams and millilitres show whole numbers from 10 up and one decimal below. 3. **Converting** (`src/convert.ts`, tested in `test/convert.test.ts`). Metric ↔ US: g ↔ oz, kg ↔ lb, ml ↔ tsp/tbsp/cup, l ↔ cup. The unit chosen keeps the number between 1/4 and 1000 (1,500 g shows as 1.5 kg). An ingredient without a unit stays as it is. 4. **The shopping list** (`src/shopping.ts`, tested in `test/shopping.test.ts`). From up to five recipes, the same ingredient (by name, ignoring case and a plural `s`) with the same unit is added up; the same ingredient in different units is listed once per unit; the list is sorted by name. 5. **The page** (`/recipes`: its routes in `src/server.ts`, its HTML in `src/pages.ts`, tested in `test/` with vitest and in `e2e/recipes.spec.ts` with Playwright). Paste a recipe, enter the servings, choose Metric or US, and see the result; add it to the list, and see the shopping list. A line that did not read is shown beside its line number. Shortcut has web pages, so this is a page rather than a command. Each part comes with its tests, in the project's own test setup (vitest under `test/`, Playwright under `e2e/`), and `CHANGELOG.md` names the change for the release-notes check.
Author
Owner

Shipped in cmoriarty/braid-combined-test#5, merged into compare/groups as 1546fba65f.

The OpenSpec change is archived as 2026-10-17-scale-recipes-and-shopping-list.

Braid run: http://openspecflow.internal.underthere.xyz/run/run_01M54H8M577MXQ87ARQVWW46BP

Shipped in [cmoriarty/braid-combined-test#5](https://forgejo.underthere.xyz/cmoriarty/braid-combined-test/pulls/5), merged into `compare/groups` as `1546fba65f`. The OpenSpec change is archived as `2026-10-17-scale-recipes-and-shopping-list`. Braid run: http://openspecflow.internal.underthere.xyz/run/run_01M54H8M577MXQ87ARQVWW46BP
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cmoriarty/braid-combined-test#4
No description provided.