@lp-labs/recipe-scaling
v0.1.0
Published
Finite-quantity recipe serving scaling and caller-declared same-dimension unit conversion.
Readme
@lp-labs/recipe-scaling
Serving scaling and declared unit conversion. Finite-quantity recipe serving scaling and caller-declared same-dimension unit conversion.
Install
npm install @lp-labs/recipe-scalingQuick start
import { scaleRecipe } from '@lp-labs/recipe-scaling';
console.log(scaleRecipe([{ name: 'flour', quantity: 250, unit: 'g' }], 2, 4));Runtime exports
scaleRecipeconvertIngredientQuantity
The package supplies independent ESM and CommonJS builds, bundled declarations, and no runtime or peer dependencies.
Complete public TypeScript declarations
export interface Ingredient {
name: string;
quantity: number;
unit: string;
}
export interface UnitScale {
dimension: string;
toBase: number;
}
export type UnitScales = Readonly<Record<string, UnitScale>>;
export declare function scaleRecipe(
ingredients: readonly Ingredient[],
originalServings: number,
targetServings: number,
): Ingredient[];
export declare function convertIngredientQuantity(
quantity: number,
from: string,
to: string,
scales: UnitScales,
): number;Scope and limits
Scales named finite scalar ingredient quantities from one positive serving count to another and optionally converts between same-dimension units using caller-provided positive scale factors.
Errors and bounds
Invalid labels/types or missing unit declarations raise TypeError. Negative/non-finite values, zero servings, oversized arrays, and numeric overflow raise RangeError.
Customization
Declare each unit as { dimension, toBase } using a base scale chosen by the caller. Convert only units within the same declared dimension; use separate recipe scaling if no conversion is intended.
Support
If this library is useful to you, consider supporting its maintenance with a donation via PayPal.
Author
Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.
