Converting Kitchen Units & Culinary Density Ratios in a TypeScript Recipe Cost Engine
Commercial kitchens buy flour in 50 lb sacks, olive oil in 1 L bottles, and ground beef in 10 lb chubs—yet line cooks measure recipes in grams, ounces, cups, and tablespoons. When building My Food Cost Calculator, the ha
Commercial kitchens buy flour in 50 lb sacks, olive oil in 1 L bottles, and ground beef in 10 lb chubs—yet line cooks measure recipes in grams, ounces, cups, and tablespoons. When building My Food Cost Calculator, the hardest engineering problem was not arithmetic; it was making mixed metric/imperial conversions and trim yield loss completely frictionless in the browser.
1. Bridging Weight, Volume & Edible Yield in TypeScript
Standard unit converters fail when a baker buys bread flour by the pound and enters cups in a recipe, or forgets that 80/20 ground beef loses ~20% weight during cooking. By pairing a lightweight culinary density lookup with an Edible Portion (EP) yield divisor, every line item stays accurate without a backend database:
export function convertQuantity(
qty: number,
fromUnit: KitchenUnit,
toUnit: KitchenUnit,
ingredientName = ""
) {
if (fromUnit === toUnit) return { value: qty };
if (WEIGHT_IN_GRAMS[fromUnit] && WEIGHT_IN_GRAMS[toUnit]) {
return { value: (qty * WEIGHT_IN_GRAMS[fromUnit]!) / WEIGHT_IN_GRAMS[toUnit]! };
}
const density = estimateDensityGPerMl(ingredientName);
if (VOLUME_IN_ML[fromUnit] && WEIGHT_IN_GRAMS[toUnit]) {
const grams = qty * VOLUME_IN_ML[fromUnit]! * density;
return { value: grams / WEIGHT_IN_GRAMS[toUnit]! };
}
return { value: qty };
}
You can try live multi-ingredient costing, trim yield adjustments, and printable cost cards directly on our Recipe Cost Calculator.
2. Tracking Actual CoGS & Restaurant Prime Cost
Dish-level cards measure theoretical margin, while operators also need weekly inventory CoGS (Beginning + Purchases - Ending) and loaded labor inside a 60% Prime Cost ceiling—both built directly into our Restaurant Labor & Prime Cost Calculator. All saved recipes stay privately in localStorage with zero sign-up.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.