refactor: move scaler out of $lib/server so it can run in browser
RecipeView needs scaleIngredients on the client for live portion scaling. Moved scaler.ts from $lib/server/recipes/ to $lib/recipes/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import type { Ingredient } from '$lib/types';
|
||||
|
||||
export function roundQuantity(q: number): number {
|
||||
if (q === 0) return 0;
|
||||
if (q < 1) return Math.round(q * 100) / 100;
|
||||
if (q < 10) return Math.round(q * 10) / 10;
|
||||
return Math.round(q);
|
||||
}
|
||||
|
||||
export function scaleIngredients(ings: Ingredient[], factor: number): Ingredient[] {
|
||||
if (factor <= 0) throw new Error('factor must be positive');
|
||||
return ings.map((i) => ({
|
||||
...i,
|
||||
quantity: i.quantity === null ? null : roundQuantity(i.quantity * factor)
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user